Code example for Locale

Methods: equals, getCountry, getLanguage

0
    private static String getHttpAcceptLanguage() {
        Locale locale = Locale.getDefault();
        StringBuilder builder = new StringBuilder();
 
        addLocaleToHttpAcceptLanguage(builder, locale);
        if (!locale.equals(Locale.US)) {
            if (builder.length() > 0) {
                builder.append(", ");
            } 
            addLocaleToHttpAcceptLanguage(builder, Locale.US);
        } 
        return builder.toString();
    } 
 
    private static void addLocaleToHttpAcceptLanguage( 
            StringBuilder builder, Locale locale) {
        String language = locale.getLanguage();
 
        if (language != null) {
            builder.append(language);
 
            String country = locale.getCountry();
 
            if (country != null) {
                builder.append("-");
                builder.append(country);
            }