Localization is built in – You can install a “resource bundle” (Hashtable in LWUIT, ME has no resource bundles), into the PLAF and most of the components (buttons, labels, check boxes etc…) will be automatically localized.

Using Resource editor you can enter the key,value pairs of all string used in the application and different locale and select or load on at run-time to be used in the app.

try
{
// where string.res in your resource 
// file which as locale as language resource in it.
Resources res = Resources.open(MIDlet.class.getResourceAsStream("/strings.res")); 
//Dynamic resource initialized into a locale hash table
locale = res.getL10N("locale","name of needed language locale matching to value column in res file" );
}
catch(Exception e)
{
System.out.println("Exception in loading resource from jar");
}

/// using locale based string
String welcome = (String) locale.get("key.welcome");
g.drawString(welcome);
textArea.setText(welcome);
This article is about: Code Sample, J2ME, LWUIT,

Stacktips

StackTips provides programming tutorials, how-to guides and code snippets on different programming languages. Follow us on Twitter

Join The Discussion

Please note: We reserve the right to delete comments that contains snarky remarks, offensive or off-topic. To know more read our comments policy.