本文整理了Java中java.util.Locale.lookup()
方法的一些代码示例,展示了Locale.lookup()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Locale.lookup()
方法的具体详情如下:
包路径:java.util.Locale
类名称:Locale
方法名:lookup
暂无
代码示例来源:origin: jooby-project/jooby
/**
* Get a locale that best matches the current request or the default locale as specified
* in <code>application.lang</code>.
*
* @return A matching locale.
*/
@Nonnull
default Locale locale() {
return locale((priorityList, locales) -> Optional.ofNullable(Locale.lookup(priorityList, locales))
.orElse(locales.get(0)));
}
代码示例来源:origin: org.jooby/jooby
/**
* Get a locale that best matches the current request or the default locale as specified
* in <code>application.lang</code>.
*
* @return A matching locale.
*/
@Nonnull
default Locale locale() {
return locale((priorityList, locales) -> Optional.ofNullable(Locale.lookup(priorityList, locales))
.orElse(locales.get(0)));
}
代码示例来源:origin: stackoverflow.com
public class SmartLocaleResolver extends AcceptHeaderLocaleResolver {
@Override
public Locale resolveLocale(HttpServletRequest request) {
if (StringUtils.isBlank(request.getHeader("Accept-Language"))) {
return Locale.getDefault();
}
List<Locale.LanguageRange> list = Locale.LanguageRange.parse(request.getHeader("Accept-Language"));
Locale locale = Locale.lookup(list, ApplicationConstants.LOCALES);
return locale ;
}
}
代码示例来源:origin: stackoverflow.com
List<Locale> locales = Arrays.asList(new Locale("en"),
new Locale("es"),
new Locale("fr"),
new Locale("es", "MX"),
new Locale("zh"),
new Locale("ja"));
List<Locale.LanguageRange> ranges = Locale.LanguageRange.parse("da,es-MX;q=0.8");
Locale best = Locale.lookup(ranges, locales);
System.out.println("best = " + best); // prints best = es_MX
ranges = Locale.LanguageRange.parse("fr,es-MX;q=0.8");
best = Locale.lookup(ranges, locales);
System.out.println("best = " + best); // prints best = fr
代码示例来源:origin: stackoverflow.com
public class SmartLocaleResolver extends AcceptHeaderLocaleResolver {
@Override
public Locale resolveLocale(HttpServletRequest request) {
if (StringUtils.isBlank(request.getHeader("Accept-Language"))) {
return Locale.getDefault();
}
List<Locale.LanguageRange> ranges = Locale.LanguageRange.parse("da,es-MX;q=0.8");
Locale locale = Locale.lookup(ranges, locales);
return locale ;
}
}
代码示例来源:origin: org.wso2.carbon.uuf/org.wso2.carbon.uuf.core
/**
* Returns the best matching locale chosen from the available locales for the given language ranges.
*
* @param languageRanges a list of comma-separated language ranges or a list of language ranges in the form of
* the "Accept-Language" header defined in
* <a href="https://tools.ietf.org/html/rfc2616#section-14.4">RFC 2616</a>
* @return Locale the best matching locale, or {@code null} if nothing matches
*/
public Locale getLocale(String languageRanges) {
if ((languageRanges == null) || languageRanges.isEmpty()) {
return null;
}
try {
return Locale.lookup(Locale.LanguageRange.parse(languageRanges), i18nResources.keySet());
} catch (IllegalArgumentException e) {
// languageRanges is ill formed
return null;
}
}
代码示例来源:origin: org.wso2.carbon.uis/org.wso2.carbon.uis.core
/**
* Returns the best matching locale chosen from the available locales for the given language ranges.
*
* @param languageRanges a list of comma-separated language ranges or a list of language ranges in the form of the
* "Accept-Language" header defined in
* <a href="https://tools.ietf.org/html/rfc2616#section-14.4">RFC 2616</a>
* @return Locale the best matching locale, or {@code null} if nothing matches
*/
public Locale getLocale(String languageRanges) {
if ((languageRanges == null) || languageRanges.isEmpty()) {
return null;
}
try {
return Locale.lookup(Locale.LanguageRange.parse(languageRanges), i18nResources.keySet());
} catch (IllegalArgumentException e) {
// languageRanges is ill formed
return null;
}
}
代码示例来源:origin: AlexanderBartash/hybris-integration-intellij-idea-plugin
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);
}
代码示例来源:origin: openhab/openhab-core
@Override
public Voice getPreferredVoice(Set<Voice> voices) {
// Express preferences with a Language Priority List
Locale locale = localeProvider.getLocale();
// Get collection of voice locales
Collection<Locale> locales = new ArrayList<Locale>();
for (Voice currentVoice : voices) {
locales.add(currentVoice.getLocale());
}
// Determine preferred locale based on RFC 4647
String ranges = locale.toLanguageTag();
List<Locale.LanguageRange> languageRanges = Locale.LanguageRange.parse(ranges + "-*");
Locale preferredLocale = Locale.lookup(languageRanges, locales);
// As a last resort choose some Locale
if (preferredLocale == null) {
preferredLocale = locales.iterator().next();
}
// Determine preferred voice
Voice preferredVoice = null;
for (Voice currentVoice : voices) {
if (preferredLocale.equals(currentVoice.getLocale())) {
preferredVoice = currentVoice;
}
}
assert (preferredVoice != null);
// Return preferred voice
return preferredVoice;
}
内容来源于网络,如有侵权,请联系作者删除!