class LanguageIdentifierConverter {

    public static Locale toLocale(final String identifier) {
        if ((identifier == null) || identifier.isEmpty()) {
            return null;
        }
        final String[] parts = identifier.split("-");
        final String language = parts[0];
        if (language.length() != 2) {
            throw new IllegalArgumentException(
                    "Language must be a 2-letter code!");
        }
        if (parts.length == 1) {
            return new Locale(language.toLowerCase());
        }
        final String country = parts[1];
        if (country.length() != 2) {
            throw new IllegalArgumentException(
                    "Country must be a 2-letter code!");
        }
        return new Locale(language.toLowerCase(), country.toUpperCase());
    }

    private  LanguageIdentifierConverter();

}