Example usage for org.apache.commons.lang3 LocaleUtils availableLocaleList

List of usage examples for org.apache.commons.lang3 LocaleUtils availableLocaleList

Introduction

In this page you can find the example usage for org.apache.commons.lang3 LocaleUtils availableLocaleList.

Prototype

public static List<Locale> availableLocaleList() 

Source Link

Document

Obtains an unmodifiable list of installed locales.

This method is a wrapper around Locale#getAvailableLocales() .

Usage

From source file:com.netflix.imfutility.itunes.locale.LocaleValidator.java

public static void validateLocale(String str) throws LocaleValidationException {
    if (StringUtils.isBlank(str)) {
        throw new LocaleValidationException("Locale must be set.");
    }/*  w  w w .j ava 2 s  . c o m*/

    try {
        Locale locale = LocaleHelper.fromITunesLocale(str);

        if (!LocaleUtils.availableLocaleList().contains(locale)) {
            throw new LocaleValidationException(String.format("Locale %s is unavailable.", str));
        }
    } catch (IllegalArgumentException e) {
        throw new LocaleValidationException("Locale validation failed.", e);
    }
}

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

/**
 * Instantiates a new ISO 639 alpha 3 mapping.
 *///from  w w  w.  j a v a2 s  .  c o  m
public ISO639Alpha3Mapping() {
    super(NAME);

    // Build reverse map
    HashMap<String, Locale> map = new HashMap<String, Locale>();
    for (Locale loc : LocaleUtils.availableLocaleList()) {
        String isoCode = loc.getLanguage();
        if (isoCode.length() > 0) {
            String displayValue = loc.getISO3Language().toLowerCase();
            if (!map.containsKey(displayValue)) {
                map.put(displayValue, LocaleUtils.toLocale(isoCode));
            }
        }
    }
    this.withMapping(map).withCaseSensitive(false);
}

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

/**
 * Instantiates a new Language tags mapping.
 *//*from w w  w.  j ava 2s  .c  o m*/
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.erudika.para.i18n.LanguageUtils.java

/**
 * Default constructor.//from w w w .ja v a2  s  .co  m
 * @param search a core search instance
 * @param dao a core persistence instance
 */
@Inject
public LanguageUtils(Search search, DAO dao) {
    this.search = search;
    this.dao = dao;
    for (Object loc : LocaleUtils.availableLocaleList()) {
        Locale locale = new Locale(((Locale) loc).getLanguage());
        String locstr = locale.getLanguage();
        if (!StringUtils.isBlank(locstr)) {
            allLocales.put(locstr, locale);
            progressMap.put(locstr, 0);
        }
    }
}

From source file:org.craftercms.engine.targeting.impl.LocaleTargetIdManager.java

@Override
public List<String> getAvailableTargetIds() {
    String[] availableTargetIds = SiteProperties.getAvailableTargetIds();
    if (ArrayUtils.isEmpty(availableTargetIds)) {
        List<Locale> availableLocales = LocaleUtils.availableLocaleList();
        List<String> availableLocaleStrs = new ArrayList<>(availableLocales.size());

        for (Locale locale : availableLocales) {
            String localeStr = locale.toString();
            // Ignore empty ROOT locale
            if (StringUtils.isNotEmpty(localeStr)) {
                availableLocaleStrs.add(StringUtils.lowerCase(localeStr));
            }//from   w w w  .  j  a  v  a  2 s  .co  m
        }

        return availableLocaleStrs;
    } else {
        return Arrays.asList(availableTargetIds);
    }
}

From source file:org.mayocat.rest.resources.LocalesResource.java

@GET
public Response getLocales() {
    if (localesRepresentations == null) {
        Set<LocaleRepresentation> locales = Sets.newHashSet();
        List<Locale> availableLocales = LocaleUtils.availableLocaleList();
        for (final Locale locale : availableLocales) {
            StringBuilder nameBuilder = new StringBuilder();
            nameBuilder.append(locale.getDisplayLanguage());
            if (!Strings.isNullOrEmpty(locale.getDisplayCountry())) {
                nameBuilder.append(" (");
                nameBuilder.append(locale.getDisplayCountry());
                nameBuilder.append(")");
            }/*w w w  .j  a v a  2 s  .  c  o  m*/
            final String name = nameBuilder.toString();
            locales.add(new LocaleRepresentation(locale.toLanguageTag(), name));
        }
        Ordering<LocaleRepresentation> nameOrdering = Ordering.natural()
                .onResultOf(new Function<LocaleRepresentation, String>() {
                    public String apply(LocaleRepresentation from) {
                        return from.getName();
                    }
                });

        localesRepresentations = ImmutableSortedSet.orderedBy(nameOrdering).addAll(locales).build();
    }

    return Response.ok(localesRepresentations).build();
}