public void setLocale(Locale locale) { this.locale = locale.toLanguageTag(); } }
@JsonProperty public String getLocale() { if (locale != null) { return locale.toLanguageTag(); } else { return null; } }
@Override public void setLocale(Locale locale) { this.locale = locale; doAddHeaderValue(HttpHeaders.CONTENT_LANGUAGE, locale.toLanguageTag(), true); }
/** * 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)); }
/** * 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()); }
/** * 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())); }
/** * 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)); }
public static LocaleDescription create(Locale locale) { return create(locale.toLanguageTag(), locale.getDisplayName(Locale.ENGLISH)); }
/** * 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()); }
@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(); }
/** * 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())); }
Locale locale = localeContext.getLocale(); if (locale != null) { connection.setRequestProperty(HTTP_HEADER_ACCEPT_LANGUAGE, locale.toLanguageTag());
@Override public void setLocale(Locale locale) { this.locale = locale; doAddHeaderValue(HttpHeaders.CONTENT_LANGUAGE, locale.toLanguageTag(), true); }
@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()); } } }
/** * 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; }
@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(); } }
public void setAlternativeLanguage(Locale lang) { if (lang == null) { if (props.isSetAltLang()) { props.unsetAltLang(); } } else { props.setAltLang(lang.toLanguageTag()); } }
@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)); }
@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"); }
@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)); }