mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-26 17:16:11 -05:00
Default to msgid string if not found
This commit is contained in:
parent
6adb6dd210
commit
75dc3ee630
4 changed files with 11 additions and 5 deletions
|
@ -57,16 +57,17 @@ glob(poUiDir + '/*', function (err, files) {
|
||||||
var pyFile = path.resolve(file, 'LC_MESSAGES/django.po');
|
var pyFile = path.resolve(file, 'LC_MESSAGES/django.po');
|
||||||
|
|
||||||
var translations = {};
|
var translations = {};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var jsTranslations = po2icu.poFileToICUSync(lang, jsFile);
|
var jsTranslations = po2icu.poFileToICUSync(lang, jsFile);
|
||||||
translations = localeCompare.mergeNewTranslations(translations, jsTranslations, md5WithIds);
|
translations = localeCompare.mergeNewTranslations(translations, jsTranslations, idsWithICU, md5WithIds);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
process.stdout.write(lang + ': ' + err + '\n');
|
process.stdout.write(lang + ': ' + err + '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var pyTranslations = po2icu.poFileToICUSync(lang, pyFile);
|
var pyTranslations = po2icu.poFileToICUSync(lang, pyFile);
|
||||||
translations = localeCompare.mergeNewTranslations(translations, pyTranslations, md5WithIds);
|
translations = localeCompare.mergeNewTranslations(translations, pyTranslations, idsWithICU, md5WithIds);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
process.stdout.write(lang + ': ' + err + '\n');
|
process.stdout.write(lang + ': ' + err + '\n');
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,18 @@ Helpers.getMD5 = function (string) {
|
||||||
ICU Map is an object in the reverse react-intl formatting (icu string as key), which will
|
ICU Map is an object in the reverse react-intl formatting (icu string as key), which will
|
||||||
help determine if the translation belongs in www currently.
|
help determine if the translation belongs in www currently.
|
||||||
*/
|
*/
|
||||||
Helpers.mergeNewTranslations = function (existingTranslations, newTranslations, md5Map) {
|
Helpers.mergeNewTranslations = function (existingTranslations, newTranslations, icuTemplate, md5Map) {
|
||||||
for (var id in newTranslations) {
|
for (var id in newTranslations) {
|
||||||
var md5 = Helpers.getMD5(id);
|
var md5 = Helpers.getMD5(id);
|
||||||
if (md5Map.hasOwnProperty(md5) && newTranslations[id].length > 0) {
|
if (md5Map.hasOwnProperty(md5) && newTranslations[id].length > 0) {
|
||||||
existingTranslations[md5Map[md5]] = newTranslations[id];
|
existingTranslations[md5Map[md5]] = newTranslations[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Fill in defaults
|
||||||
|
for (var id in icuTemplate) {
|
||||||
|
if (!existingTranslations.hasOwnProperty(id)) existingTranslations[id] = icuTemplate[id];
|
||||||
|
}
|
||||||
return existingTranslations;
|
return existingTranslations;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ var buildLocales = require('../../lib/locale-compare');
|
||||||
tap.test('buildLocalesFile', function (t) {
|
tap.test('buildLocalesFile', function (t) {
|
||||||
var md5map = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../fixtures/test_es_md5map.json'), 'utf8'));
|
var md5map = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../fixtures/test_es_md5map.json'), 'utf8'));
|
||||||
var newTranslations = po2icu.poFileToICUSync('es', path.resolve(__dirname, '../fixtures/test_es.po'));
|
var newTranslations = po2icu.poFileToICUSync('es', path.resolve(__dirname, '../fixtures/test_es.po'));
|
||||||
var translations = buildLocales.mergeNewTranslations({}, newTranslations, md5map);
|
var translations = buildLocales.mergeNewTranslations({}, newTranslations, {}, md5map);
|
||||||
|
|
||||||
t.ok(translations['test.id1'] !== undefined);
|
t.ok(translations['test.id1'] !== undefined);
|
||||||
t.ok(translations['test.id2'] !== undefined);
|
t.ok(translations['test.id2'] !== undefined);
|
||||||
|
|
|
@ -16,7 +16,7 @@ tap.test('buildLocalesMergeTranslations', function (t) {
|
||||||
'6885a345adafb3a9dd43d9f549430c88': 'test.test3'
|
'6885a345adafb3a9dd43d9f549430c88': 'test.test3'
|
||||||
};
|
};
|
||||||
|
|
||||||
var mergedTranslations = buildLocales.mergeNewTranslations(existingTranslations, newTranslations, md5map);
|
var mergedTranslations = buildLocales.mergeNewTranslations(existingTranslations, newTranslations, {}, md5map);
|
||||||
t.ok(mergedTranslations['test.test3'] !== undefined);
|
t.ok(mergedTranslations['test.test3'] !== undefined);
|
||||||
t.ok(mergedTranslations['test.test2'] !== undefined);
|
t.ok(mergedTranslations['test.test2'] !== undefined);
|
||||||
t.end();
|
t.end();
|
||||||
|
|
Loading…
Reference in a new issue