java - Which format of "en_US" and "en-US" should be used in Http header request as Accept-Language? -
i tested these 2 formats , server okay both. since http header fields saying "en-us" format , local java class returning "en_us", i'm little bit confused of them use!
my partial code this:
// set accepted language list<string> acceptedlanguages = null; final locale defaultlocale = locale.getdefault(); // en if (defaultlocale != null) { final string defaultlang = defaultlocale.tostring(); // en_us if (!textutils.isempty(defaultlang)) { acceptedlanguages = new arraylist<string>(); acceptedlanguages.add(defaultlang); // add en fallback if applicable if (!httpclient.default_accepted_language_country.equals(defaultlang)) { acceptedlanguages.add(httpclient.default_accepted_language_country); } } } string header = httpclient.getacceptlanguageheader(acceptedlanguages); // like: cz_ch;q=1.0, en_us;q=0.9 this.mhttpgetrequest.addheader(httpheaders.accept_language, header);
getacceptlanguageheader()
method adds en_us;q=0.9
to string if user's device language in not en_us
.
any idea appreciated. thanks.
i believe hyphen "-" accepted part of http standard, while underscore "_" rejected. see w3c http v1.1 standard, header field definitions, section 14.4 accept-language more info.
note: w3c stands world wide web consortium.
Comments
Post a Comment