List of usage examples for java.util Locale getCountry
public String getCountry()
From source file:Main.java
public static String toLanguageTag(Locale locale) { StringBuilder languageTag = new StringBuilder(); languageTag.append(locale.getLanguage()); if (!isNullOrEmpty(locale.getCountry())) { languageTag.append('-').append(locale.getCountry()); }/*from ww w . j a v a 2 s. c o m*/ if (!isNullOrEmpty(locale.getVariant())) { languageTag.append('-').append(locale.getVariant()); } return languageTag.toString(); }
From source file:Main.java
/** * Convert a locale into a string that is conform with XML's xml:lang attribute. * Basically it is language-COUNTRY, e.g. en-US. * * @param locale a locale, must not be null * @return// w ww . j a va2s . com * @throws IllegalArgumentException if locale is null */ public static String locale2xmllang(Locale locale) { if (locale == null) throw new IllegalArgumentException("Locale must not be null"); String country = locale.getCountry(); if (!"".equals(country)) return locale.getLanguage() + "-" + country; return locale.getLanguage(); }
From source file:org.jahia.ajax.gwt.helper.LanguageHelper.java
/** * Get icon style depending and the selected language * * * @param locale/*from w w w .ja v a 2 s . c om*/ * @return */ public static String getLangIcon(String contextPath, Locale locale) { if ("".equals(locale.getCountry())) return contextPath + "/css/images/flags/" + locale.getLanguage().toLowerCase() + "_on.png"; else return contextPath + "/css/images/flags/plain/flag_" + Patterns.SPACE.matcher(locale.getDisplayCountry(Locale.ENGLISH).toLowerCase()).replaceAll("_") + ".png"; }
From source file:org.primefaces.extensions.converter.LocaleConverter.java
public static String getLocaleString(final Locale locale, final char seperator) { if (StringUtils.isBlank(locale.getCountry())) { return locale.getLanguage(); }/* w ww . j ava2 s . c om*/ return locale.getLanguage() + seperator + locale.getCountry(); }
From source file:org.openflamingo.locale.ResourceBundleHolder.java
public static String getDefaultLocale() { Locale defaultLocale = Locale.getDefault(); return getLocaleKey(defaultLocale.getLanguage(), defaultLocale.getCountry()); }
From source file:Main.java
/** * //w w w. j av a 2 s . c o m * Returns the "parent" locale of a given locale. * * * If the original locale is only language-based, the {@link #NULL_LOCALE} * object is returned. * * * If the original locale is {@link #NULL_LOCALE}, then <code>null</code> * is returned. * * * @param locale The original locale. * @return The parent locale. */ public static Locale getParentLocale(Locale locale) { Locale retValue = null; String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); if (!"".equals(variant)) { retValue = new Locale(language, country); } else if (!"".equals(country)) { retValue = new Locale(language); } else if (!"".equals(language)) { retValue = NULL_LOCALE; } return retValue; }
From source file:org.openflamingo.locale.ResourceBundleHolder.java
public static String getMessage(Locale locale, String pattern, Object... args) { String localeKey = getLocaleKey(locale.getLanguage(), locale.getCountry()); Map map = resourceBundleMap.get(localeKey); return MessageFormat.format((String) map.get(pattern), args); }
From source file:org.sacredscripturefoundation.commons.locale.LocaleStringUtils.java
/** * Determine the RFC 3066 compliant language tag, as used for the HTTP * "Accept-Language" header./*from ww w . java 2s .c o m*/ * * @param locale the Locale to transform to a language tag * @return the RFC 3066 compliant language tag as String */ public static String toLanguageTag(Locale locale) { StringBuilder sb = new StringBuilder(locale.getLanguage()); if (!locale.getCountry().isEmpty()) { sb.append("-"); sb.append(locale.getCountry()); } return sb.toString(); }
From source file:org.alex73.skarynka.scan.Messages.java
public static String getFile(String name) { Locale loc1 = Locale.getDefault(); Locale loc2 = new Locale(loc1.getLanguage(), loc1.getCountry()); Locale loc3 = new Locale(loc1.getLanguage()); for (Locale loc : new Locale[] { loc1, loc2, loc3 }) { URL r = Messages.class.getResource(name.replaceAll("(\\.[a-zA-Z0-9]+)$", "_" + loc + "$1")); if (r != null) { try { return IOUtils.toString(r, "UTF-8"); } catch (IOException ex) { throw new RuntimeException(ex); }// www .j a va2 s . c o m } } URL r = Messages.class.getResource(name); if (r != null) { try { return IOUtils.toString(r, "UTF-8"); } catch (IOException ex) { throw new RuntimeException(ex); } } return null; }
From source file:org.craftercms.engine.util.LocaleUtils.java
/** * Returns a new url base on the given locale. The implementation returns an url with (delim is normally '_'): * <pre>// w ww. j av a 2 s . c om * baseName + delim + language + delim + country + delim + variant * </pre> */ public static String getLocalizedUrl(ContentBundleUrlParser urlParser, String baseUrl, Locale locale, String delim) { String language = locale.getLanguage(); String country = locale.getCountry(); String variant = locale.getVariant(); if (StringUtils.isEmpty(language) && StringUtils.isEmpty(country) && StringUtils.isEmpty(variant)) { return baseUrl; } ContentBundleUrl parsedUrl = urlParser.getContentBundleUrl(baseUrl); String localizedUrl = baseUrl; if (StringUtils.isNotEmpty(parsedUrl.getBaseNameAndExtensionToken())) { StringBuilder localizedUrlBuilder = new StringBuilder(parsedUrl.getBaseNameAndExtensionToken()); localizedUrlBuilder.append(delim); if (StringUtils.isNotEmpty(variant)) { localizedUrlBuilder.append(language).append(delim).append(country).append(delim).append(variant); } else if (StringUtils.isNotEmpty(country)) { localizedUrlBuilder.append(language).append(delim).append(country); } else { localizedUrlBuilder.append(language); } localizedUrlBuilder.insert(0, parsedUrl.getPrefix()).append(parsedUrl.getSuffix()); localizedUrl = localizedUrlBuilder.toString(); } return localizedUrl; }