Cordova 1.7.2 app localization

1,200 views
Skip to first unread message

Marshal

unread,
May 11, 2012, 3:40:34 AM5/11/12
to phonegap
Hi,

I'm a really noob javascript+html5 developer and I don't have any idea
about how to make my app multilingual. I've searched about this and
found some solution with globalize.js, but I think there are better
options to achieve this with phone gap + Xcode.

I've seen that in my Cordova Xcode project folder, there are some
Localizable.strings files under /Resources/en.lproj, or /Resources/
es.lproj. But I'm not able to find any documentation or example about
how to use this files to create the multilingual app.

Can you help me please?

Kerri Shotts

unread,
May 11, 2012, 5:14:10 PM5/11/12
to phon...@googlegroups.com
Use Javascript all the way... You can get the locale from a combination of navigator.language for iOS, the navigator.userAgent for Android, and various properties on WP7 (navigator.browserLanguage, systemLanguage, and userLanguage)

Define your translation matrix, set up some convenience functions (I use __T("text"), __N(number), __C(currency), etc.) and you should be good to go. I also take $() and extend it a bit to include the locale so that I can have use HTML blocks without having to do a lot of nutty innerHTML work when dealing with paragraphs, headings, and more. For example, I might have a DIV called "welcome_enus" and one called "welcome_eses" and my $Localized("welcome") returns either the _enus or _eses version appropriately.

Or use a pre-built library. There should be several out there.

Unless you're intending to stay iOS only, I would add one more reason to stay with Javascript for this purpose: it stays multi-platform compatible, whereas you'd have to redo the work for each platform if you implemented the localization natively.

Avidan Chen

unread,
May 13, 2012, 2:12:23 AM5/13/12
to phon...@googlegroups.com
I'm using jQueryGlobalize to format date/time and messages (alerts, etc.), and jQueryLocalize to replace strings in static html (headers, lables, etc.).
 
So far it's been working great and my app is running on both Android and iOS.
 
In the deviceready event I'm retrieving the device language using navigator.userAgent, and use it to initialize jQueryGlobalize. From then on, I can format date/time and localize messages on the fly...
 
If you need any more help, let me know.

Marshal

unread,
May 15, 2012, 4:37:29 AM5/15/12
to phonegap
Ok, thank you to both. I will use jQuery Globalize then. It looks
nice :)

On 13 mayo, 08:12, Avidan Chen <socsh...@gmail.com> wrote:
> I'm using jQueryGlobalize<https://www.google.co.il/search?hl=iw&q=jquery+globalize>to format date/time and messages (alerts, etc.), and
> jQueryLocalize <https://github.com/coderifous/jquery-localize> to replace
Reply all
Reply to author
Forward
0 new messages