|
|
Isolating Locale-Specific Data |
Identifying the Locale-specific Objects
If your application has a user interface, it contains many locale-specific objects. To get started, you should go through your source code and look for objects that vary withLocale. Your list may include the objects instantiated from the following classes:You'll notice that this list doesn't contain objects representing numbers, dates, times, or currencies. The format of these objects varies with
StringComponentGraphicsImageColorAudioClipLocale, but the objects themselves do not. For example, you format aDateaccording toLocale, but you use the sameDateobject regardless ofLocale. Instead of isolating these objects in aResourceBundle, you format them with special locale-sensitive formatting classes. You'll learn how to do this in the Dates and Times section of the Formatting lesson.In general, the objects stored in a
ResourceBundleare pre-defined and ship with the product. These objects are not modified while the program is running. For instance, you should store aMenulabel in aResourceBundlebecause it is locale-specific, and will not change during the program session. However, you should not isolate in aResourceBundleaStringobject entered by the end-user in aTextField. Data such as thisStringmay vary from day to day. It is specific to the program session, not to theLocalein which the program runs.Usually, most of the objects you need to isolate in a
ResourceBundleareStringobjects. However, not allStringobjects are locale-specific. For example, if aStringis a protocol element used by inter-process communication, it doesn't need to be localized because the end-users never see it. The decision whether to localize someStringobjects is not always clear. Log files are a good example. If a log file is written by one program and read by another, then both programs are using the log file as a buffer for communication. Suppose end-users occasionally check the contents of this log file. Shouldn't the log file be localized? On the other hand, if the log file is rarely checked by end-users the cost of translation may not be worthwhile. Your decision to localize this log file depends on a number of factors: program design, ease of use, cost of translation, and supportablity.Organizing ResourceBundle Objects
You can organinze yourResourceBundleobjects by loading each one of them with a different category of objects. For example, you might want to load all of yourButtonlabels into aResourceBundlecalledButtonLabelsBundle. Loading the related objects into differentResourceBundleobjects offers several advantages:
- Your code is easier to read and maintain.
- Retrieving an object from a
ResourceBundleis faster if theResourceBundlecontains a small number of objects.- Translators will find it easier to work with smaller properties files.
Most locale-specific data consists of
Stringobjects. If yourStringobjects need to be translated, store them in aResourceBundleobject that is backed by properties files. If you use properties files, translators can add support for additional languages by creating new properties files. Your localizers won't have to call you up and ask you to create more classes every time a newLocalerequires support.
|
|
Isolating Locale-Specific Data |