using amplify for i18n

41 views
Skip to first unread message

Stefano Cudini

unread,
Dec 2, 2013, 11:33:53 AM12/2/13
to ampl...@googlegroups.com
hello
I'm using amplify for the first time

To begin, I'm using amplify.store to store a json file that contains localized strings for i18n module of my application

anyone ever used to amplify manage i18n?
how did you proceed?

I load a json file on boot, but the problem is that I should refresh this file when the server side json file is updated with new strings

App.loadI18n = function(callback)
{
var storeKey = "i18n-" + App.lang;

if( !amplify.store(storeKey) )
{
$.getJSON("/i18n/" + App.opts.lang + ".json", function(json) {

App.i18n = amplify.store(storeKey, json );

if($.isFunction(callback))
callback( App.i18n );
});
}
else
{
App.i18n = amplify.store(storeKey);
if($.isFunction(callback))
callback( App.i18n );
}
};

Stefano Cudini

unread,
Jan 22, 2014, 10:20:09 PM1/22/14
to ampl...@googlegroups.com
I do not want to believe that no one has used to amplify this purpose!  :-(

Doug Neiner

unread,
Jan 23, 2014, 12:02:05 AM1/23/14
to ampl...@googlegroups.com
Hi Stefano,

Sorry you had to ping the list twice before getting an answer!

Your JavaScript won’t know your server file has changed, so you’ll need to either automatically expire your storage or use a few other approaches.

You can set an automatic caching length when you store the file:

amplify.store(storeKey, json, { expires: 24 * 60 * 60 * 1000 }); // cache for 24 hours

Another approach depends on when/how the i18n files change. If they change only when code that uses them changes, and all your JS is rebuilt – you can use a hard coded timestamp that you update in your JS (or as part of your build step) when your code should refresh the store.

You’d want to store that timestamp using amplify.store after checking if the hardcoded date is greater than the existing stored date. When you have updated the JS and i18n files, this date will be out of sync and you can clear out your i18n cache and reload it.

Or, if you are already versioning your JS, you could compare the version of the app with one you stored in amplify.store and automatically re-fetch the i18n files when the app version changes.

Hope some of these ideas give you a nice approach short of reaching out to your server to see if the file has changed.

Doug
--
You received this message because you are subscribed to the Google Groups "Amplify" group.
To unsubscribe from this group and stop receiving emails from it, send an email to amplifyjs+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages