diff --git a/lib/bin/build-locales b/lib/bin/build-locales index 0e10738de..c315deb47 100755 --- a/lib/bin/build-locales +++ b/lib/bin/build-locales @@ -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'); } diff --git a/lib/locale-compare.js b/lib/locale-compare.js index cbd644b9a..25ac94345 100644 --- a/lib/locale-compare.js +++ b/lib/locale-compare.js @@ -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; }; diff --git a/test/functional/build_locales_complex_strings.js b/test/functional/build_locales_complex_strings.js index d67f01b4c..7e630f9ac 100644 --- a/test/functional/build_locales_complex_strings.js +++ b/test/functional/build_locales_complex_strings.js @@ -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); diff --git a/test/functional/build_locales_mergeTranslations.js b/test/functional/build_locales_mergeTranslations.js index 09b68bb3b..b3fa06f8a 100644 --- a/test/functional/build_locales_mergeTranslations.js +++ b/test/functional/build_locales_mergeTranslations.js @@ -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();