Fix localize-ftl crashing in certain cases #4773 (#4775)

* Tweak the script to use `en-us` `.ftl` files as the source of truth.
* Update `ftl-tx` to a version that can handle referencing terms with arguments.
This commit is contained in:
Tom Najdek 2024-10-23 07:30:58 +02:00 committed by GitHub
parent 88d4598fce
commit 7c1eb0c3f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 21 deletions

View file

@ -40,15 +40,6 @@ async function getFTL() {
}
for (let sourceFileBaseName of sourceFileBaseNames) {
const ftlFilePath = join(getLocaleDir(locale), sourceFileBaseName + '.ftl');
let jsonFromLocalFTL = {};
try {
const ftl = await fs.readFile(ftlFilePath, 'utf8');
jsonFromLocalFTL = ftlToJSON(ftl);
}
catch (e) {
// no local .ftl file
}
let baseFTL;
let jsonFromEnUSFTL = {};
@ -61,8 +52,7 @@ async function getFTL() {
throw new Error(`No en-US .ftl file for ${sourceFileBaseName}.ftl`);
}
const mergedSourceJSON = { ...jsonFromEnUSFTL, ...jsonFromLocalFTL };
const sourceKeys = Object.keys(mergedSourceJSON);
const sourceKeys = Object.keys(jsonFromEnUSFTL);
const translated = new Map();
for (let key of sourceKeys) {
@ -71,7 +61,7 @@ async function getFTL() {
translated.set(key, jsonFromTransifex[key]);
}
else {
translated.set(key, mergedSourceJSON[key]);
translated.set(key, jsonFromEnUSFTL[key]);
}
}

15
package-lock.json generated
View file

@ -40,7 +40,7 @@
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.0.4",
"fs-extra": "^3.0.1",
"ftl-tx": "^0.15.1",
"ftl-tx": "^0.16.0",
"globby": "^6.1.0",
"jspath": "^0.4.0",
"mocha": "^10.4.0",
@ -3667,11 +3667,10 @@
}
},
"node_modules/ftl-tx": {
"version": "0.15.1",
"resolved": "https://registry.npmjs.org/ftl-tx/-/ftl-tx-0.15.1.tgz",
"integrity": "sha512-NEaZVw0nVGy+TK7GpZx8q4u99eUbkg0Yhsh9c9r/kgnPIfHFrS/v9kn8YBDYxwBe/CqmnGPmOuuwXUGdILjSNQ==",
"version": "0.16.0",
"resolved": "https://registry.npmjs.org/ftl-tx/-/ftl-tx-0.16.0.tgz",
"integrity": "sha512-vQgx4oRtBCoVhoda5vSwRF50ukR1+U027on3ncehFsNFAehNfZfe6WzJZpyMXip1IbswPcoF4haAtlLkbvubcA==",
"dev": true,
"license": "AGPL-3.0",
"dependencies": {
"@fluent/syntax": "^0.19.0"
}
@ -10586,9 +10585,9 @@
}
},
"ftl-tx": {
"version": "0.15.1",
"resolved": "https://registry.npmjs.org/ftl-tx/-/ftl-tx-0.15.1.tgz",
"integrity": "sha512-NEaZVw0nVGy+TK7GpZx8q4u99eUbkg0Yhsh9c9r/kgnPIfHFrS/v9kn8YBDYxwBe/CqmnGPmOuuwXUGdILjSNQ==",
"version": "0.16.0",
"resolved": "https://registry.npmjs.org/ftl-tx/-/ftl-tx-0.16.0.tgz",
"integrity": "sha512-vQgx4oRtBCoVhoda5vSwRF50ukR1+U027on3ncehFsNFAehNfZfe6WzJZpyMXip1IbswPcoF4haAtlLkbvubcA==",
"dev": true,
"requires": {
"@fluent/syntax": "^0.19.0"

View file

@ -49,7 +49,7 @@
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.0.4",
"fs-extra": "^3.0.1",
"ftl-tx": "^0.15.1",
"ftl-tx": "^0.16.0",
"globby": "^6.1.0",
"jspath": "^0.4.0",
"mocha": "^10.4.0",