Default to msgid string if not found

This commit is contained in:
Matthew Taylor 2015-12-01 09:37:56 -05:00
parent 6adb6dd210
commit 75dc3ee630
4 changed files with 11 additions and 5 deletions

View file

@ -57,16 +57,17 @@ glob(poUiDir + '/*', function (err, files) {
var pyFile = path.resolve(file, 'LC_MESSAGES/django.po');
var translations = {};
try {
var jsTranslations = po2icu.poFileToICUSync(lang, jsFile);
translations = localeCompare.mergeNewTranslations(translations, jsTranslations, md5WithIds);
translations = localeCompare.mergeNewTranslations(translations, jsTranslations, idsWithICU, md5WithIds);
} catch (err) {
process.stdout.write(lang + ': ' + err + '\n');
}
try {
var pyTranslations = po2icu.poFileToICUSync(lang, pyFile);
translations = localeCompare.mergeNewTranslations(translations, pyTranslations, md5WithIds);
translations = localeCompare.mergeNewTranslations(translations, pyTranslations, idsWithICU, md5WithIds);
} catch (err) {
process.stdout.write(lang + ': ' + err + '\n');
}

View file

@ -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
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) {
var md5 = Helpers.getMD5(id);
if (md5Map.hasOwnProperty(md5) && newTranslations[id].length > 0) {
existingTranslations[md5Map[md5]] = newTranslations[id];
}
}
//Fill in defaults
for (var id in icuTemplate) {
if (!existingTranslations.hasOwnProperty(id)) existingTranslations[id] = icuTemplate[id];
}
return existingTranslations;
};

View file

@ -8,7 +8,7 @@ var buildLocales = require('../../lib/locale-compare');
tap.test('buildLocalesFile', function (t) {
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 translations = buildLocales.mergeNewTranslations({}, newTranslations, md5map);
var translations = buildLocales.mergeNewTranslations({}, newTranslations, {}, md5map);
t.ok(translations['test.id1'] !== undefined);
t.ok(translations['test.id2'] !== undefined);

View file

@ -16,7 +16,7 @@ tap.test('buildLocalesMergeTranslations', function (t) {
'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.test2'] !== undefined);
t.end();