public static Locale toLocale()

in src/main/java/org/apache/commons/configuration2/convert/PropertyConverter.java [559:577]


    public static Locale toLocale(final Object value) throws ConversionException {
        if (value instanceof Locale) {
            return (Locale) value;
        }
        if (!(value instanceof String)) {
            throw new ConversionException("The value " + value + " can't be converted to a Locale");
        }
        final String[] elements = ((String) value).split("_");
        final int size = elements.length;

        if (size >= 1 && (elements[0].length() == 2 || elements[0].isEmpty())) {
            final String language = elements[0];
            final String country = size >= 2 ? elements[1] : "";
            final String variant = size >= 3 ? elements[2] : "";

            return new Locale(language, country, variant);
        }
        throw new ConversionException("The value " + value + " can't be converted to a Locale");
    }