如何获得地区的语言环境? [英] How to get locale with region?
本文介绍了如何获得地区的语言环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用"en_us","en_gb"之类的区域来获取当前设备的语言环境.
I am trying to get the current device locale with the region like "en_us","en_gb".
我正在调用 Locale.getDefault().getLanguage()
,它仅返回两个字母代码 en
.
I am calling Locale.getDefault().getLanguage()
and it returns only the two letters code en
.
推荐答案
"en_us"或"en_gb"之类的格式具有语言代码" _国家/地区代码"
Format like "en_us" or "en_gb" has "language code"_"country code"
语言环境对象同时包含国家代码和语言代码.
A Locale object contains both country code and language code.
因此您可以使用下面的代码片段格式化自己的代码.
So you can use below snippet to format your own code..
String cCode = Locale.getDefault().getCountry();
String lCode = Locale.getDefault().getLanguage();
String code = lCode+"_"+cCode;
或
您可以在Locale对象上使用 toString()
方法获取数据
you can use toString()
method on Locale object to get the data
String code = Locale.getDefault().toString();
这篇关于如何获得地区的语言环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文