For Programmers: Free Programming Magazines  


Home > Archive > Java Help > August 2006 > Internationalization: Translating the application to the english?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Internationalization: Translating the application to the english?
Dado

2006-08-23, 8:02 am

I was thinking about internationalization of my small app. At this moment,
tooltips and captions of about 20 buttons , table and tree is wrote in a
code. So my question is what is the easiest procedure to add one more
language to the captions of my buttons and other component ?


Thomas Fritsch

2006-08-23, 8:02 am

Dado schrieb:
> I was thinking about internationalization of my small app. At this moment,
> tooltips and captions of about 20 buttons , table and tree is wrote in a
> code. So my question is what is the easiest procedure to add one more
> language to the captions of my buttons and other component ?
>
>

You create several resource properties files (one per language),
for example:
your/package/Res.properties (default language resources)
your/package/Res_hr.properties (croatian resources)
your/package/Res_fr.properties (french resources)
your/package/Res_de.proeprties (german resources)
...
In your Java code you simply call
ResourceBundle bundle = ResourceBundle.getBundle("your.package.Res");
which will magically load the resources of your system's language.

For more info see the API doc of class
java.util.ResourceBundle#getBundle. And for examples of the properties
files see the API doc of java.util.PropertyResourceBundle.

--
Thomas
Thomas Fritsch

2006-08-23, 8:02 am

Thomas Fritsch schrieb:
> In your Java code you simply call
> ResourceBundle bundle = ResourceBundle.getBundle("your.package.Res");
> which will magically load the resources of your system's language.


I forgot to mention the most important part.
In your Java you change all hard-coded strings. For example:
button.setText("Cancel");
to
button.setText(bundle.getString("cancelText"));
assuming that you have a line
cancelText=....
in all of your resource properties files.

--
Thomas
Dado

2006-08-24, 4:04 am


"Thomas Fritsch" <i.dont.like.spam@invalid.com> je napisao u poruci
interesnoj grupi:newscache$uheg4j$ejl$1@news.ops.de...
> Thomas Fritsch schrieb:
>
> I forgot to mention the most important part.
> In your Java you change all hard-coded strings. For example:
> button.setText("Cancel");
> to
> button.setText(bundle.getString("cancelText"));
> assuming that you have a line
> cancelText=....
> in all of your resource properties files.
>
> --
> Thomas


So simple and I procrastinate internationalization so long. Thank you.


Oliver Wong

2006-08-24, 7:02 pm


"Thomas Fritsch" <i.dont.like.spam@invalid.com> wrote in message
news:newscache$uheg4j$ejl$1@news.ops.de...
> Thomas Fritsch schrieb:
>
> I forgot to mention the most important part.
> In your Java you change all hard-coded strings. For example:
> button.setText("Cancel");
> to
> button.setText(bundle.getString("cancelText"));
> assuming that you have a line
> cancelText=....
> in all of your resource properties files.


Also, see http://java.sun.com/docs/books/tutorial/i18n/index.html

- Oliver

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com