mirror of
https://github.com/scratchfoundation/scratch-l10n.git
synced 2024-12-22 13:42:30 -05:00
c286f62d69
* bumped minor version * added localeMap for converting between transifex locales and the ones used by Scratch (e.g., pt-br - pt_BR) * using the transifex node package to automatically sync translations * added scripts: * sync_tx_src: uploads an en.json source file, for use by client packages * sync_tx_translations: downloads gui translations, used by this repo, flattens Chrome i18n json into plain key-value json. * sync_tx_blocks: same as above, but blocks need slightly different handling * validate_translations: check the translation json files for basic translation errors * tx_util - methods shared by sync and validate * simplified build-data because jsons have already been flattened * added new npm tasks
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
#!/usr/bin/env babel-node
|
|
|
|
/**
|
|
* @fileoverview
|
|
* Script to validate the translation json
|
|
*/
|
|
|
|
const args = process.argv.slice(2);
|
|
const usage = `
|
|
Validate translation json. Usage:
|
|
babel-node validate_translations.js path
|
|
path: where to find the downloaded json files
|
|
`;
|
|
// Fail immediately if the TX_TOKEN is not defined
|
|
if (args.length < 1) {
|
|
process.stdout.write(usage);
|
|
process.exit(1);
|
|
}
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import async from 'async';
|
|
import {validateTranslations} from './tx_util.js';
|
|
import locales from '../src/supported-locales.js';
|
|
|
|
// Globals
|
|
const JSON_DIR = path.resolve(args[0]);
|
|
|
|
const source = JSON.parse(fs.readFileSync(`${JSON_DIR}/en.json`));
|
|
|
|
const validate = (locale, callback) => {
|
|
fs.readFile(`${JSON_DIR}/${locale}.json`, function (err, data) {
|
|
if (err) callback(err);
|
|
// let this throw an error if invalid json
|
|
data = JSON.parse(data);
|
|
const translations = {
|
|
locale: locale,
|
|
translations: data
|
|
};
|
|
validateTranslations(translations, source);
|
|
});
|
|
};
|
|
|
|
async.each(Object.keys(locales), validate, function (err) {
|
|
if (err) {
|
|
console.error(err); // eslint-disable-line no-console
|
|
process.exit(1);
|
|
}
|
|
});
|