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

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

Introduction

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

Prototype

public static List localeLookupList(Locale locale, Locale defaultLocale) 

Source Link

Document

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

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

The result list begins with the most specific locale, then the next more general and so on, finishing with the default locale.

Usage

From source file:org.openengsb.core.api.l10n.BundleStrings.java

@Override
public String getString(String key, Locale locale, String... parameters) {
    @SuppressWarnings("unchecked")
    List<Locale> locales = LocaleUtils.localeLookupList(locale, new Locale(""));
    for (Locale l : locales) {
        Properties p = entries.get(buildEntryFilename(l));
        if (p == null) {
            continue;
        }/*from  w ww  . j  a va 2s  . c o m*/
        if (p.containsKey(key)) {
            String property = p.getProperty(key);
            String format = MessageFormat.format(property, (Object[]) parameters);
            return format;
        }
    }
    return null;
}