[WG: I18N & L10N] Best way to handle i18n bundles in client side Javascript

Matthew Jones matthew at longsight.com
Fri Jul 6 08:41:00 PDT 2012


I was recently working on on feature on Schedule/Calendar which was making
some ajax calls all client side, and I wanted to pass some return text back
based on a success or failure. Ideally this message would be displayed in
the UI and be i18n'd, however when searching through the docs, they were
mostly incomplete relating the javascript and there didn't appear to be any
great existing way of doing it.
https://confluence.sakaiproject.org/display/I18N/Best+Practices+for+Internationalized+Tools+in+Sakai#BestPracticesforInternationalizedToolsinSakai-Javascriptbasedtoolsjavascript

What was there was a presentation from Lovemore about how for evaluation,
they created a new Provider (the EvalResourcesProvider) which returns json
pairs of all messages in evaluation. I was thinking it would be great if
rather than having every tool write this, we could have a central provider
(maybe in the config project) which could return json for any message
bundle and any locale (or the current users preferred locale if not
specified). Ideally an external way to:

String getString(bundleName,key) {


return ResourceBundle.getBundle(bundleName,
getUserPreferredLocale()).getString(key);


}

Or possibly more efficiently, just return the entire bundle in the
UsersPreferredLocale as json.

ResourceBundle getBundle(bundleName) {


return ResourceBundle.getBundle(bundleName, getUserPreferredLocale();


}


The problem is that otherwise there's no way to know the users preferred
locale, and there's no reliable way to get the properties off of a standard
http call (like with the jquery-i18n-properties library). The only other
way I can think of is to pass the entire bundle (or at least the values I
need) as javascript values when creating the template, but this seems
easier in the long run.

Has anyone thought about this any further and did any work on this?

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://collab.sakaiproject.org/pipermail/i18n/attachments/20120706/9a4094a3/attachment.html 


More information about the i18n mailing list