java - 我怎样才能获得语言环境的语言?
问题描述
请问题主,如何在android的locale中获取语言?我使用 countrycodepicker 获取国家代码并使用 locale.getLanguage 获取该国家/地区的语言。但是当我选择美国,法国,英国,......它得到错误的语言,如美国 - ikt; 法国-gsw?
String countryCode = ccp.getSelectedCountryNameCode();
String languageCode = null;
Locale[] all = Locale.getAvailableLocales();
for (Locale locale : all) {
String country = locale.getCountry();
if(country.equalsIgnoreCase(countryCode)){
languageCode = locale.getLanguage();
}
}
解决方案
要获取当前的 Locale 语言,请使用以下方法:
Locale.getDefault().getLanguage()
推荐阅读
- c# - 如何在将 xml 文件反序列化为 C# 模型时阻止 XmlReader.Create() 缓冲结果
- python-3.x - API 请求 - 创建字典
- javascript - 无法覆盖 CORS 策略。我做错了什么?
- amazon-web-services - AWS CloudFormer 支持哪些 AWS 服务?
- java - 从 Thymeleaf 中的对象列表填充输入标签的默认值
- java - 用接口替换装饰器模式中的继承
- java - 使用 Java 注释,有没有办法在其他模式中指定 Swagger/OpenAPI 模式?
- reactjs - 初始化期间返回的减速器“语言”未定义 - combineReducers 出错
- javascript - ipywidget 可以从 URL 而非本地磁盘获取其 JavaScript 吗?
- php - 在 Windows CMD 中 PHP 将数组导出为 CSV?