From a0d92dacfc3a6a5bac0032f915602ccb986641ca Mon Sep 17 00:00:00 2001 From: Matthew Taylor Date: Tue, 19 Jan 2016 15:52:42 -0500 Subject: [PATCH 1/2] Add general localizations to nonlocalized pages For nav/footer purposes. --- bin/build-locales | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bin/build-locales b/bin/build-locales index 878fb0e81..714174ab0 100755 --- a/bin/build-locales +++ b/bin/build-locales @@ -90,12 +90,21 @@ for (var id in generalIds) { icuWithIds[generalIds[id]] = 'general-' + id; } +// start with all views, and remove localized ones as they are iterated over +var nonLocalizedViews = glob.sync(path.resolve(__dirname, '../src/views/*')); +for (var i = 0; i < nonLocalizedViews.length; i++) { + nonLocalizedViews[i] = nonLocalizedViews[i].split('/').pop(); +} + // get view-specific locale strings. var files = glob.sync(path.resolve(__dirname, '../src/views/**/l10n.json')); files.forEach(function (file) { var dirPath = file.split('/'); dirPath.pop(); var view = dirPath.pop(); + if (nonLocalizedViews.indexOf(view) > -1) { + nonLocalizedViews.splice(nonLocalizedViews.indexOf(view), 1); + } var viewIds = JSON.parse(fs.readFileSync(file, 'utf8')); viewLocales[view] = { @@ -158,4 +167,11 @@ glob(poUiDir + '/*', function (err, files) { var fileString = 'window._messages = ' + objectString + ';'; fs.writeFileSync(outputDir + '/' + view + '.intl.js', fileString); } + + // Add general localization strings for non localized views, to account for nav/footer. + for (var i in nonLocalizedViews) { + objectString = JSON.stringify(generalLocales); + fileString = 'window._messages = ' + objectString + ';'; + fs.writeFileSync(outputDir + '/' + nonLocalizedViews[i] + '.intl.js', fileString); + } }); From 1ad1380eff76056e1b0657b6adba8f101d523576 Mon Sep 17 00:00:00 2001 From: Matthew Taylor Date: Fri, 22 Jan 2016 10:16:18 -0500 Subject: [PATCH 2/2] simplify to one loop thanks @rschamp! --- bin/build-locales | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/bin/build-locales b/bin/build-locales index 714174ab0..136ea385b 100755 --- a/bin/build-locales +++ b/bin/build-locales @@ -91,9 +91,9 @@ for (var id in generalIds) { } // start with all views, and remove localized ones as they are iterated over -var nonLocalizedViews = glob.sync(path.resolve(__dirname, '../src/views/*')); -for (var i = 0; i < nonLocalizedViews.length; i++) { - nonLocalizedViews[i] = nonLocalizedViews[i].split('/').pop(); +var views = glob.sync(path.resolve(__dirname, '../src/views/*')); +for (var i = 0; i < views.length; i++) { + views[i] = views[i].split('/').pop(); } // get view-specific locale strings. @@ -102,9 +102,6 @@ files.forEach(function (file) { var dirPath = file.split('/'); dirPath.pop(); var view = dirPath.pop(); - if (nonLocalizedViews.indexOf(view) > -1) { - nonLocalizedViews.splice(nonLocalizedViews.indexOf(view), 1); - } var viewIds = JSON.parse(fs.readFileSync(file, 'utf8')); viewLocales[view] = { @@ -161,17 +158,13 @@ glob(poUiDir + '/*', function (err, files) { } }); - for (var view in viewLocales) { - var viewTranslations = merge(viewLocales[view], generalLocales); + for (var i in views) { + var viewTranslations = generalLocales; + if (views[i] in viewLocales) { + viewTranslations = merge(viewLocales[views[i]], viewTranslations); + } var objectString = JSON.stringify(viewTranslations); var fileString = 'window._messages = ' + objectString + ';'; - fs.writeFileSync(outputDir + '/' + view + '.intl.js', fileString); - } - - // Add general localization strings for non localized views, to account for nav/footer. - for (var i in nonLocalizedViews) { - objectString = JSON.stringify(generalLocales); - fileString = 'window._messages = ' + objectString + ';'; - fs.writeFileSync(outputDir + '/' + nonLocalizedViews[i] + '.intl.js', fileString); + fs.writeFileSync(outputDir + '/' + views[i] + '.intl.js', fileString); } });