Skip to content

Instantly share code, notes, and snippets.

@steelx
Forked from lgalfaso/generateLocales.js
Created October 26, 2016 12:52
Show Gist options
  • Save steelx/d9ce68c7894719088f47cb4e91b47d6b to your computer and use it in GitHub Desktop.
Save steelx/d9ce68c7894719088f47cb4e91b47d6b to your computer and use it in GitHub Desktop.
var fs = require('fs');
// Specify the locales you are interested here.
var locales = ['en', 'fr'];
var i;
var localesData = Object.create(null);
var prefix = 'data:text/javascript;base64,';
var outputPrefix = "angular.module('tmh.dynamicLocalePreload', ['tmh.dynamicLocale'])" +
".config(['tmhDynamicLocaleProvider', function(tmhDynamicLocaleProvider) {" +
"tmhDynamicLocaleProvider.localeLocationPattern('{{base64Locales[locale]}}');" +
"tmhDynamicLocaleProvider.addLocalePatternValue('base64Locales', "
var outputSuffix = ");" +
"}]);";
// Read all the locales and base64 encode them.
for (i = 0; i < locales.length; ++i) {
localesData[locales[i]] = prefix + base64(
fs.readFileSync('../node_modules/angular-i18n/angular-locale_' + locales[i] + '.js', 'utf8'));
}
console.log(outputPrefix);
console.log(JSON.stringify(localesData));
console.log(outputSuffix);
function base64(content) {
return new Buffer(content).toString('base64');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment