Skip to content

Commit 5eada93

Browse files
committed
fix(crowdin): normalize repo locale codes on upload
- replace the raw translation upload script with a Node wrapper that rewrites repo-facing locale aliases before invoking Crowdin - previously maintainers had to know that the repo stores Chinese translations in i18n/zh while the Crowdin project only accepts the zh-CN language slug - that mismatch made the documented pnpm upload command fail even when the underlying translation files and Crowdin config were otherwise correct - the new wrapper strips pnpm's passthrough delimiter, normalizes zh to zh-CN, preserves other language codes as-is, and keeps the documented workflow aligned with the actual CLI behavior
1 parent 7307f63 commit 5eada93

3 files changed

Lines changed: 58 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ Help translate Unraid Docs for the global community.
245245
* Follow the glossary and tone guidance in the [Style Guide](docs/contribute/style-guide.mdx)
246246
* Use `pnpm crowdin:upload` or `pnpm crowdin:upload:sources` after changing English source docs
247247
* Use `pnpm crowdin:upload:translations -- --language <lang>` after manually fixing files under `i18n/` so those fixes are pushed back to Crowdin before the next download
248-
* Use Crowdin project language codes for `<lang>`: `de`, `es`, `fr`, and `zh-CN` for the `i18n/zh` locale
248+
* The upload wrapper accepts the repo locale codes directly: use `de`, `es`, `fr`, and `zh` for `i18n/zh`; it normalizes `zh` to Crowdin's `zh-CN` project language code automatically
249249
* Use `pnpm crowdin:download` to pull the latest exported translations after uploads
250250
* `pnpm crowdin:sync` updates source strings and downloads translations, but it does not replace `crowdin:upload:translations` when you need to preserve manual translation fixes
251251

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"postinstall": "pnpm rebuild sharp",
2323
"crowdin:upload": "crowdin upload sources --config crowdin.yml",
2424
"crowdin:upload:sources": "crowdin upload sources --config crowdin.yml",
25-
"crowdin:upload:translations": "crowdin upload translations --config crowdin.yml",
25+
"crowdin:upload:translations": "node scripts/crowdin-upload-translations.js",
2626
"crowdin:sync": "docusaurus write-translations && crowdin upload sources --config crowdin.yml && crowdin download --config crowdin.yml",
2727
"crowdin:download": "crowdin download --config crowdin.yml",
2828
"write-translations": "docusaurus write-translations"
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env node
2+
3+
const { spawnSync } = require("node:child_process");
4+
5+
function normalizeLanguageCode(language) {
6+
if (!language) {
7+
return language;
8+
}
9+
10+
const lowered = language.toLowerCase();
11+
if (lowered === "zh" || lowered === "zh-cn") {
12+
return "zh-CN";
13+
}
14+
15+
return language;
16+
}
17+
18+
const rawArgs = process.argv.slice(2);
19+
const args = [];
20+
21+
for (let index = 0; index < rawArgs.length; index += 1) {
22+
const arg = rawArgs[index];
23+
24+
if (arg === "--") {
25+
continue;
26+
}
27+
28+
if (arg === "--language") {
29+
args.push(arg, normalizeLanguageCode(rawArgs[index + 1]));
30+
index += 1;
31+
continue;
32+
}
33+
34+
if (arg.startsWith("--language=")) {
35+
const [, language] = arg.split("=", 2);
36+
args.push(`--language=${normalizeLanguageCode(language)}`);
37+
continue;
38+
}
39+
40+
args.push(arg);
41+
}
42+
43+
const result = spawnSync(
44+
"crowdin",
45+
["upload", "translations", "--config", "crowdin.yml", ...args],
46+
{
47+
stdio: "inherit",
48+
shell: true,
49+
}
50+
);
51+
52+
if (result.error) {
53+
throw result.error;
54+
}
55+
56+
process.exit(result.status ?? 1);

0 commit comments

Comments
 (0)