mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: prune
This commit is contained in:
1 parent
6725e79021
commit
7027f63236
12 files changed
+5866
-7415
No files matched your search
@@ -141,7 +141,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Start server and build assets
|
- name: Start server and build assets
|
||||||
run: |
|
run: |
|
||||||
bun dev:website --verbose &
|
bun dev:website --verbosepa &
|
||||||
SERVER_PID=$!
|
SERVER_PID=$!
|
||||||
|
|
||||||
bun run build:assets --all-targets --depot --production
|
bun run build:assets --all-targets --depot --production
|
||||||
|
|||||||
+2
-1
@@ -35,7 +35,8 @@
|
|||||||
"build:protos": "bun packages/scripts/src/protos.ts",
|
"build:protos": "bun packages/scripts/src/protos.ts",
|
||||||
"preview:website": "cd packages/website && bun run preview",
|
"preview:website": "cd packages/website && bun run preview",
|
||||||
"build:reviews": "cd packages/scripts && bun build:reviews",
|
"build:reviews": "cd packages/scripts && bun build:reviews",
|
||||||
"build:ids": "cd packages/scripts && bun build:ids"
|
"build:ids": "cd packages/scripts && bun build:ids",
|
||||||
|
"prunestrings": "cd packages/scripts && bun prunestrings"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
+1193
-491
File diff suppressed because it is too large.
Load diff
+476
-1126
File diff suppressed because it is too large.
Load diff
+476
-1126
File diff suppressed because it is too large.
Load diff
+502
-1094
File diff suppressed because it is too large.
Load diff
+655
-1053
File diff suppressed because it is too large.
Load diff
+1347
-329
File diff suppressed because it is too large.
Load diff
+476
-1126
File diff suppressed because it is too large.
Load diff
+687
-1067
File diff suppressed because it is too large.
Load diff
@@ -10,7 +10,8 @@
|
|||||||
"build:reviews": "bun src/reviews.ts",
|
"build:reviews": "bun src/reviews.ts",
|
||||||
"build:ids": "bun src/discoverIds.ts",
|
"build:ids": "bun src/discoverIds.ts",
|
||||||
"build:bot": "bun src/buildBot.ts",
|
"build:bot": "bun src/buildBot.ts",
|
||||||
"build:ratingleaderboard": "bun src/buildRatingLeaderboard.ts"
|
"build:ratingleaderboard": "bun src/buildRatingLeaderboard.ts",
|
||||||
|
"prunestrings": "bun src/pruneStrings.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@blitzkit/core": "workspace:*",
|
"@blitzkit/core": "workspace:*",
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import {
|
||||||
|
DEFAULT_LOCALE,
|
||||||
|
SUPPORTED_LOCALES,
|
||||||
|
TranslationTree,
|
||||||
|
} from '@blitzkit/i18n';
|
||||||
|
import { writeFile } from 'fs/promises';
|
||||||
|
|
||||||
|
const ROOT = '@blitzkit/i18n/strings';
|
||||||
|
const WORKING_ROOT = '../../packages/i18n/strings';
|
||||||
|
|
||||||
|
const defaultStrings = await import(`${ROOT}/${DEFAULT_LOCALE}.json`);
|
||||||
|
const nonDefaultLocales = SUPPORTED_LOCALES.filter(
|
||||||
|
(locale) => locale !== DEFAULT_LOCALE,
|
||||||
|
);
|
||||||
|
|
||||||
|
function prune(defaultStrings: TranslationTree, strings: TranslationTree) {
|
||||||
|
for (const key in strings) {
|
||||||
|
if (key in defaultStrings) {
|
||||||
|
if (typeof defaultStrings[key] === typeof strings[key]) {
|
||||||
|
if (typeof strings[key] === 'string') {
|
||||||
|
if (
|
||||||
|
(defaultStrings[key] as string).replaceAll(/%s\d/g, '%s') ===
|
||||||
|
(strings[key] as string).replaceAll(/%s\d/g, '%s') ||
|
||||||
|
strings[key] === ''
|
||||||
|
) {
|
||||||
|
delete strings[key];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
prune(defaultStrings[key] as TranslationTree, strings[key]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
delete strings[key];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
delete strings[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const locale of nonDefaultLocales) {
|
||||||
|
console.log(`Pruning ${locale}...`);
|
||||||
|
|
||||||
|
const strings = await import(`${ROOT}/${locale}.json`);
|
||||||
|
const pruned = prune(defaultStrings, strings);
|
||||||
|
|
||||||
|
writeFile(`${WORKING_ROOT}/${locale}.json`, JSON.stringify(pruned, null, 2));
|
||||||
|
}
|
||||||
Reference in new issue
Block a user