Getting the Locale short code
In Java it is easy enough to get the default Locale, but is there a way to get the short code that you see so often in websites such as lang=en or lang=zh
I need to send to informatio开发者_C百科n to a website but need the short code so the response will be in the correct language.
Locale.getDefault().getLanguage();
Use the Locale.getLanguage()
method (API Link)
Returns the language code for this locale, which will either be the empty string or a lowercase ISO 639 code.
ISO-639 is the standard for two-letter language codes. See here for the list.
精彩评论