Android Wear - 支持不同的语言

Android Wear - Supporting different languages

Android Wear 系统仅支持几种语言。有没有办法强制资源管理器使用我在手机 phone 中设置但 Android Wear 系统不支持的语言资源?

例子

在我的 Android Wear 应用程序中,我希望支持三种语言。英语、德语和捷克语。在我的 Android Wear 应用程序中,我有这些包含字符串文件的目录:valuesvalues-devalues -cs.

如果我将 phone 语言设置为德语,我的 Android Wear 应用程序会正确使用德语字符串。但是如果我在我的手机 phone 中设置捷克语,Android Wear 应用程序使用默认值(来自目录:values)字符串。

有什么办法,当我的 phone 有捷克语但捷克语不受 Android穿系统?

提前谢谢你。

编辑

我做了非常丑陋的解决方法。我的移动 phone 应用程序中有与此磨损应用程序相关的服务。当启动我的 wear 应用程序时,我只是询问 phone 它使用什么语言。在它向我发送响应后,我只是尝试在我的 Xamarin Android Wear app.

中切换语言环境

更改区域设置的代码:

myLocale = new Java.Util.Locale(lang);
DisplayMetrics dm = Resources.DisplayMetrics;
Configuration conf = Resources.Configuration;
conf.Locale = myLocale;
Resources.UpdateConfiguration(conf, dm);

其中 lang 是 ISO639-1 代码,myLocale 是 Locale 类型的 activity 属性。

Localization Tips

所述

If an application is missing even one default resource, it will not run on a device that is set to an unsupported locale. For example, the res/values/strings.xml default file might lack one string that the application needs: When the application runs in an unsupported locale and attempts to load res/values/strings.xml, the user will see an error message and a Force Close button.

有关其他信息,您可能还想查看 Language and Locale。它解释了低于 7.0(API 级别 24)的 Android 版本中的资源解析策略。接下来介绍Android7.0中改进的resource-resolution策略。最后,它解释了如何利用更多的语言环境来支持更多的多语言用户。

此外,如给定文档中所述,

When your Java code refers to strings, the system would load strings from the default (en_US) resource file, even if the app has Spanish resources localized under es_ES. This is because when the system cannot find an exact match, it continues to look for resources by stripping the country code off the locale. Finally, if no match is found, the system falls back to the default, which is en_US.

如前所述,您不可能使用不受支持的语言环境。因此,如果您仍然喜欢使用捷克语,则可能需要使用 Android 5.0 或更低版本,其中支持捷克语,如相关 SO post and in list of Android Supported Language and Locales.

中所示