本文整理汇总了Java中java.util.Locale.Builder.setLanguageTag方法的典型用法代码示例。如果您正苦于以下问题:Java Builder.setLanguageTag方法的具体用法?Java Builder.setLanguageTag怎么用?Java Builder.setLanguageTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Locale.Builder
的用法示例。
在下文中一共展示了Builder.setLanguageTag方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBug7002320
import java.util.Locale.Builder; //导入方法依赖的package包/类
public void testBug7002320() {
// forLanguageTag() and Builder.setLanguageTag(String)
// should add a location extension for following two cases.
//
// 1. language/country are "ja"/"JP" and the resolved variant (x-lvariant-*)
// is exactly "JP" and no BCP 47 extensions are available, then add
// a Unicode locale extension "ca-japanese".
// 2. language/country are "th"/"TH" and the resolved variant is exactly
// "TH" and no BCP 47 extensions are available, then add a Unicode locale
// extension "nu-thai".
//
String[][] testdata = {
{"ja-JP-x-lvariant-JP", "ja-JP-u-ca-japanese-x-lvariant-JP"}, // special case 1
{"ja-JP-x-lvariant-JP-XXX"},
{"ja-JP-u-ca-japanese-x-lvariant-JP"},
{"ja-JP-u-ca-gregory-x-lvariant-JP"},
{"ja-JP-u-cu-jpy-x-lvariant-JP"},
{"ja-x-lvariant-JP"},
{"th-TH-x-lvariant-TH", "th-TH-u-nu-thai-x-lvariant-TH"}, // special case 2
{"th-TH-u-nu-thai-x-lvariant-TH"},
{"en-US-x-lvariant-JP"},
};
Builder bldr = new Builder();
for (String[] data : testdata) {
String in = data[0];
String expected = (data.length == 1) ? data[0] : data[1];
// forLanguageTag
Locale loc = Locale.forLanguageTag(in);
String out = loc.toLanguageTag();
assertEquals("Language tag roundtrip by forLanguageTag with input: " + in, expected, out);
// setLanguageTag
bldr.clear();
bldr.setLanguageTag(in);
loc = bldr.build();
out = loc.toLanguageTag();
assertEquals("Language tag roundtrip by Builder.setLanguageTag with input: " + in, expected, out);
}
}