Re: How to set locale for application at runtime?
Sabine Dinis Blochberger wrote:
Andrew Thompson wrote:
Sabine Dinis Blochberger wrote:
How to set locale for application at runtime?
...
..have tried Locale.setDefault(Locale newlocale), but it
doesn't change the strings. ...
What ouput does this example produce on that PC?
<sscce>
snipped
Output is
C:\Projekte\localetest>java LocaleTest
pt_PT
es_HN
es_PE
This seemed interesting but I'm easily confused, so I did it this way
------------------------------ 8< --------------------------
package uk.co.infotop.ukbond.test;
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;
class LocaleTest {
public static void main(String[] args) {
Locale[] allLocale = Locale.getAvailableLocales();
Arrays.sort(allLocale, new Comparator<Locale>() {
public int compare(Locale o1, Locale o2) {
return o1.toString().compareTo(o2.toString());
}
});
printLocaleInfo();
System.out.println("\nSetting default locale to 1st available");
Locale.setDefault( allLocale[0] );
printLocaleInfo();
System.out.println("\nSetting default locale to last available");
Locale.setDefault( allLocale[allLocale.length-1] );
printLocaleInfo();
}
static void printLocaleInfo() {
System.out.println("Default Locale is " + Locale.getDefault());
System.out.println("Number format " +
NumberFormat.getInstance().format(12345.67));
}
}
------------------------------ 8< --------------------------
Default Locale is en_GB
Number format 12,345.67
Setting default locale to 1st available
Default Locale is be
Number format 12 345,67
Setting default locale to last available
Default Locale is uk_UA
Number format 12.345,67