加载语言资源从特定的字符串? [英] Load language specific string from resource?

查看:123
本文介绍了加载语言资源从特定的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前在我的我需要加载特定语言的字符串Android应用程序一一点。例如:

At one point in one of my Android apps I need to load strings of a specific language. For example:

 values:    <string name="txt_help">Help</string>
 values-de: <string name="txt_help">Hilfe</string>
 values-fr: <string name="txt_help">Aider</string>

现在我需要的缺省(值)文本。

Now I need the default (values) text.

有没有办法来加载密钥txt_help与给定的​​语言恩?我找不到我在哪里可以设置一个区域作为附加参数的方法。

Is there a way to load the key "txt_help" with a given language "en"? I can't find a method where I can set a locale as an additional parameter.

或者我可以创建一个新的ResourceManager与给定的语言环境,并通过这个资源对象读取字符串?

Or can I create a new ResourceManager with a given locale and read the String through this resource object?

在预先感谢。 HJW

Many thanks in advance. hjw

推荐答案

展望文档< /一>,这看起来很有希望:

Looking in the documentation, this looks promising:

Resources standardResources = context.getResources();
AssetManager assets = standardResources.getAssets();
DisplayMetrics metrics = standardResources.getDisplayMetrics();
Configuration config = new Configuration(standardResources.getConfiguration());
config.locale = Locale.US;
Resources defaultResources = new Resources(assets, metrics, config);

在换句话说,创建一个配置为标准的语言环境的新资源对象。

In other words, create a new Resources object configured to a standard locale.

这篇关于加载语言资源从特定的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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