Locale names in Java consist of three parts: language code, country code, and variant code. The country and variant code are optional.
Language Code | Description |
---|---|
de | German |
en | English |
fr | French |
ja | Japanese |
ko | Korean |
zh | Chinese |
Country Code | Description |
---|---|
CN | China |
DE | Germany |
FR | France |
IN | India |
US | United States |
Examples
en_GB en_US en_US_unix en_US_8859-1 de_DE_EURO
Problems: the standard is continually modified --- Bosnia and Bosnian added.
aLocale = new Locale("fr", "CA"); bLocale = new Locale("en", "US"); cLocale = new Locale("en", "GB"); xLocale = new Locale("de", "DE", "UNIX"); yLocale = new Locale("de", "DE", "WINDOWS"); enLocale = new Locale("en", ""); j1Locale = Locale.JAPAN; j2Locale = new Locale("ja", "JP"); j3Locale = Locale.JAPANESE; j4Locale = new Locale("ja", "");
javap java.util.Locale | grep "public static final" | sort
CANADA CANADA_FRENCH CHINA CHINESE ENGLISH FRANCE FRENCH GERMAN GERMANY ITALIAN ITALY JAPAN JAPANESE KOREA KOREAN PRC SIMPLIFIED_CHINESE TAIWAN TRADITIONAL_CHINESE UK US
CANADA : English (Canada) : en_CA CANADA_FRENCH: French (Canada) : fr_CA CHINA : Chinese (China) : zh_CN CHINESE : Chinese : zh ENGLISH : English : en FRANCE : French (France) : fr_FR FRENCH : French : fr GERMAN : German : de GERMANY : German (Germany) : de_DE ITALIAN : Italian : it ITALY : Italian (Italy) : it_IT JAPAN : Japanese (Japan) : ja_JP JAPANESE : Japanese : ja KOREA : Korean (South Korea) : ko_KR KOREAN : Korean : ko RPC : Chinese (China) : zh_CN SIMPLIFIED_CHINESE: Chinese (China) : zh_CN TAIWAN : Chinese (Taiwan) : zh_TW TRADITIONAL_CHINESE: Chinese (Taiwan) : zh_TW UK : English (United Kingdom) : en_GB US : English (United States) : en_US
English | Dutch | French | German |
---|---|---|---|
apply | wekvenster | validation | anwenden |
cancel | annuleren | annulation | abbrechen |
copy | kopiëren | copie | kopieren |
delete | knippen | suppression | löschen |
edit | bewerken | amener | editiern |
exit | |||
file | Bestand | fichier | Datei |
help | Help | aide | Hilfe |
new | nieuw | nouveau | neu |
ok | ok | ||
open | openen | ouvrir | öffen |
paste | coller | enfügen | |
save | opslaan | sauvegarde | sichern |
save as | opslaan als | sauvegarde en | sichern als |
view | Beeld | Visualisation | Anzeige |
SimpleMenu.java, Menus.properties, Menus_fr.properties, Menus_en_GB.properties
Object [][] getContents()
that returns label/value pairs.
Labels must be strings which as used as arguments to the method getString(String label)
of the class ListResourceBundle.
The values are any type of object in the Java language.
Bundle.java, Labels.java, Labels_de.java
! lines beginning with ! are comments # also, lines beginning with # are comments # pairs seperated by '=' or ':' # case of labels matters: label != LaBeL label=value label:value # multiple lines can be continuate with a backslash (\)An example using string tokenizer.
classes=Betriebssysteme, Programmierung, Optimierung,\ Computationale Logik, Algorithmen classes=Operating Systems, Programming, Optimization,\ Computational Logic, Algorithms final ResourceBundle b = ResourceBundle.getBundle ("Text"); final StringTokenizer classes = new StringTokenizer (b.getString ("classes"), ","); final String c = classes.nextToken().trim();
package com.acme; getBundle ("com.acme.Labels");
Tools to create sound and image bundles...
For example,
ButtonLabel_fr_CA_UNIX ButtonLabel_fr_CA ButtonLabel_fr ButtonLabel_en_US ButtonLabel_en ButtonLabel
Class files hide properties files at the same level.
The Java NumberFormat class java.text.NumberFormat and . (See table of special pattern characters.)
Number.java -- formating numbers
7 37 537 7 37 537 7 37 537 700% 3,700% 53,700% ¤7.00 ¤37.00 ¤537.00Example use of DecimalFormat, Decimal.java, output.
Parsing
final String parseMe = "1.234,56"; final NumberFormat numParser = NumberFormat.getInstance(Locale.GERMANY); try { Number result = numParser.parse(parseMe); System.out.println(result); } catch(ParseException e) { // handle error condition }The output is 1234.56
// Malayalam digits 123456 final String parseMe = "\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26"; final NumberFormat numParser = NumberFormat.getInstance(); // No locale! try { Number result = numParser.parse(parseMe); System.out.println(result); } catch(ParseException e) { // handle error condition }The output is 123456
ArabicDigits.java from Deitsch and Czarnecki.
Java SDK 1.4 does not support ideographic number formatting; however, IBM does. You can download a class called RuleBasedNumberFormat from the ICU4J WWW site at oss.software.ibm.com/icu4j/
CalendarManipulation.java from Deitsch and Czarnecki.
> java CalendarManipulation Wednesday, April 2, 2003 4:16:29 PM Thursday, April 10, 2003 4:16:29 PM Thursday, April 10, 2003 12:16:29 PM Friday, April 11, 2003 12:16:29 AM Friday, April 11, 2003 12:16:29 PM > java -Duser.language=de CalendarManipulation Mittwoch, 2. April 2003 16:16:59 Donnerstag, 10. April 2003 16:16:59 Donnerstag, 10. April 2003 12:16:59 Freitag, 11. April 2003 00:16:59 Freitag, 11. April 2003 12:16:59 > java -Duser.language=fr CalendarManipulation mercredi 2 avril 2003 16:17:16 jeudi 10 avril 2003 16:17:16 jeudi 10 avril 2003 12:17:16 vendredi 11 avril 2003 00:17:16 vendredi 11 avril 2003 12:17:16 > java -Duser.language=es CalendarManipulation miércoles 2 de abril de 2003 16:17:52 jueves 10 de abril de 2003 16:17:52 jueves 10 de abril de 2003 12:17:52 viernes 11 de abril de 2003 0:17:52 viernes 11 de abril de 2003 12:17:52 > java -Duser.language=zh CalendarManipulation 2003?4?2? 16:19:26 2003?4?10? 16:19:26 2003?4?10? 12:19:26 2003?4?11? 0:19:26 2003?4?11? 12:19:26 > java -Duser.language=ko CalendarManipulation 2003? 4? 2? ??? ?? 4:19:41 2003? 4? 10? ??? ?? 4:19:41 2003? 4? 10? ??? ?? 12:19:41 2003? 4? 11? ??? ?? 12:19:41 2003? 4? 11? ??? ?? 12:19:41 > java -Duser.language=uk CalendarManipulation ??????, 2, ?????? 2003 16:22:11 ??????, 10, ?????? 2003 16:22:11 ??????, 10, ?????? 2003 12:22:11 ?'??????, 11, ?????? 2003 0:22:11 ?'??????, 11, ?????? 2003 12:22:11 > java -Duser.language=th CalendarManipulation ????????? 2 ?????? ?.?. 2003, 16:22:19 ?????????????? 10 ?????? ?.?. 2003, 16:22:19 ?????????????? 10 ?????? ?.?. 2003, 12:22:19 ??????????? 11 ?????? ?.?. 2003, 0:22:19 ??????????? 11 ?????? ?.?. 2003, 12:22:19
See date formatting (but this uses the Java class, see below).
The Java class takes a set of objects, formats them, then inserts the formatted strings into the pattern at the appropriate places.
MessageFormat and resource bundles
MessageFormat.parse()The Java class allows you to attach a format to a range of numbers. It is generally used in a for handling plurals. The choice is specified with an ascending list of doubles, where each item specifies a half-open interval up to the next item.
Example use of ChoiceFormat, Choice.java, output.
Latin1 Es ------ ------ agüero agüero argüir argüir caro caro carro carro carta carta cellisca célula chaleco cellisca churo cuco cuchara cuchara cuco cuna cuna cundir cundir cuña cuña chaleco célula churo día día güero güero güisquil güisquil llave lobo lobo llave maíz maíz pero pero perro perro
Swedish | German |
---|---|
banan | äpple |
orange | banan |
päron | orange |
äpple | päron |
Lexicographic | Multilevel comparison |
---|---|
Co-Op of America | Coates |
CoSelCo | Cohen |
Coates | Cooper |
Cohen | Cooperatives United |
Cooper | Co-Op of America |
Cooperatives United | CoSelCo |
Cosell | Cosell |
MacIntosh | Machinists Union |
MacPherson | Macintosh |
Machinists Union | MacIntosh |
Macintosh | Macpherson |
Macpherson | MacPherson |
Van Damme | Van Damme |
Vandenberg | Vandenberg |
van den Hul | van den Hul |
van der Waal | van der Waal |
Localize This! from Java World
NB. Extension classes are classes which extend the Java platform. Every .jar file in the extension directory, jre/lib/ext, is assumed to be an extension and is loaded using the Java Extension Framework. Only jar files can be used; not loose class files. There is no (classpath like) option provided for changing the location of the extension directory.
jar -tf /software/java/jdk1.2.2/jre/lib/rt.jar | grep .prop com/sun/java/swing/plaf/motif/resources/motif.properties com/sun/java/swing/plaf/motif/resources/motif_ja.properties com/sun/java/swing/plaf/windows/resources/windows.properties com/sun/java/swing/plaf/windows/resources/windows_ja.properties java/awt/resources/awt.properties java/awt/resources/awt_ja.properties javax/swing/plaf/basic/resources/basic.properties javax/swing/plaf/basic/resources/basic_ja.properties javax/swing/plaf/metal/resources/metal.properties javax/swing/plaf/metal/resources/metal_ja.properties sun/tools/jar/resources/jar.properties sun/awt/motif/resources/updialog.properties sun/awt/motif/resources/updialog_ja.properties sun/awt/motif/resources/printcontrol.properties sun/awt/motif/resources/printcontrol_ja.properties sun/rmi/registry/resources/rmiregistry.properties sun/rmi/rmid/resources/rmid.propertiesjavax/swing/plaf/basic/resources/basic.properties
# This properties file is used to create a PropertyResourceBundle # It contains Locale specific strings used in Swing # Currently, the following components need this for support: # # ColorChooser # FileChooser # OptionPane # # When this file is read in, the strings are put into the # defaults table. This is an implementation detail of the current # workings of Swing. DO NOT DEPEND ON THIS. # This may change in future versions of Swing as we improve localization # support. # # %I% %G% # @author Steve Wilson ############ FILE CHOOSER STRINGS ############# FileChooser.fileDescriptionText=Generic File FileChooser.directoryDescriptionText=Directory FileChooser.newFolderErrorText=Error creating new folder FileChooser.newFolderErrorSeparator= : FileChooser.acceptAllFileFilterText=All Files (*.*) FileChooser.cancelButtonText=Cancel FileChooser.saveButtonText=Save FileChooser.openButtonText=Open FileChooser.updateButtonText=Update FileChooser.helpButtonText=Help ## file chooser tooltips ### FileChooser.cancelButtonToolTipText=Abort file chooser dialog FileChooser.saveButtonToolTipText=Save selected file FileChooser.openButtonToolTipText=Open selected file FileChooser.updateButtonToolTipText=Update directory listing FileChooser.helpButtonToolTipText=FileChooser help ############ COLOR CHOOSER STRINGS ############# ColorChooser.previewText=Preview ColorChooser.okText=OK ColorChooser.cancelText=Cancel ColorChooser.resetText=Reset ColorChooser.swatchesNameText=Swatches ColorChooser.swatchesRecentText=Recent: ColorChooser.hsbNameText=HSB ColorChooser.hsbHueText=H ColorChooser.hsbSaturationText=S ColorChooser.hsbBrightnessText=B ColorChooser.hsbRedText=R ColorChooser.hsbGreenText=G ColorChooser.hsbBlueText=B ColorChooser.rgbNameText=RGB ColorChooser.rgbRedText=Red ColorChooser.rgbGreenText=Green ColorChooser.rgbBlueText=Blue ############ OPTION PANE STRINGS ############# OptionPane.yesButtonText=Yes OptionPane.noButtonText=No OptionPane.okButtonText=OK OptionPane.cancelButtonText=Cancel
Other thins in javax/swing/plaf/metal/resources/metal.properties
# This properties file is used to create a PropertyResourceBundle # It contains Locale specific strings used be the Metal Look and Feel. # Currently, the following components need this for support: # # FileChooser # # When this file is read in, the strings are put into the # defaults table. This is an implementation detail of the current # workings of Swing. DO NOT DEPEND ON THIS. # This may change in future versions of Swing as we improve localization # support. # # 1.1 08/26/98 # @author Steve Wilson ############ FILE CHOOSER STRINGS ############# FileChooser.lookInLabelText=Look in: FileChooser.fileNameLabelText=File name: FileChooser.filesOfTypeLabelText=Files of type: FileChooser.upFolderToolTipText=Up One Level FileChooser.upFolderAccessibleName=Up FileChooser.homeFolderToolTipText=Home FileChooser.homeFolderAccessibleName=Home FileChooser.newFolderToolTipText=Create New Folder FileChooser.newFolderAccessibleNam=New Folder FileChooser.listViewButtonToolTipText=List FileChooser.listViewButtonAccessibleName=List FileChooser.detailsViewButtonToolTipText=Details FileChooser.detailsViewButtonAccessibleName=Details
To internationalize built your own files basic_tr.properties and metal_tr.properties in the javax/swing/plaf directory structure and get them on the boot of the application.
Notice, this is not guaranteed to work in the future.