本文整理汇总了Java中java.util.Locale.lookup方法的典型用法代码示例。如果您正苦于以下问题:Java Locale.lookup方法的具体用法?Java Locale.lookup怎么用?Java Locale.lookup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Locale
的用法示例。
在下文中一共展示了Locale.lookup方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: chooseForLocale
import java.util.Locale; //导入方法依赖的package包/类
private static IProperty chooseForLocale(
final @NotNull List<Locale.LanguageRange> priorityList,
final @NotNull List<IProperty> properties
) {
if (properties.isEmpty()) {
return null;
}
IProperty first = properties.get(0);
if (properties.size() == 1) {
return first;
}
final Map<Locale, IProperty> map = new HashMap<>();
final List<Locale> locales = new LinkedList<>();
for (IProperty nextProperty : properties) {
Locale nextLocale = safeGetLocale(nextProperty);
if (nextLocale != null) {
map.put(nextLocale, nextProperty);
locales.add(nextLocale);
}
}
Locale best = Locale.lookup(priorityList, locales);
//System.err.println("found locales: " + locales + ", best: " + best + ", result: " + map.get(best));
return Optional.ofNullable(best).map(map::get).orElse(first);
}
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:26,代码来源:JspPropertyFoldingBuilder.java
示例2: getImplicitLocale
import java.util.Locale; //导入方法依赖的package包/类
/**
* Gets the locale to use if one was not explicitly provided.
*
* @return the implicit locale to use, not null
*/
@Nonnull
protected Locale getImplicitLocale() {
Locale locale = null;
if (getLocaleSupplier().isPresent()) {
locale = getLocaleSupplier().get().get();
} else if (getLanguageRangesSupplier().isPresent()) {
List<LanguageRange> languageRanges = getLanguageRangesSupplier().get().get();
if (languageRanges != null)
locale = Locale.lookup(languageRanges, getLocalizedStringsByLocale().keySet());
}
return locale == null ? getFallbackLocale() : locale;
}
示例3: checkLookup
import java.util.Locale; //导入方法依赖的package包/类
private static void checkLookup(String ranges, String tags,
String expectedLocale) {
List<Locale.LanguageRange> priorityList = Locale.LanguageRange
.parse(ranges);
List<Locale> localeList = generateLocales(tags);
Locale loc = Locale.lookup(priorityList, localeList);
String actualLocale
= loc.toLanguageTag();
if (!actualLocale.equals(expectedLocale)) {
System.err.println("Locale.lookup failed with ranges: " + ranges
+ " Expected: " + expectedLocale
+ " Actual: " + actualLocale);
err = true;
}
}
示例4: testLookup
import java.util.Locale; //导入方法依赖的package包/类
private static void testLookup() {
boolean error = false;
String ranges = "hi-IN, itc-Ital";
String tags = "hi-IN, itc-Ital";
List<LanguageRange> priorityList = LanguageRange.parse(ranges);
List<Locale> localeList = generateLocales(tags);
Locale actualLocale
= Locale.lookup(priorityList, localeList);
String actualLocaleString = "";
if (actualLocale != null) {
actualLocaleString = actualLocale.toLanguageTag();
} else {
error = true;
}
String expectedLocale = "hi-IN";
if (!expectedLocale.equals(actualLocaleString)) {
error = true;
}
if (error) {
System.err.println("testLookup() failed on language ranges:"
+ " [" + ranges + "] and language tags: [" + tags + "]");
err = true;
}
}