Open amritk opened 8 years ago
I think also that something like this would be really valuable.
@lgalfaso does the library support loading a data uri via in a way like localeLocationPattern(datauri) ?
if yes one in the build process could simply do a rewrite from localeLocationPattern(/file/path/for/lang) to localeLocationPattern(dataUriOf(/file/path/for/lang))
We are doing it in GlobaLeaks in our build process for other reasons and it works great in general: https://github.com/globaleaks/GlobaLeaks/blob/master/client/Gruntfile.js#L9
@evilaliv3 it should work in any browser that allows <script src="data:text/javascript;base64,..."></script>
, but it is kind of clunky. That I why I just cut release 0.1.32 that adds the method tmhDynamicLocaleProvider.addLocalePatternValue
to add a local value to the interpolation locale location pattern. Eg.
// Untested code.
tmhDynamicLocaleProvider.addLocalePatternValue('base64Locales',
{
'en': 'data:text/javascript;base64,TheEnglishLocaleInBase64',
'fr': 'data:text/javascript;base64,TheFrenchLocaleInBase64'
});
tmhDynamicLocaleProvider.localeLocationPattern('{{base64Locales[locale]}}');
If you would like to give it a spin, it would be great!
I am sure that this can be cleaned up a lot, but given the number of people that are asking for this I will post it here.
Note: This only works with versions 0.1.32 or newer.
generateLocales.js
with this content https://gist.github.com/lgalfaso/cb18110aa2d87279884dd18fe1fbf851generateLocales.js
to generate the locales you are interested in.npm install angular-i18n
node generateLocales.js > tmhPreloadedLocales.js
tmhPreloadedLocales.js
into your project'tmh.dynamicLocalePreload'
to the dependencies of your projecti leave here some comment so that we can iterate on a good solution eventually to be integrated in the library.
new Buffer(content).toString('base64')
does not require to use other libraries not already included in node like js-base64
i will be back also when finalized the solution that we are integratin in GlobaLeaks
@evilaliv3 thanks, updated the code and the comment.
Thanks for your work guys! In case anyone is trying to use this with gulp (like me), here's a more elaborate example.
Hey, I have the same problem this solution worked for me on chrome and firefox but not work on IE @lgalfaso if you have an idea how to solve it on IE
@yboug the solution posted should work with relative new version of IE without any issues. For older versions you will have to work around the limitation of IE on data
schema in script
. A possible workaround would be:
Modify the solution in this thread so it generates a module that:
localeMap
$cache
(that I am going to call localeCache
) that, when asked for a key (that is one of the key that should be pre-loaded), does:
localeMap
angular.injector(['ngLocale']).localInjector.get('$locale');
tmhDynamicLocaleCache
and replace it with localeCache
If you put this script together, please post it in this thread.
@lgalfaso Thanx for your response. I use IE 9. So i dont'think thats this problem come from IE version
@lgalfaso i use another approch to manage this: i add a gulp task: 1) gulp.task('angularI18n',function () { return gulp.src('bower_components/angular-i18n/**.js') .pipe(gulp.dest(path.join(conf.paths.dist, '/angular-i18n'))) });
2) add 'tmh.dynamicLocale' to angular.module 3)add this two line into app.config.js tmhDynamicLocaleProvider.localeLocationPattern('angular-i18n/angular-locale_{{locale | lowercase}}.js'); tmhDynamicLocaleProvider.defaultLocale(navigator.language);
Hi, The solution you posted is good and it solves the issue of how to pack the locales in your app. It does not solve the other issue raised here that is to populate the cache with the locales so they do not have to be loaded from the server.
Anyhow, thanks for your post and I hope that this also help other developers.
On Thu, Sep 29, 2016 at 2:38 PM, yboug notifications@github.com wrote:
@lgalfaso https://github.com/lgalfaso i use another approch to manage this: i add a gulp task: 1) gulp.task('angularI18n',function () { return gulp.src('bower_components/angular-i18n/**.js') .pipe(gulp.dest(path.join(conf.paths.dist, '/angular-i18n'))) });
2) add 'tmh.dynamicLocale' to angular.module 3)add this two line into app.config.js tmhDynamicLocaleProvider.localeLocationPattern(' angular-i18n/angular-locale_{{locale | lowercase}}.js'); tmhDynamicLocaleProvider.defaultLocale(navigator.language);
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lgalfaso/angular-dynamic-locale/issues/93#issuecomment-250454030, or mute the thread https://github.com/notifications/unsubscribe-auth/AAX44gyYWJA8TM78YOVz2M2NlbN_B9gVks5qu7FHgaJpZM4H9KMY .
I'll probably create a gulp plugin or something that would load selected locales directly into the cache so there's no need to load a file on language change. Could you provide an example of what to load into the cache?