lgalfaso / angular-dynamic-locale

Module to be able to change the locale at an angularjs application
http://lgalfaso.github.io/angular-dynamic-locale/
MIT License
322 stars 75 forks source link

Any examples for loading directly into cache? #93

Open amritk opened 8 years ago

amritk commented 8 years ago

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?

evilaliv3 commented 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

lgalfaso commented 8 years ago

@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!

lgalfaso commented 8 years ago

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.

npm install angular-i18n
node generateLocales.js > tmhPreloadedLocales.js
evilaliv3 commented 8 years ago

i 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

lgalfaso commented 8 years ago

@evilaliv3 thanks, updated the code and the comment.

schnatterer commented 8 years ago

Thanks for your work guys! In case anyone is trying to use this with gulp (like me), here's a more elaborate example.

yboug commented 8 years ago

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

lgalfaso commented 8 years ago

@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:

If you put this script together, please post it in this thread.

yboug commented 8 years ago

@lgalfaso Thanx for your response. I use IE 9. So i dont'think thats this problem come from IE version

yboug commented 8 years ago

@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);

lgalfaso commented 8 years ago

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 .