List of usage examples for java.util Locale forLanguageTag
public static Locale forLanguageTag(String languageTag)
From source file:com.haulmont.cuba.core.sys.FormatStringsRegistryImpl.java
@Nullable @Override/*from w w w. ja va 2s .c o m*/ public FormatStrings getFormatStrings(Locale locale) { if (useLocaleLanguageOnly) locale = Locale.forLanguageTag(locale.getLanguage()); return formatStringsMap.get(locale); }
From source file:pl.java.scalatech.config.I18nConfig.java
@Bean public LocaleResolver localeResolver() { CookieLocaleResolver clr = new CookieLocaleResolver(); log.info("++++ language : ", env.getProperty("language")); clr.setDefaultLocale(Locale.forLanguageTag(env.getProperty("language"))); return clr;/*from ww w. ja va 2 s. c om*/ }
From source file:com.ejisto.modules.vertx.handler.Translations.java
@Override public void addRoutes(RouteMatcher routeMatcher) { routeMatcher.get("/translations", request -> { final String lang = request.params().get("lang"); CACHE.computeIfAbsent(lang,//w w w. j av a2s . c o m k -> dumpMessages(ResourceBundle.getBundle("messages", Locale.forLanguageTag(k)))); request.response().end(JSONUtil.encode(CACHE.get(lang)), "UTF-8"); }); }
From source file:com.btmatthews.atlas.core.domain.i18n.LocalizedDeserializer.java
@Override public Localized deserialize(final JsonParser parser, final DeserializationContext context) throws IOException { final LocalizedBuilder<Object> builder = new LocalizedBuilder<>(); final ObjectCodec codec = parser.getCodec(); final JsonNode node = codec.readTree(parser); final Iterator<Map.Entry<String, JsonNode>> iterator = node.fields(); while (iterator.hasNext()) { final Map.Entry<String, JsonNode> entry = iterator.next(); builder.setValue(Locale.forLanguageTag(entry.getKey()), entry.getValue().textValue()); }/*www .ja v a 2 s. c om*/ return builder.build(); }
From source file:pt.ua.ri.tokenizer.WordTokenizer.java
private WordTokenizer(String locale) { checkNotNull(locale);/*from ww w . ja va 2 s. co m*/ bi = BreakIterator.getWordInstance(Locale.forLanguageTag(locale)); tokens = new PatriciaTrie<>(); bf = new StringBuilder(); }
From source file:org.wallride.web.support.BlogLanguageLocaleResolver.java
@Override public Locale resolveLocale(HttpServletRequest request) { BlogLanguage blogLanguage = (BlogLanguage) request .getAttribute(BlogLanguageMethodArgumentResolver.BLOG_LANGUAGE_ATTRIBUTE); if (blogLanguage == null) { Blog blog = blogService.getBlogById(Blog.DEFAULT_ID); blogLanguage = blog.getLanguage(blog.getDefaultLanguage()); }//from www . j a v a 2 s .c o m return (blogLanguage != null) ? Locale.forLanguageTag(blogLanguage.getLanguage()) : request.getLocale(); }
From source file:hu.petabyte.redflags.web.cfg.I18N.java
@Bean public LocaleResolver localeResolver() { SessionLocaleResolver slr = new SessionLocaleResolver(); slr.setDefaultLocale(Locale.forLanguageTag("en")); return slr;//from w w w . j a va 2 s . c o m }
From source file:org.cee.service.language.LanguageService.java
public LanguageList getSupportedLanguages() { List<String> langIds = searchService.getSupportedLanguages(); if (langIds == null) { //search service does not support languages at all, provide user with full list of languages langIds = Arrays.asList(Locale.getISOLanguages()); }/* w w w .j a v a2s. c o m*/ List<EntityKey> languages = new ArrayList<EntityKey>(); int defaultLanguageIndex = 0; String defaultLanguage = "en"; Locale currentUserLocale = LocaleContextHolder.getLocaleContext().getLocale(); if (currentUserLocale != null) { defaultLanguage = currentUserLocale.getLanguage(); } for (String langId : langIds) { Locale locale = Locale.forLanguageTag(langId); if (locale != null) { if (locale.getLanguage().startsWith(defaultLanguage) || defaultLanguage.startsWith(locale.getLanguage())) { defaultLanguageIndex = languages.size(); } languages.add(EntityKey.get(locale.getDisplayLanguage(), langId)); } else { languages.add(EntityKey.get(langId, langId)); } } LanguageList languageList = new LanguageList(); languageList.setLanguages(languages); languageList.setDefaultLanguage(defaultLanguageIndex); return languageList; }
From source file:org.obiba.mica.core.domain.LocalizedStringTest.java
@Test public void test_localized_string_to_json() throws Exception { LocalizedString string = new LocalizedString().forLanguageTag(null, "coucou").forEn("kewkew"); String json = objectMapper.writeValueAsString(string); log.debug(string.toString());/*from www. j a v a2 s . c o m*/ log.debug(json); assertThat(string.keySet().contains(Locale.ENGLISH.toLanguageTag())).isTrue(); assertThat(string.keySet().contains(Locale.forLanguageTag("und").toLanguageTag())).isTrue(); LocalizedString string2 = objectMapper.readValue(json, LocalizedString.class); log.debug(string2.toString()); assertThat(string2.keySet().contains(Locale.ENGLISH.toLanguageTag())).isTrue(); assertThat(string2.keySet().contains(Locale.forLanguageTag("und").toLanguageTag())).isTrue(); }
From source file:ch.xxx.carrental.ui.rest.model.CrTableResource.java
@GET @Path("/mietNr/{mietNr}") @DisableCaching/*from w w w .j ava 2 s. co m*/ @ApiOperation(value = "gets the rows for the table", response = CrTableRow.class, responseContainer = "List") public Response getAll(@PathParam("mietNr") final String mietNr, @HeaderParam("Accept-Language") final String acceptLang) { String[] langs = acceptLang.split(","); Locale locale = Locale.forLanguageTag(langs[0]); return Response.ok(service.readCrRowsByMiete(mietNr, locale)).build(); }