Last active
October 26, 2016 12:52
-
-
Save lgalfaso/cb18110aa2d87279884dd18fe1fbf851 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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