mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 01:25:52 -05:00
214430b0c4
This moves all locale/translation building to a dependency, `scratch-www-intl-loader`, as well as tests associated with it. Also gets rid of the `make translations` step.
45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
var glob = require('glob');
|
|
var path = require('path');
|
|
var po2icu = require('po2icu');
|
|
|
|
var localeCompare = require('./bin/lib/locale-compare');
|
|
|
|
module.exports = function (source) {
|
|
this.cacheable();
|
|
|
|
var poUiDir = path.resolve(__dirname, './node_modules/scratchr2_translations/ui');
|
|
var viewIds = JSON.parse(source);
|
|
var viewLocales = {
|
|
en: viewIds
|
|
};
|
|
var icuWithIds = {};
|
|
for (var id in viewIds) {
|
|
icuWithIds[viewIds[id]] = id;
|
|
}
|
|
var md5WithIds = localeCompare.getMD5Map(icuWithIds);
|
|
|
|
var files = glob.sync(poUiDir + '/*');
|
|
files.forEach(function (file) {
|
|
var lang = file.split('/').pop();
|
|
var jsFile = path.resolve(file, 'LC_MESSAGES/djangojs.po');
|
|
var pyFile = path.resolve(file, 'LC_MESSAGES/django.po');
|
|
|
|
var translations = {};
|
|
try {
|
|
var jsTranslations = po2icu.poFileToICUSync(lang, jsFile);
|
|
translations = localeCompare.mergeNewTranslations(translations, jsTranslations, viewIds, md5WithIds);
|
|
} catch (err) {
|
|
process.stdout.write(lang + ': ' + err + '\n');
|
|
}
|
|
try {
|
|
var pyTranslations = po2icu.poFileToICUSync(lang, pyFile);
|
|
translations = localeCompare.mergeNewTranslations(translations, pyTranslations, viewIds, md5WithIds);
|
|
} catch (err) {
|
|
process.stdout.write(lang + ': ' + err + '\n');
|
|
}
|
|
|
|
viewLocales[lang] = translations;
|
|
});
|
|
|
|
return 'module.exports = ' + JSON.stringify(viewLocales, undefined, '\t') + ';';
|
|
};
|