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
New Developer
Posts: 3
Registered: ‎02-11-2010
My Device: Curve 8300
My Carrier: Entel PCS
Accepted Solution

Using variables on localization files

[ Edited ]

Hi all!

I would like to know if is it possible to use variables on rrh files, so them could be replaced with dynamic text while app is running.

 

My point is, I need to to display this message on an alert:

 

"Hi Carlos, nice to see you again", when "Carlos" is the user name and of course it's different on each installation.

 

Should be something like this: 

 

key: GREETINGS_MSG

value: Hi %s, nice to see you again

 

And then,

Dialog.alert(_res.getString(GREETINGS_MSG, "Carlos").

 

So, Is there any way to do this?

 

Thank you!

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: Using variables on localization files

Why not use replace after getting the string from the localization file?

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
New Developer
Posts: 3
Registered: ‎02-11-2010
My Device: Curve 8300
My Carrier: Entel PCS

Re: Using variables on localization files

That's an option, but I'd like to know if is it an "official" approach to this problem.

 

Thank you.

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: Using variables on localization files

[ Edited ]

Based on what you are asking for, this is what I've found.

 

See if you can try this:

 

http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/i18n/MessageFormat.html

http://java.sun.com/j2se/1.3/docs/api/java/text/MessageFormat.html

 

Example:

 

 

Object[] arguments = {
new Integer(7),
new Date(System.currentTimeMillis()),
"a disturbance in the Force"
};

String result = MessageFormat.format(
"At {1,time} on {1,date}, there was {2} on planet {0,number,integer}.",
arguments);

 

 

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Highlighted
New Developer
Posts: 3
Registered: ‎02-11-2010
My Device: Curve 8300
My Carrier: Entel PCS

Re: Using variables on localization files

Hey Jerome, that works great, 

 

Thank you!!