mirror of
https://github.com/scratchfoundation/scratch-l10n.git
synced 2024-12-22 13:42:30 -05:00
50761ad970
* tx-pull-www: pull www translations from transifex * validate-www: check www for correct placeholders * add commands to pull and validate www to package.json * add validating www to the test step * add pulling www to the update-translations script for the cron job * changed .tx/config to match the new folder names `scratch-website.<resource-slug>`, and added missing folders. This isn’t needed for the scripts, but it’s useful if you need to pull the translation for a single language/resource
63 lines
1.7 KiB
JavaScript
Executable file
63 lines
1.7 KiB
JavaScript
Executable file
#!/usr/bin/env babel-node
|
|
|
|
/**
|
|
* @fileoverview
|
|
* Script to validate the www translation json
|
|
*/
|
|
|
|
const args = process.argv.slice(2);
|
|
const usage = `
|
|
Validate translation json. Usage:
|
|
babel-node validate_www.js path
|
|
path: root folder for all the www resource folders
|
|
`;
|
|
if (args.length < 1) {
|
|
process.stdout.write(usage);
|
|
process.exit(1);
|
|
}
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import glob from 'glob';
|
|
import async from 'async';
|
|
import {validateTranslations} from './tx-util.js';
|
|
import locales from '../src/supported-locales.js';
|
|
|
|
// Globals
|
|
const WWW_DIR = path.resolve(args[0]);
|
|
const RESOURCES = glob.sync(`${path.resolve(WWW_DIR)}/*`);
|
|
|
|
const validate = (localeData, callback) => {
|
|
fs.readFile(localeData.localeFileName, function (err, data) {
|
|
if (err) callback(err);
|
|
// let this throw an error if invalid json
|
|
data = JSON.parse(data);
|
|
const translations = {
|
|
locale: localeData.locale,
|
|
translations: data
|
|
};
|
|
validateTranslations(translations, localeData.sourceData);
|
|
});
|
|
};
|
|
|
|
const validateResource = (resource, callback) => {
|
|
const source = JSON.parse(fs.readFileSync(`${resource}/en.json`));
|
|
const allLocales = Object.keys(locales).map(loc => {
|
|
return {
|
|
locale: loc,
|
|
localeFileName: `${resource}/${loc}.json`,
|
|
sourceData: source
|
|
};
|
|
});
|
|
async.each(allLocales, validate, function (err) {
|
|
if (err) {
|
|
callback(err);
|
|
}
|
|
});
|
|
};
|
|
|
|
async.each(RESOURCES, validateResource, function (err) {
|
|
if (err) {
|
|
console.error(err); // eslint-disable-line no-console
|
|
process.exit(1);
|
|
}
|
|
});
|