With UNIX locales, the breakdown of which means what is relatively well documented.
LC_COLLATE
(string collation)LC_CTYPE
(character conversion)LC_MESSAGES
(messages shown in UI)LC_MONETARY
(formatting of monetary values)LC_NUMERIC
(formatting of non-monetary numeric values)LC_TIME
(formatting of date and time values)LANG
(fallback if any of the above are not set)
Java has a different categorisation which doesn't quite match the real world (as usual):
Locale.getDefault()
Locale.getDefault(Locale.Category.DISPLAY)
Locale.getDefault(Locale.Category.FORMAT)
If you read the documentation on these, Locale.getDefault(Locale.Category.DISPLAY)
appears to correspond to LC_MESSAGES
while Locale.getDefault(Locale.Category.FORMAT)
appears to correspond to some combination of LC_MONETARY
+LC_NUMERIC
+LC_TIME
.
There are problems, though.
If you read the JDK source, you start to find many worrying things. For instance, ResourceBundle.getBundle(String)
- which is entirely about string messages - uses Locale.getDefault()
, not Locale.getDefault(Locale.Category.DISPLAY)
.
So I guess what I want to know is:
Which of these methods is supposed to be used for which purpose?
Related, but I made a little test program to see which Java locales corresponded to which UNIX locales and got even more surprising results.
import java.util.Locale;
public class Test {
public static void main(String[] args) {
System.out.println(" Unqualified: " + Locale.getDefault());
System.out.println(" Display: " + Locale.getDefault(Locale.Category.DISPLAY));
System.out.println(" Format: " + Locale.getDefault(Locale.Category.FORMAT));
}
}
Locales according to my shell:
$ locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
Output of the program:
$ java Test
Unqualified: en_AU
Display: en_AU
Format: en_AU
So it turns out Java doesn't even get it from the UNIX locale. It must be using some other back door to get the settings without using those.