如何获取当前 Android 应用程序显示的语言(区域设置)? [英] How to get language (locale) currently Android app displays?

查看:19
本文介绍了如何获取当前 Android 应用程序显示的语言(区域设置)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何了解当前 Android 应用用于向用户显示文本的语言(区域设置)?

How to get know language (locale) currently Android app uses to display texts to user?

我知道我可以使用 Locale.getDefault() 来获取默认的操作系统区域设置.但如果应用不支持此语言环境,它可能与应用用于显示文本和其他资源的语言环境不同.

I know I can use Locale.getDefault() to get default OS locale. But it may differ from locale used by app to display text and other resources, if this locale isn't supported by app.

我需要确定应用程序显示的语言(区域设置),因此应用程序可以将语言传递给服务器,因此它可以本地化返回的结果.

I need to determine language (locale) displayed by the app, thus the app can pass language to the server, so it can localise returned results.

推荐答案

我自己的解决方案是在strings.xml键值对中添加locale=code>,因此 context.getResources().getString(R.string.locale) 将返回特定于使用的语言环境的语言环境代码.

My own solution is to add to strings.xml key-value pair locale=<locale code>, thus context.getResources().getString(R.string.locale) will return locale code specific for used locale.

这篇关于如何获取当前 Android 应用程序显示的语言(区域设置)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆