Skip to main content

How localise Strings with special characters and variables

3 replies [Last post]
gavdian
Offline
Joined: 2010-07-13
Points: 0

Hi all,

Is it possible to localise a String like the following:

String message = "\n" +" Game is over!" + "\n" + "\n" + "Right Answers" + ":" + "\t" + this.rightAnswers + "\n" + "Wrong Answers" + ":" + "\t" + this.wrongAnswers + "\n" + "Final Score" + ":" + "\t" + this.finalScore + "%\n\n";

If so, what should I put as a key in the Resource Editor L10N panel in order to have the above String translated?

I have tried the key e.g. "Game is over!" with a couple of translations but unfortunately it doesn't work.

Please help...

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vprise
Offline
Joined: 2003-11-07
Points: 0

You can do this with the command line tools but I suggest you avoid it. Notice that your string is assembled in runtime and includes variables so your string should essentially be comprised of the snippets which you should concate manually in code.

Just use the UIManager.localize() method to manually localize portions of the string.

gavdian
Offline
Joined: 2010-07-13
Points: 0

Thanks for the reply!

The UIManager.getInstance().localize() method needs a String KEY and a String defaultValue as input parameters. I am using LWUIT version 1.4.

Can you please assist me on how to use it when e.g. I have 2 locales "en" and "fr" and I need to localise the

String message = "\n" + "Game is over!"+ "\n" + "Right Answers" + ":" + "\t" + this.rightAnswers + "\n" + "Wrong Answers"+ ":" + "\t" + this.wrongAnswers; ?

vprise
Offline
Joined: 2003-11-07
Points: 0

Give it a key such as "gameOverMessage" and a default value such as "Game is over!". Then use it like

u.localize("gameOverMessage", "Game is over!") + "\n" + u.localize("rightAnswers", "Right Answers") +....