加载语言资源从特定的字符串?字符串、加载、语言、资源

由网友(這麽菦丶那庅遠)分享简介:目前在我的我需要加载特定语言的字符串Android应用程序一一点。例如:At one point in one of my Android apps I need to load strings of a specific language. For example:values: 目前在我的我需要加载特定语言的字符串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.

阅读全文

相关推荐

最新文章