Java resource bundle: Difference between revisions

Content deleted Content added
No edit summary
m removed extra line breaks
Line 1:
A resource bundle is a [[Java (software platform)|Java]] [[.properties]] file that contains [[locale]]-specific data<ref>[http://java.sun.com/developer/technicalArticles/Intl/ResourceBundles/ O'Conner, B. ''Java Internationalization: Localization with ResourceBundles'', Sun Developer Network.]</ref>. It is a way of internationalising a Java application by making the code locale-independent.
 
 
== Naming a resource bundle ==
Resource bundles have a naming convention to identify them when they deal with different languages. The file name is followed by an underscore and a two-letter language code ([[ISO 639-2]] code) that specifies the language that the resource bundle deals with. So, for example, an application that supports Spanish and French can have these resource bundles, respectively:
 
resbund_es.properties
resbund_fr.properties
 
ResourceThis bundles have a naming convention to identify them when they deal with different languages. The filecan namealso isbe followed by ananother underscore and a two-letter languagecountry code ([[ISO 6393166-21]] code) that specifies the language that the resource bundle deals with. So,In forthis examplecase, an application that supports SpanishBritish English and FrenchUS canEnglish respectively will have thesethe resourcefollowing bundlesfiles:<br />
 
<br />
resbund_en_GB.properties<br />
resbund_es.properties (this one includes data for version in Spanish)<br />
resbund_en_US.properties<br />
resbund_fr.properties (this other one includes data for version in French)<br />
<br />
This can also be followed by another underscore and a two-letter country code ([[ISO 3166-1]]). In this case, an application that supports British and US English will have the following files:<br />
<br />
resbund_en_GB.properties<br />
resbund_en_US.properties<br />
 
== Content of a resource bundle ==
Resource bundles are essentially text files. The most common type of content in a resource bundle is a list of strings. Each string has a “key” to identify it, which is the same in all the different resource bundles. When writing the code for the application, only the key is mentioned (this is why we say that the code is locale-independent). Using the methods provided in the Java [[API]] for the ResourceBundle class<ref>[http://java.sun.com/j2se/1.5.0/docs/api/ Java API ResourceBundle Class]</ref> , we can access the string (i.e. the "value") associated with the key. Depending on which locale the application is handling, it will call the adequate resource bundle at [[runtime]]<ref>Esselink, B. ''A Practical Guide to Software Localisation'', John Benjamins Publishing (1998).</ref>. <br />
 
 
Resource bundles are essentially text files. The most common type of content in a resource bundle is a list of strings. Each string has a “key” to identify it, which is the same in all the different resource bundles. When writing the code for the application, only the key is mentioned (this is why we say that the code is locale-independent). Using the methods provided in the Java [[API]] for the ResourceBundle class<ref>[http://java.sun.com/j2se/1.5.0/docs/api/ Java API ResourceBundle Class]</ref> , we can access the string (i.e. the "value") associated with the key. Depending on which locale the application is handling, it will call the adequate resource bundle at [[runtime]]<ref>Esselink, B. ''A Practical Guide to Software Localisation'', John Benjamins Publishing (1998).</ref>. <br />
<br />
For instance, our resource bundle for the UK English locale can contain “firstKey = Localisation” and our US English one can contain “firstKey = Localization”. We will refer only to “firstKey” in the code and, according to the current locale settings, the application will use either “Localization” or “Localisation”.
 
 
== Benefits of using resource bundles ==
 
 
Extracting locale-sensitive objects such as strings from the code (as opposed to [[hard-coding]] them) means that the application can handle multiple locales without having to write different code for each locale. It also means that translators can deal with just the translatable text and not the programming code. Therefore, using resource bundles improves the [[internationalisation]] and the [[localisation]] process of a software product.
 
 
== Translating a resource bundle ==
 
 
Some [[CAT tools]] like [[OmegaT]], OmegaT+ <ref>[http://omegatplus.sourceforge.net/ OmegaT+]</ref> or Sun's [[Open language tools]] can specifically handle resource bundles. In addition to these, translators can use any [[text editor]] to create new resource bundles or to modify existing ones.
 
== References ==
 
== Notes ==
 
<references/>
 
 
[[Category:Java programming language]]