Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
VansFannel
Posts: 166
Registered: ‎03-04-2011
My Device: Playbook

Internationalization a webworks app for Playbook

 

I want to let user select application language. I have some texts and buttons and I want to change to the language selected by user.

 

How can I do that?

 

I'm working with webworks for Playbook.

Please use plain text.
BlackBerry Development Advisor
tneil
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Internationalization a webworks app for Playbook

There are various different ways to handle it.. .searching google for JavaScript Internationalization yields some good results.

 

Here is one example:

http://www.lingoport.com/javascript-internationalization-%E2%80%93-the-good-the-bad-and-the-ugly

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Please use plain text.
Developer
TheMarco
Posts: 669
Registered: ‎02-19-2011
My Device: BlackBerry PlayBook 32GB
My Carrier: Sprint

Re: Internationalization a webworks app for Playbook

[ Edited ]

The best way is to remove all strings from your code and have them all in an object with key-value pairs.

 

Something like:

 

var strings = {
	"en" : {
		"BUTTON_CANCEL"  : "Cancel",
		"BUTTON_SAVE" : "Save"
	},
	nl: {
		"BUTTON_CANCEL" : "Annuleer",
		"BUTTON_SAVE" : "Opslaan"
	}
}

 Now let's assume you keep the chosen language somewhere in a variable called language.

 

You can then access the right string for the user language like for example with the cancel button text:

 

strings[language].BUTTON_CANCEL

 

That will give you either 'Cancel' or 'Annuleer' depending on whether the language variable contains 'en' or 'nl'.

 

Note that this approach is only good for plain strings. If things need to be substituted in it and the location of the substituted string (like someone's name for example) varies from language to language you need to take it several steps further.

 

If needed I can elaborate on that as well but maybe this approach is already enough for your application.

 

Depending on what JS library you may be using there's also plugins / libraries available for this stuff. I know there are for JQuery at least. Not sure how good they are but you can try.

 

Hope this helps a bit!

 

Staff UI Prototyper (read: full-time hacker)


My BB10 apps: Screamager | Scientific RPN Calculator | The Last Weather App

Please use plain text.
Contributor
garciaf
Posts: 12
Registered: ‎03-15-2011
My Device: Tourch OS 6.0
My Carrier: Programmer Beginner

Re: Internationalization a webworks app for Playbook

For example you have the i18n plugging for Jquery : 

 

http://plugins.jquery.com/project/jquery_i18n_properties

 

I never tested, but I would be interested by a feedback 

 

Regards 

 

Please use plain text.
New Contributor
davidr
Posts: 8
Registered: ‎01-20-2012
My Device: Bold 9780
My Carrier: Tigo

Re: Internationalization a webworks app for Playbook

I added the l10n.js library to my WebWorks app.  Following the instructions for l10n.js I created a file which contains the different language constants.  When this WebWorks app is loaded in Firefox, the l10n.js function swaps the variable with the matching string constant based on the browser's language.  My understanding is that Firefox is passing the preferred language code in the HTTP_ACCEPT_LANGUAGE variable.  I've tested my WebWorks app in Firefox with Spanish, Portuguese, and French and the lirbary works well.

http://eligrey.com/blog/post/passive-localization-in-javascript

 

Now, I've packaged and signed the app with Ripple and loaded it to my device in the hope that the WebWorks environment on a Bb device supports the HTTP_ACCEPT_LANGUAGE environment variable.  It appears that it doesn't.  I was hoping that by changing the language on my device the WebWorks environment, which I believe is based on the WebKit browser that's part of the OS6, would pass the HTTP_ACCEPT_LANGUAGE variable to my app, and then let the l10n.js library take over.  Any suggestions?

Please use plain text.