言語、国を定義している情報がLocale class
setVariantで使用可能なvariantはここで参照できる
https://r12a.github.io/app-subtags/
public class Outer {
public static void main(String args[]) {
printLocale(Locale.getDefault());
printLocale(Locale.JAPAN);
printLocale(new Locale("ja","JP"));
printLocale(new Locale("ja","JP","JP"));
printLocale(new Locale("ja","JP","JP1")); //variant err
Locale.Builder bl = new Locale.Builder();
bl = bl.setLanguage("jp");
bl = bl.setRegion("JP");
bl = bl.setScript("Jpan");
bl = bl.setVariant("nedis");
Locale lc = bl.build();
printLocale(lc);
printLocale(Locale.forLanguageTag("ja-JP-u-ca-japanese-x-lvariant-JP"));
printLocale(Locale.US);
printLocale(Locale.CANADA_FRENCH);
printLocale(Locale.CANADA);
printLocale(new Locale("es","ES","Traditional_WIN"));
printLocale(new Locale("xx","yy","Traditional_WIN")); //language,country err
}
static void printLocale(Locale lc) {
System.out.println("--------------");
System.out.println("getLanguage:" + lc.getLanguage());
System.out.println("getCountry:" + lc.getCountry());
System.out.println("getScript:" + lc.getScript());
System.out.println("getVariant:" + lc.getVariant());
System.out.println("getDisplayLanguage:" + lc.getDisplayLanguage());
System.out.println("getDisplayCountry:" + lc.getDisplayCountry());
System.out.println("getDisplayVariant:" + lc.getDisplayVariant());
System.out.println("getDisplayScript:" + lc.getDisplayScript());
System.out.println("toLanguageTag:" + lc.toLanguageTag());
Set<Character> s = lc.getExtensionKeys();
s.forEach(x -> System.out.println("getExtension:" + x + ":" + lc.getExtension(x)));
System.out.println("locale.toString() :" + lc);
}
}
getLanguage:ja
getCountry:JP
getScript:
getVariant:
getDisplayLanguage:日本語
getDisplayCountry:日本
getDisplayVariant:
getDisplayScript:
toLanguageTag:ja-JP
locale.toString() :ja_JP
--------------
getLanguage:ja
getCountry:JP
getScript:
getVariant:
getDisplayLanguage:日本語
getDisplayCountry:日本
getDisplayVariant:
getDisplayScript:
toLanguageTag:ja-JP
locale.toString() :ja_JP
--------------
getLanguage:ja
getCountry:JP
getScript:
getVariant:
getDisplayLanguage:日本語
getDisplayCountry:日本
getDisplayVariant:
getDisplayScript:
toLanguageTag:ja-JP
locale.toString() :ja_JP
--------------
getLanguage:ja
getCountry:JP
getScript:
getVariant:JP
getDisplayLanguage:日本語
getDisplayCountry:日本
getDisplayVariant:JP
getDisplayScript:
toLanguageTag:ja-JP-u-ca-japanese-x-lvariant-JP
getExtension:u:ca-japanese
locale.toString() :ja_JP_JP_#u-ca-japanese
--------------
getLanguage:ja
getCountry:JP
getScript:
getVariant:JP1
getDisplayLanguage:日本語
getDisplayCountry:日本
getDisplayVariant:JP1
getDisplayScript:
toLanguageTag:ja-JP-x-lvariant-JP1
locale.toString() :ja_JP_JP1
--------------
getLanguage:jp
getCountry:JP
getScript:Jpan
getVariant:nedis
getDisplayLanguage:jp
getDisplayCountry:日本
getDisplayVariant:nedis
getDisplayScript:日本語の文字
toLanguageTag:jp-Jpan-JP-nedis
locale.toString() :jp_JP_nedis_#Jpan
--------------
getLanguage:ja
getCountry:JP
getScript:
getVariant:JP
getDisplayLanguage:日本語
getDisplayCountry:日本
getDisplayVariant:JP
getDisplayScript:
toLanguageTag:ja-JP-u-ca-japanese-x-lvariant-JP
getExtension:u:ca-japanese
locale.toString() :ja_JP_JP_#u-ca-japanese
--------------
getLanguage:en
getCountry:US
getScript:
getVariant:
getDisplayLanguage:英語
getDisplayCountry:アメリカ合衆国
getDisplayVariant:
getDisplayScript:
toLanguageTag:en-US
locale.toString() :en_US
--------------
getLanguage:fr
getCountry:CA
getScript:
getVariant:
getDisplayLanguage:フランス語
getDisplayCountry:カナダ
getDisplayVariant:
getDisplayScript:
toLanguageTag:fr-CA
locale.toString() :fr_CA
--------------
getLanguage:en
getCountry:CA
getScript:
getVariant:
getDisplayLanguage:英語
getDisplayCountry:カナダ
getDisplayVariant:
getDisplayScript:
toLanguageTag:en-CA
locale.toString() :en_CA
--------------
getLanguage:es
getCountry:ES
getScript:
getVariant:Traditional_WIN
getDisplayLanguage:スペイン語
getDisplayCountry:スペイン
getDisplayVariant:Traditional、WIN
getDisplayScript:
toLanguageTag:es-ES
locale.toString() :es_ES_Traditional_WIN
--------------
getLanguage:xx
getCountry:YY
getScript:
getVariant:Traditional_WIN
getDisplayLanguage:xx
getDisplayCountry:YY
getDisplayVariant:Traditional、WIN
getDisplayScript:
toLanguageTag:xx-YY
locale.toString() :xx_YY_Traditional_WIN