本文整理了Java中java.util.Locale.toLanguageTag()
方法的一些代码示例,展示了Locale.toLanguageTag()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Locale.toLanguageTag()
方法的具体详情如下:
包路径:java.util.Locale
类名称:Locale
方法名:toLanguageTag
暂无
代码示例来源:origin: MovingBlocks/Terasology
public void setLocale(Locale locale) {
this.locale = locale.toLanguageTag();
}
}
代码示例来源:origin: apache/incubator-druid
@JsonProperty
public String getLocale()
{
if (locale != null) {
return locale.toLanguageTag();
} else {
return null;
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void setLocale(Locale locale) {
this.locale = locale;
doAddHeaderValue(HttpHeaders.CONTENT_LANGUAGE, locale.toLanguageTag(), true);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Set the {@link Locale} of the content language,
* as specified by the {@literal Content-Language} header.
* <p>Use {@code set(CONTENT_LANGUAGE, ...)} if you need
* to set multiple content languages.</p>
* @since 5.0
*/
public void setContentLanguage(@Nullable Locale locale) {
setOrRemove(CONTENT_LANGUAGE, (locale != null ? locale.toLanguageTag() : null));
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Render the given locale as a text value for inclusion in a cookie.
* <p>The default implementation calls {@link Locale#toString()}
* or JDK 7's {@link Locale#toLanguageTag()}, depending on the
* {@link #setLanguageTagCompliant "languageTagCompliant"} configuration property.
* @param locale the locale to stringify
* @return a String representation for the given locale
* @since 4.3
* @see #isLanguageTagCompliant()
*/
protected String toLocaleValue(Locale locale) {
return (isLanguageTagCompliant() ? locale.toLanguageTag() : locale.toString());
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Variant of {@link #setAcceptLanguage(List)} using {@link Locale}'s.
* @since 5.0
*/
public void setAcceptLanguageAsLocales(List<Locale> locales) {
setAcceptLanguage(locales.stream()
.map(locale -> new Locale.LanguageRange(locale.toLanguageTag()))
.collect(Collectors.toList()));
}
代码示例来源:origin: org.springframework/spring-web
/**
* Set the {@link Locale} of the content language,
* as specified by the {@literal Content-Language} header.
* <p>Use {@code set(CONTENT_LANGUAGE, ...)} if you need
* to set multiple content languages.</p>
* @since 5.0
*/
public void setContentLanguage(@Nullable Locale locale) {
setOrRemove(CONTENT_LANGUAGE, (locale != null ? locale.toLanguageTag() : null));
}
代码示例来源:origin: Graylog2/graylog2-server
public static LocaleDescription create(Locale locale) {
return create(locale.toLanguageTag(), locale.getDisplayName(Locale.ENGLISH));
}
代码示例来源:origin: org.springframework/spring-webmvc
/**
* Render the given locale as a text value for inclusion in a cookie.
* <p>The default implementation calls {@link Locale#toString()}
* or JDK 7's {@link Locale#toLanguageTag()}, depending on the
* {@link #setLanguageTagCompliant "languageTagCompliant"} configuration property.
* @param locale the locale to stringify
* @return a String representation for the given locale
* @since 4.3
* @see #isLanguageTagCompliant()
*/
protected String toLocaleValue(Locale locale) {
return (isLanguageTagCompliant() ? locale.toLanguageTag() : locale.toString());
}
代码示例来源:origin: apache/incubator-druid
@Override
public byte[] getCacheKey()
{
final String tzId = (tz == null ? DateTimeZone.UTC : tz).getID();
final String localeTag = (locale == null ? Locale.getDefault() : locale).toLanguageTag();
final byte[] exprBytes = StringUtils.toUtf8(format + "\u0001" + tzId + "\u0001" + localeTag);
final byte[] granularityCacheKey = granularity.getCacheKey();
return ByteBuffer.allocate(4 + exprBytes.length + granularityCacheKey.length)
.put(ExtractionCacheHelper.CACHE_TYPE_ID_TIME_FORMAT)
.put(exprBytes)
.put((byte) 0xFF)
.put(granularityCacheKey)
.put((byte) 0xFF)
.put(asMillis ? (byte) 1 : (byte) 0)
.array();
}
代码示例来源:origin: org.springframework/spring-web
/**
* Variant of {@link #setAcceptLanguage(List)} using {@link Locale}'s.
* @since 5.0
*/
public void setAcceptLanguageAsLocales(List<Locale> locales) {
setAcceptLanguage(locales.stream()
.map(locale -> new Locale.LanguageRange(locale.toLanguageTag()))
.collect(Collectors.toList()));
}
代码示例来源:origin: spring-projects/spring-framework
Locale locale = localeContext.getLocale();
if (locale != null) {
connection.setRequestProperty(HTTP_HEADER_ACCEPT_LANGUAGE, locale.toLanguageTag());
代码示例来源:origin: spring-projects/spring-framework
@Override
public void setLocale(Locale locale) {
this.locale = locale;
doAddHeaderValue(HttpHeaders.CONTENT_LANGUAGE, locale.toLanguageTag(), true);
}
代码示例来源:origin: spring-projects/spring-framework
@Test // SPR-16651
public void testAvailableLocalesWithLanguageTag() {
for (Locale locale : Locale.getAvailableLocales()) {
Locale parsedLocale = StringUtils.parseLocale(locale.toLanguageTag());
if (parsedLocale == null) {
assertEquals("", locale.getLanguage());
}
else {
assertEquals(parsedLocale.toLanguageTag(), locale.toLanguageTag());
}
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Create a HttpPost for the given configuration.
* <p>The default implementation creates a standard HttpPost with
* "application/x-java-serialized-object" as "Content-Type" header.
* @param config the HTTP invoker configuration that specifies the
* target service
* @return the HttpPost instance
* @throws java.io.IOException if thrown by I/O methods
*/
protected HttpPost createHttpPost(HttpInvokerClientConfiguration config) throws IOException {
HttpPost httpPost = new HttpPost(config.getServiceUrl());
RequestConfig requestConfig = createRequestConfig(config);
if (requestConfig != null) {
httpPost.setConfig(requestConfig);
}
LocaleContext localeContext = LocaleContextHolder.getLocaleContext();
if (localeContext != null) {
Locale locale = localeContext.getLocale();
if (locale != null) {
httpPost.addHeader(HTTP_HEADER_ACCEPT_LANGUAGE, locale.toLanguageTag());
}
}
if (isAcceptGzipEncoding()) {
httpPost.addHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
}
return httpPost;
}
代码示例来源:origin: robolectric/robolectric
@Implementation
public static String addLikelySubtags(String locale) {
if (RuntimeEnvironment.getApiLevel() >= N) {
return ULocale.addLikelySubtags(ULocale.forLanguageTag(locale)).toLanguageTag();
} else {
// Return what is essentially the given locale, normalized by passing through the Locale
// factory method.
return Locale.forLanguageTag(locale).toLanguageTag();
}
}
代码示例来源:origin: org.apache.poi/poi-ooxml
public void setAlternativeLanguage(Locale lang) {
if (lang == null) {
if (props.isSetAltLang()) {
props.unsetAltLang();
}
} else {
props.setAltLang(lang.toLanguageTag());
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void resolvePreferredNotSupportedWithDefault() {
this.resolver.setSupportedLocales(Arrays.asList(US, JAPAN));
this.resolver.setDefaultLocale(Locale.JAPAN);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Accept-Language", KOREA.toLanguageTag());
request.setPreferredLocales(Collections.singletonList(KOREA));
assertEquals(Locale.JAPAN, this.resolver.resolveLocale(request));
}
代码示例来源:origin: SonarSource/sonarqube
@Override
public void define(WebService.NewController context) {
WebService.NewAction indexAction = context.createAction("index")
.setInternal(true)
.setDescription("Get all localization messages for a given locale")
.setResponseExample(getClass().getResource("l10n-index-example.json"))
.setSince("4.4")
.setHandler(this);
indexAction.createParam(LOCALE_PARAM)
.setDescription("BCP47 language tag, used to override the browser Accept-Language header")
.setExampleValue("fr-CH")
.setDefaultValue(ENGLISH.toLanguageTag());
indexAction.createParam(TS_PARAM)
.setDescription("Date of the last cache update.")
.setExampleValue("2014-06-04T09:31:42+0000");
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void defaultLocale() {
this.resolver.setDefaultLocale(JAPANESE);
MockHttpServletRequest request = new MockHttpServletRequest();
assertEquals(JAPANESE, this.resolver.resolveLocale(request));
request.addHeader("Accept-Language", US.toLanguageTag());
request.setPreferredLocales(Collections.singletonList(US));
assertEquals(US, this.resolver.resolveLocale(request));
}
内容来源于网络,如有侵权,请联系作者删除!