java.util.Locale.toLanguageTag()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.8k)|赞(0)|评价(0)|浏览(354)

本文整理了Java中java.util.Locale.toLanguageTag()方法的一些代码示例,展示了Locale.toLanguageTag()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Locale.toLanguageTag()方法的具体详情如下:
包路径:java.util.Locale
类名称:Locale
方法名:toLanguageTag

Locale.toLanguageTag介绍

暂无

代码示例

代码示例来源:origin: MovingBlocks/Terasology

  1. public void setLocale(Locale locale) {
  2. this.locale = locale.toLanguageTag();
  3. }
  4. }

代码示例来源:origin: apache/incubator-druid

  1. @JsonProperty
  2. public String getLocale()
  3. {
  4. if (locale != null) {
  5. return locale.toLanguageTag();
  6. } else {
  7. return null;
  8. }
  9. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Override
  2. public void setLocale(Locale locale) {
  3. this.locale = locale;
  4. doAddHeaderValue(HttpHeaders.CONTENT_LANGUAGE, locale.toLanguageTag(), true);
  5. }

代码示例来源:origin: spring-projects/spring-framework

  1. /**
  2. * Set the {@link Locale} of the content language,
  3. * as specified by the {@literal Content-Language} header.
  4. * <p>Use {@code set(CONTENT_LANGUAGE, ...)} if you need
  5. * to set multiple content languages.</p>
  6. * @since 5.0
  7. */
  8. public void setContentLanguage(@Nullable Locale locale) {
  9. setOrRemove(CONTENT_LANGUAGE, (locale != null ? locale.toLanguageTag() : null));
  10. }

代码示例来源:origin: spring-projects/spring-framework

  1. /**
  2. * Render the given locale as a text value for inclusion in a cookie.
  3. * <p>The default implementation calls {@link Locale#toString()}
  4. * or JDK 7's {@link Locale#toLanguageTag()}, depending on the
  5. * {@link #setLanguageTagCompliant "languageTagCompliant"} configuration property.
  6. * @param locale the locale to stringify
  7. * @return a String representation for the given locale
  8. * @since 4.3
  9. * @see #isLanguageTagCompliant()
  10. */
  11. protected String toLocaleValue(Locale locale) {
  12. return (isLanguageTagCompliant() ? locale.toLanguageTag() : locale.toString());
  13. }

代码示例来源:origin: spring-projects/spring-framework

  1. /**
  2. * Variant of {@link #setAcceptLanguage(List)} using {@link Locale}'s.
  3. * @since 5.0
  4. */
  5. public void setAcceptLanguageAsLocales(List<Locale> locales) {
  6. setAcceptLanguage(locales.stream()
  7. .map(locale -> new Locale.LanguageRange(locale.toLanguageTag()))
  8. .collect(Collectors.toList()));
  9. }

代码示例来源:origin: org.springframework/spring-web

  1. /**
  2. * Set the {@link Locale} of the content language,
  3. * as specified by the {@literal Content-Language} header.
  4. * <p>Use {@code set(CONTENT_LANGUAGE, ...)} if you need
  5. * to set multiple content languages.</p>
  6. * @since 5.0
  7. */
  8. public void setContentLanguage(@Nullable Locale locale) {
  9. setOrRemove(CONTENT_LANGUAGE, (locale != null ? locale.toLanguageTag() : null));
  10. }

代码示例来源:origin: Graylog2/graylog2-server

  1. public static LocaleDescription create(Locale locale) {
  2. return create(locale.toLanguageTag(), locale.getDisplayName(Locale.ENGLISH));
  3. }

代码示例来源:origin: org.springframework/spring-webmvc

  1. /**
  2. * Render the given locale as a text value for inclusion in a cookie.
  3. * <p>The default implementation calls {@link Locale#toString()}
  4. * or JDK 7's {@link Locale#toLanguageTag()}, depending on the
  5. * {@link #setLanguageTagCompliant "languageTagCompliant"} configuration property.
  6. * @param locale the locale to stringify
  7. * @return a String representation for the given locale
  8. * @since 4.3
  9. * @see #isLanguageTagCompliant()
  10. */
  11. protected String toLocaleValue(Locale locale) {
  12. return (isLanguageTagCompliant() ? locale.toLanguageTag() : locale.toString());
  13. }

代码示例来源:origin: apache/incubator-druid

  1. @Override
  2. public byte[] getCacheKey()
  3. {
  4. final String tzId = (tz == null ? DateTimeZone.UTC : tz).getID();
  5. final String localeTag = (locale == null ? Locale.getDefault() : locale).toLanguageTag();
  6. final byte[] exprBytes = StringUtils.toUtf8(format + "\u0001" + tzId + "\u0001" + localeTag);
  7. final byte[] granularityCacheKey = granularity.getCacheKey();
  8. return ByteBuffer.allocate(4 + exprBytes.length + granularityCacheKey.length)
  9. .put(ExtractionCacheHelper.CACHE_TYPE_ID_TIME_FORMAT)
  10. .put(exprBytes)
  11. .put((byte) 0xFF)
  12. .put(granularityCacheKey)
  13. .put((byte) 0xFF)
  14. .put(asMillis ? (byte) 1 : (byte) 0)
  15. .array();
  16. }

代码示例来源:origin: org.springframework/spring-web

  1. /**
  2. * Variant of {@link #setAcceptLanguage(List)} using {@link Locale}'s.
  3. * @since 5.0
  4. */
  5. public void setAcceptLanguageAsLocales(List<Locale> locales) {
  6. setAcceptLanguage(locales.stream()
  7. .map(locale -> new Locale.LanguageRange(locale.toLanguageTag()))
  8. .collect(Collectors.toList()));
  9. }

代码示例来源:origin: spring-projects/spring-framework

  1. Locale locale = localeContext.getLocale();
  2. if (locale != null) {
  3. connection.setRequestProperty(HTTP_HEADER_ACCEPT_LANGUAGE, locale.toLanguageTag());

代码示例来源:origin: spring-projects/spring-framework

  1. @Override
  2. public void setLocale(Locale locale) {
  3. this.locale = locale;
  4. doAddHeaderValue(HttpHeaders.CONTENT_LANGUAGE, locale.toLanguageTag(), true);
  5. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test // SPR-16651
  2. public void testAvailableLocalesWithLanguageTag() {
  3. for (Locale locale : Locale.getAvailableLocales()) {
  4. Locale parsedLocale = StringUtils.parseLocale(locale.toLanguageTag());
  5. if (parsedLocale == null) {
  6. assertEquals("", locale.getLanguage());
  7. }
  8. else {
  9. assertEquals(parsedLocale.toLanguageTag(), locale.toLanguageTag());
  10. }
  11. }
  12. }

代码示例来源:origin: spring-projects/spring-framework

  1. /**
  2. * Create a HttpPost for the given configuration.
  3. * <p>The default implementation creates a standard HttpPost with
  4. * "application/x-java-serialized-object" as "Content-Type" header.
  5. * @param config the HTTP invoker configuration that specifies the
  6. * target service
  7. * @return the HttpPost instance
  8. * @throws java.io.IOException if thrown by I/O methods
  9. */
  10. protected HttpPost createHttpPost(HttpInvokerClientConfiguration config) throws IOException {
  11. HttpPost httpPost = new HttpPost(config.getServiceUrl());
  12. RequestConfig requestConfig = createRequestConfig(config);
  13. if (requestConfig != null) {
  14. httpPost.setConfig(requestConfig);
  15. }
  16. LocaleContext localeContext = LocaleContextHolder.getLocaleContext();
  17. if (localeContext != null) {
  18. Locale locale = localeContext.getLocale();
  19. if (locale != null) {
  20. httpPost.addHeader(HTTP_HEADER_ACCEPT_LANGUAGE, locale.toLanguageTag());
  21. }
  22. }
  23. if (isAcceptGzipEncoding()) {
  24. httpPost.addHeader(HTTP_HEADER_ACCEPT_ENCODING, ENCODING_GZIP);
  25. }
  26. return httpPost;
  27. }

代码示例来源:origin: robolectric/robolectric

  1. @Implementation
  2. public static String addLikelySubtags(String locale) {
  3. if (RuntimeEnvironment.getApiLevel() >= N) {
  4. return ULocale.addLikelySubtags(ULocale.forLanguageTag(locale)).toLanguageTag();
  5. } else {
  6. // Return what is essentially the given locale, normalized by passing through the Locale
  7. // factory method.
  8. return Locale.forLanguageTag(locale).toLanguageTag();
  9. }
  10. }

代码示例来源:origin: org.apache.poi/poi-ooxml

  1. public void setAlternativeLanguage(Locale lang) {
  2. if (lang == null) {
  3. if (props.isSetAltLang()) {
  4. props.unsetAltLang();
  5. }
  6. } else {
  7. props.setAltLang(lang.toLanguageTag());
  8. }
  9. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void resolvePreferredNotSupportedWithDefault() {
  3. this.resolver.setSupportedLocales(Arrays.asList(US, JAPAN));
  4. this.resolver.setDefaultLocale(Locale.JAPAN);
  5. MockHttpServletRequest request = new MockHttpServletRequest();
  6. request.addHeader("Accept-Language", KOREA.toLanguageTag());
  7. request.setPreferredLocales(Collections.singletonList(KOREA));
  8. assertEquals(Locale.JAPAN, this.resolver.resolveLocale(request));
  9. }

代码示例来源:origin: SonarSource/sonarqube

  1. @Override
  2. public void define(WebService.NewController context) {
  3. WebService.NewAction indexAction = context.createAction("index")
  4. .setInternal(true)
  5. .setDescription("Get all localization messages for a given locale")
  6. .setResponseExample(getClass().getResource("l10n-index-example.json"))
  7. .setSince("4.4")
  8. .setHandler(this);
  9. indexAction.createParam(LOCALE_PARAM)
  10. .setDescription("BCP47 language tag, used to override the browser Accept-Language header")
  11. .setExampleValue("fr-CH")
  12. .setDefaultValue(ENGLISH.toLanguageTag());
  13. indexAction.createParam(TS_PARAM)
  14. .setDescription("Date of the last cache update.")
  15. .setExampleValue("2014-06-04T09:31:42+0000");
  16. }

代码示例来源:origin: spring-projects/spring-framework

  1. @Test
  2. public void defaultLocale() {
  3. this.resolver.setDefaultLocale(JAPANESE);
  4. MockHttpServletRequest request = new MockHttpServletRequest();
  5. assertEquals(JAPANESE, this.resolver.resolveLocale(request));
  6. request.addHeader("Accept-Language", US.toLanguageTag());
  7. request.setPreferredLocales(Collections.singletonList(US));
  8. assertEquals(US, this.resolver.resolveLocale(request));
  9. }

相关文章