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

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

Introduction

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

Prototype

public static List<Locale> localeLookupList(final Locale locale) 

Source Link

Document

Obtains the list of locales to search through when performing a locale search.

 localeLookupList(Locale("fr","CA","xxx")) = [Locale("fr","CA","xxx"), Locale("fr","CA"), Locale("fr")] 

Usage

From source file:de.viaboxx.nlstools.formats.BundleWriter.java

public static Properties createProperties(String locale, MBBundle bundle, boolean merged, boolean debugMode,
        Task task) {//from www.  j a  va  2 s  . c  om
    Iterator<MBEntry> entries = bundle.getEntries().iterator();
    Properties p = new Properties();

    while (entries.hasNext()) {
        MBEntry eachEntry = entries.next();
        String key = eachEntry.getKey();
        MBText langText = eachEntry.getText(locale);
        if (langText == null && merged && !StringUtils.isEmpty(locale)) {
            List<Locale> locales = LocaleUtils.localeLookupList(LocaleUtils.toLocale(locale));
            // start with i=1 because locales.get(0) has already been tried - it is the 'locale' itself.
            for (int i = 1; i < locales.size(); i++) { // try to find from parent. begin with next specific
                Locale each = locales.get(i);
                langText = eachEntry.getText(each.toString());
                if (langText != null)
                    break;
            }
            if (langText == null)
                langText = eachEntry.getText("");
        }
        if (langText != null) {
            String value;

            // in debug mode the keys are also displayed as labels
            if (!debugMode) {
                value = langText.getValue();
            } else {
                value = key;
            }
            // Continue text at line breaks followed by whitespaces (indentations due to code formatter etc.)
            int indentIndex;
            while (value != null && (indentIndex = value.indexOf("\n ")) > -1) {
                int lastBlankIndex = indentIndex + 1;
                while (lastBlankIndex + 1 < value.length()
                        && Character.isWhitespace(value.charAt(lastBlankIndex + 1))) {
                    lastBlankIndex++;
                }
                value = value.substring(0, indentIndex) + ' ' + value.substring(lastBlankIndex + 1);
            }
            task.log("'" + key + "' ==> '" + value + "'", Project.MSG_DEBUG);
            if (key != null && value != null) {
                p.setProperty(key, value);
            }
        }
    }
    return p;
}

From source file:org.lockss.util.MetadataUtil.java

/** Return the closest matching Locale in the set, or null if none. Looks
 * for an exact match, then an exact match after dropping the variant (if
 * any), then after dropping the country (if any).
 * @param targetLocale the target Locale
 * @param locales the list of Locales in which to search
 * @return the closest matching Locale or null
 *//*from w  ww .j a v  a2  s  . c o  m*/
public static Locale findClosestLocale(Locale targetLocale, Set<Locale> locales) {
    List<Locale> search = LocaleUtils.localeLookupList(targetLocale);
    for (Locale locale : search) {
        if (locales.contains(locale)) {
            return locale;
        }
    }
    return null;
}