Few fixes to ftl-to-json
and localize-ftl
scripts (#3707)
* Omit msg-ref-only strings from Transifex JSON * Fix msg-ref-only strings not included in translated .ftl files * Update ftl-tx. Simplify localize-ftl script. * Tweak FTL -> JSON conversion to produce a single file
This commit is contained in:
parent
f8a8f694b4
commit
b7244998a1
5 changed files with 71 additions and 58 deletions
|
@ -6,25 +6,36 @@ import { ftlFileBaseNames as sourceFileBaseNames } from './config.js';
|
|||
import { onError, onProgress, onSuccess } from './utils.js';
|
||||
|
||||
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const TRANSIFEX_FILE_NAME = 'zotero.json';
|
||||
|
||||
async function getJSON() {
|
||||
const t1 = performance.now();
|
||||
const sourceDir = join(ROOT, 'chrome', 'locale', 'en-US', 'zotero');
|
||||
const destFile = join(sourceDir, TRANSIFEX_FILE_NAME);
|
||||
let messagesMap = new Map();
|
||||
|
||||
for (let sourceFileBaseName of sourceFileBaseNames) {
|
||||
const sourceFile = join(sourceDir, sourceFileBaseName + '.ftl');
|
||||
const destFile = join(sourceDir, sourceFileBaseName + '.json');
|
||||
const ftl = await fs.readFile(sourceFile, 'utf8');
|
||||
const json = ftlToJSON(ftl, { transformTerms: false, storeTermsInJSON: false });
|
||||
await fs.outputJSON(destFile, json, { spaces: '\t' });
|
||||
onProgress(destFile, destFile, 'json');
|
||||
}
|
||||
const t2 = performance.now();
|
||||
return ({
|
||||
action: 'ftl->json',
|
||||
count: sourceFileBaseNames.length,
|
||||
totalCount: sourceFileBaseNames.length,
|
||||
processingTime: t2 - t1
|
||||
const json = ftlToJSON(ftl, { transformTerms: false, storeTermsInJSON: false, skipRefOnly: true });
|
||||
Object.entries(json).forEach(([key, value]) => {
|
||||
if (messagesMap.has(key)) {
|
||||
throw new Error(`Duplicate key: ${key} found in file ${sourceFileBaseName}.ftl`);
|
||||
}
|
||||
messagesMap.set(key, value);
|
||||
});
|
||||
onProgress(`${sourceFileBaseName}.ftl`, TRANSIFEX_FILE_NAME, 'ftl->json');
|
||||
}
|
||||
|
||||
const messagesJSON = Object.fromEntries(messagesMap);
|
||||
await fs.outputJSON(destFile, messagesJSON, { spaces: '\t' });
|
||||
const t2 = performance.now();
|
||||
return ({
|
||||
action: 'ftl->json',
|
||||
count: sourceFileBaseNames.length,
|
||||
totalCount: sourceFileBaseNames.length,
|
||||
processingTime: t2 - t1
|
||||
});
|
||||
}
|
||||
|
||||
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue