Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.