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

Java Development

Reply
Developer
sandeepkumar03
Posts: 117
Registered: ‎02-12-2009
My Device: Not Specified
Accepted Solution

Enable lookup from resource bundle using String key

[ Edited ]

 

Hi All,

 

To support localization of apps RIM has provided API  (Resource Bundle). We are able to use it

 

ResourceBundle.getBundle(BUNDLE_ID, BUNDLE_NAME).getString(key);

 This expects int key and that is generated by Blackberry dynamically. There are 2 cases.

 

  1. Local labels we are aware and we can provide keys for those, for these there is no issue.
  2. Error codes coming from backend. Now is not a definite list. This is String value. But we can't lookup Resource bundle using this String key. We have to check what is error code and create key for that and use that to fetch label.
if(errorCode.equals("SOME_ERROR_CODE"){
   Dialog.alert(LanguageResource.getString(SOME_ERROR_CODE));
} else if (errorCode.equals("ANOTHER_ERROR_CODE"){
   Dialog.alert(LanguageResource.getString(ANOTHER_ERROR_CODE));
}

To avoid this check, we were thinking if this was possible.

 

String msg =  LanguageResource.getString("SOME_ERROR_CODE"));
if (msg == null) // Label not found
   Dialog.alert(LanguageResource.getString("GENERAL_ERROR");
else
  Dialog.alert(msg);

 Now API is not providing support for this, is the solution to create own Properties file and load them but I think Blackberry doesn't supports reading properties file like Standard Java or may be something else. Even Reflection API is not supported in Blackberry till now, there may be support in future. This may enable to dynamically use variable name as key.

 

Has anyone faced simular situation and done some work around? Any inputs would help.

 

Regards,

Sandeep

 

Edited : Updated info about Reflection API option.

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Enable lookup from resource bundle using String key

there will never be reflection support as the base line for BB Os is J2ME, and therefor java 1.3/1.4

you will have to translate the error string to the resource key yourself.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter