public static LocaleCode getByLocale(Locale locale)
    {
        if (locale == null)
        {
            return null;
        }

        // Locale.getLanguage() returns either an empty string or
        // a lower-case ISO 639 code.
        String language = locale.getLanguage();

        // Locale.getCountry() returns either an empty string or
        // a upper-case ISO 3166-1 alphe-2 code.
        String country = locale.getCountry();

        if ((language == null || language.length() == 0) &&
            (country  == null || country.length()  == 0))
        {
            return LocaleCode.undefined;
        }

        // 'language' and 'country' are already lower-case and upper-case,
        // so true can be given as the third argument.
        return getByCode(language, country, true);
    }