blob: 1af37eef14249a060871255bec6a809b64fb7482 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.preferences;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;
public class LocaleUtils {
private LocaleUtils() {
}
/**
* @param locale
* @return the display name for the given locale
*/
public static String getDisplayName(Locale locale) {
String displayName = locale.getDisplayLanguage();
if (locale.getLanguage().length()>0 && locale.getCountry().length()>0){
displayName = displayName + " " + locale.getDisplayCountry();
if (locale.getVariant().length()>0) {
displayName = displayName + " " + locale.getDisplayVariant();
}
}
return displayName;
}
/**
* @param locales the array of locales, that should be sorted
*/
public static void sortLocalesOnDisplayName(Locale[] locales) {
Comparator<Locale> localeComparator = (locale1, locale2) -> {
return locale1.getDisplayName().compareTo(locale2.getDisplayName());
};
Arrays.sort(locales, localeComparator);
}
}