Example usage for java.util Locale toLanguageTag

List of usage examples for java.util Locale toLanguageTag

Introduction

In this page you can find the example usage for java.util Locale toLanguageTag.

Prototype

public String toLanguageTag() 

Source Link

Document

Returns a well-formed IETF BCP 47 language tag representing this locale.

Usage

From source file:org.efaps.esjp.common.format.EvalFormatFcty.java

@Override
public Format getFormat(final String _name, final String _arguments, final Locale _locale) {
    Format ret;//  w ww .j  a v  a 2 s .  c o  m
    final String key = _locale.toLanguageTag() + "_" + _arguments;
    if (EvalFormatFcty.FORMATS.containsKey(key)) {
        ret = EvalFormatFcty.FORMATS.get(key);
    } else {
        ret = new EvalFormat(_arguments, _locale);
        EvalFormatFcty.FORMATS.put(key, ret);
    }
    return ret;
}

From source file:org.mayocat.rest.jackson.LocaleBCP47LanguageTagSerializer.java

@Override
public void serialize(Locale locale, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
        throws IOException, JsonGenerationException {
    // IETF BCP 47
    jsonGenerator.writeString(locale.toLanguageTag());
}

From source file:com.michellemay.mappings.LanguageTagsMapping.java

/**
 * Instantiates a new Language tags mapping.
 *//*  w w w  . java2  s .  c om*/
public LanguageTagsMapping() {
    super(NAME);
    this.withCaseSensitive(false);

    // Build reverse map.  Use a tree map to offer case insensitiveness while preserving keys case (useful for extending)
    TreeMap<String, Locale> map = new TreeMap<String, Locale>(
            this.getCaseSensitive() ? null : String.CASE_INSENSITIVE_ORDER);
    for (Locale loc : LocaleUtils.availableLocaleList()) {
        String isoCode = loc.getLanguage();
        if (isoCode.length() > 0) {
            String displayValue = loc.toLanguageTag();
            if (!map.containsKey(displayValue)) {
                // Also add variant with underscores
                map.put(displayValue, loc);
                map.put(displayValue.replace('-', '_'), loc);
            }
        }
    }
    this.withMapping(map);
}

From source file:com.haulmont.cuba.core.sys.FormatStringsRegistryImpl.java

@Override
public FormatStrings getFormatStringsNN(Locale locale) {
    FormatStrings format = getFormatStrings(locale);
    if (format == null) {
        throw new IllegalArgumentException("Not found format strings for locale " + locale.toLanguageTag());
    }/*from w  w w.  j a v  a2  s . c o m*/
    return format;
}

From source file:org.phenotips.vocabulary.translation.AbstractXliffTranslatedVocabularyExtension.java

/**
 * Check if the specified locale is supported by this translation, specifically if the {@link #getTargetLocale()
 * targeted locale} is a superset of it.
 *
 * @param locale the locale to check//  w w w.  j a  v  a  2 s .com
 * @return {@code true} if the specified locale is supported
 */
protected boolean isLocaleSupported(Locale locale) {
    return locale.toLanguageTag().startsWith(getTargetLocale().toLanguageTag());
}

From source file:org.wso2.carbon.uuf.api.config.I18nResources.java

/**
 * Returns the local for the supported language.
 *
 * @param localeHeaderValue local header value
 * @return Locale object for language support
 *//*from   ww w.ja  va  2s . c  om*/
public Locale getLocale(String localeHeaderValue) {
    if (localeHeaderValue == null) {
        return Locale.forLanguageTag(DEFAULT_LOCALE.replace("_", "-"));
    }

    // example: en,en-us;q=0.7, en-au;q=0.3
    // https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
    // Change the locale value to lower case because we store the language keys in lower case.
    String languageCode = localeHeaderValue.toLowerCase().split(",")[0];
    Locale locale = Locale.forLanguageTag(languageCode);
    String currentLang = null;
    for (String language : getAvailableLanguages()) {
        if (StringUtils.isNotEmpty(locale.toLanguageTag())
                && language.equalsIgnoreCase(locale.toLanguageTag())) {
            currentLang = language;
        } else if (StringUtils.isNotEmpty(locale.getLanguage()) && language.startsWith(locale.getLanguage())) {
            currentLang = language;
        }
    }
    if (currentLang == null) {
        currentLang = DEFAULT_LOCALE.replace("_", "-");
    }
    return Locale.forLanguageTag(currentLang);
}

From source file:ips1ap101.lib.base.bundle.ResourceBundleHandler.java

private void put(Locale locale, ResourceBundleTriad triad) {
    Bitacora.trace(getClass(), "put", locale.toLanguageTag(), triad);
    _triads.put(locale, triad);/*from   www. j a v  a2s.  com*/
}

From source file:ips1ap101.lib.base.bundle.JRResourceBundleHandler.java

private void add(Locale locale, Set<ResourceBundle> bundles) {
    ResourceBundleTriad triad;//from  www  .j av  a  2 s .c  o  m
    if (locale != null) {
        String tag = locale.toLanguageTag();
        if (_triads.containsKey(locale)) {
            triad = _triads.get(locale);
        } else if (projectLanguageTagStartsWithDefaultLanguageTag && tag.startsWith(defaultLanguageTag)) {
            triad = _defaultTriad;
            put(locale, triad);
        } else {
            triad = new ResourceBundleTriad(locale);
            put(locale, triad);
        }
        add(triad, bundles);
    }
}

From source file:org.wso2.carbon.uuf.api.config.I18nResources.java

/**
 * Adds the given language./* w w w  .j  a va 2 s  .  com*/
 *
 * @param locale language to be add
 * @param i18n   properties
 */
public void addI18nResource(Locale locale, Properties i18n) {
    // Convert the language key to lower case before adding to the map. This is done because various browsers
    // send the locale in different formats.
    Properties i18nResource = this.i18nResources.get(locale.toLanguageTag());
    if (i18nResource == null) {
        this.i18nResources.put(locale.toLanguageTag(), i18n);
    } else {
        i18nResource.putAll(i18n);
    }
}

From source file:org.apache.phoenix.expression.function.CollationKeyFunction.java

private void initialize() {
    String localeISOCode = getLiteralValue(1, String.class);
    Boolean useSpecialUpperCaseCollator = getLiteralValue(2, Boolean.class);
    Integer collatorStrength = getLiteralValue(3, Integer.class);
    Integer collatorDecomposition = getLiteralValue(4, Integer.class);

    if (LOG.isTraceEnabled()) {
        StringBuilder logInputsMessage = new StringBuilder();
        logInputsMessage.append("Input (literal) arguments:").append("localeISOCode: " + localeISOCode)
                .append(", useSpecialUpperCaseCollator: " + useSpecialUpperCaseCollator)
                .append(", collatorStrength: " + collatorStrength)
                .append(", collatorDecomposition: " + collatorDecomposition);
        LOG.trace(logInputsMessage);/*from   w w w  .j  a v  a  2  s  .  co m*/
    }

    Locale locale = LocaleUtils.get().getLocaleByIsoCode(localeISOCode);

    if (LOG.isTraceEnabled()) {
        LOG.trace(String.format("Locale: " + locale.toLanguageTag()));
    }

    LinguisticSort linguisticSort = LinguisticSort.get(locale);

    collator = BooleanUtils.isTrue(useSpecialUpperCaseCollator) ? linguisticSort.getUpperCaseCollator(false)
            : linguisticSort.getCollator();

    if (collatorStrength != null) {
        collator.setStrength(collatorStrength);
    }

    if (collatorDecomposition != null) {
        collator.setDecomposition(collatorDecomposition);
    }

    if (LOG.isTraceEnabled()) {
        LOG.trace(String.format("Collator: [strength: %d, decomposition: %d], Special-Upper-Case: %s",
                collator.getStrength(), collator.getDecomposition(),
                BooleanUtils.isTrue(useSpecialUpperCaseCollator)));
    }
}