Question: I have developed an
application. At present the application is in English Language. Now I need to
convert this site to another languages but don't know how to do it.
Can anybody tell me the way to do it... I do not want to rewrite every time my
code...
Part 2.
The following is a very simple example of a ResourceBundle subclass,
MyResources, that manages two resources (for a larger number of resources you
would probably use a Hashtable). Notice that you don't need to supply a value if
a "parent-level" ResourceBundle handles the same key with the same value (as for
the okKey below).
Example:
// default (English language, United States)
public class MyResources extends ResourceBundle {
public Object handleGetObject(String key) {
if (key.equals("okKey")) return "Ok";
if (key.equals("cancelKey")) return "Cancel";
return null;
}
}
// German language
public class MyResources_de extends MyResources {
public Object handleGetObject(String key) {
// don't need okKey, since parent level handles
it.
if (key.equals("cancelKey")) return "Abbrechen";
return null;
}
}
You do not have to restrict yourself to using a single family of
ResourceBundles. For example, you could have a set of bundles for exception
messages, ExceptionResources (ExceptionResources_fr, ExceptionResources_de,
...), and one for widgets, WidgetResource (WidgetResources_fr,
WidgetResources_de, ...); breaking up the resources however you like.
This tip is based on API description.
***************************************
Our older tips: March 22, 2001 - October 21, 2002
read here.
All published and not published on site tips you can find
here
9 comments | | Score: 0
|