10-04-2012 02:33 AM
Hello everyone !
This is my first post and I feel good about it
I have created two resource files and now I want the user to select the language so that the app refreshes itself to that locale, Here's how I did it.
public static String localizeString(int key) {
String appLocale = ConfigManager.getLanguage();
String localizedString = "";
if(appLocale.equals("en")){
ResourceBundle _resources = ResourceBundle.getBundle(0x8db49c0ed78e47deL, "com.blackberry.util.LocalizeEN");
localizedString = _resources.getString(key);
}
else if(appLocale.equals("es")){
ResourceBundle _resources = ResourceBundle.getBundle(0x6185d12a6d73a498L, "com.blackberry.util.LocalizeES");
localizedString = _resources.getString(key);
}
return localizedString;
} I have implemented two interfaces created by BlackBerry but when I call this method it says the field is ambigous probably because it doesn't know from what resource to pick value. Please help ![]()
Solved! Go to Solution.
10-04-2012 02:50 AM
Hi @atif_imran
Check out this link:
https://developer.blackberry.com/java/documentatio
Hope that helps,
E.
10-04-2012 02:57 AM
Unfortunately that's not what I am looking for. The example simply picks the resources from one file. In my case I am truing it with two rrh(bundle) files so that the localization is done instantly wihout changing the Device langugage setting.
10-04-2012 03:04 AM
Hi Atif
you can do the language localization via very simple way.
create the resource localization file in your project and add the value and key pair of the texts which you want in your project.
use this code for the language localization it will automatically take the text according to your app language.
public ResourceBundle testResources = ResourceBundle.getBundle(TestResourceResource.BUNDLE_ID,TestResourceResource.BUNDLE_NAME); testResources.getString(TestResourceResource.lblTe st);
here TestResource is the name of the resource file which you can create in your project.
10-04-2012 03:35 AM
Thanks, but if you see my code I have taken a parameter 'key' in my method so that I can dynamically display the localized text in my app. So, I cannot use any specific key like the 'lblTest'
10-04-2012 03:59 AM
Hi Atif
can i know that why are you using two separate resource bundles for diff diff language? You can do this via single resource bundle and i think key ramains unique for the multiple languages.
10-04-2012 04:47 AM
I am giving user an option to select a language and when he does the screen refreshes and the screen content also gets localized. Now depending upon the app language the bundle should be selected. If my app language is "es" how do I pick the es.rrc?
10-04-2012 05:25 AM
Thank you all!
Finally I did what I wanted ![]()
if(appLocale.equals("en")){
ResourceBundle _resources = ResourceBundle.getBundle(LocalizationResource.BUND LE_ID, LocalizationResource.BUNDLE_NAME).getBundle(Locale .get(Locale.LOCALE_en));
localizedString = _resources.getString(key);
}
else if(appLocale.equals("es")){
ResourceBundle _resources = ResourceBundle.getBundle(LocalizationResource.BUND LE_ID, LocalizationResource.BUNDLE_NAME).getBundle(Locale .get(Locale.LOCALE_es));
localizedString = _resources.getString(key);
}I used only one resource file and simply picked up the one using
Locale.LOCALE_es and Locale.LOCALE_en
depending upon my app language.
10-04-2012 05:31 AM
use this code to set the language:
public void SetLanguage(int langType)
{
Locale _locale;
switch (langType)
{
case LanguageType.ENGLISH:
AppConstants.LANGUAGE_CODE = "en";
_locale = Locale.get(Locale.LOCALE_en);
Locale.setDefault(_locale);
break;
case LanguageType.ARABIC:
AppConstants.LANGUAGE_CODE = "ar";
_locale = Locale.get(Locale.LOCALE_ar);
Locale.setDefault(_locale);
break;
default:
_locale=Locale.getDefault();
Locale.setDefault(_locale);
break;
}
}
10-04-2012 05:40 AM
good to know. ![]()