Android Play商店本地化问题

时间:2019-01-08 12:10:08

标签: android-studio

我正在处理一个android项目,并且我用两种语言本地化了我的应用程序,问题是当我直接从android studio运行我的应用程序但在Google Play商店中上传我的项目并下载该应用程序时,它运行良好从play store本地化在某些版本的Android中不起作用。

这是我设置本地语言的Java代码。

 private static Context updateResources(Context context) {

        Locale locale = new Locale("fa","AF");
        Locale.setDefault(locale);
        Resources res = context.getResources();
        Configuration config = new Configuration(res.getConfiguration());
        if (Build.VERSION.SDK_INT >= 17) {
            config.setLocale(locale);
            context = context.createConfigurationContext(config);
        } else {
            config.locale = locale;
            res.updateConfiguration(config, res.getDisplayMetrics());
        }
        return context;
    }

这是我的英语版式文件。

<resources xmlns:tools="http://schemas.android.com/tools" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <string name="update">Update</string>
    <string name="app_version_title">New version</string>
    <string name="app_version_title_second">is now available</string>
    <string name="logout_msg">Are you sure you want to logout?</string>
    <string name="logout_title">Log Out?</string>
    <string name="languages">Languages</string>
    <string name="km">Km</string>
</resources>

这是我的Persion布局文件。

<resources xmlns:tools="http://schemas.android.com/tools" xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <string name="update">به روز رسانی </string>
    <string name="app_version_title">نسخه جدید</string>
    <string name="app_version_title_second">موجود است</string>
    <string name="logout_msg">آیا مطمئین هستید که خارج میشوید؟ </string>
    <string name="logout_title">خروج؟</string>
    <string name="languages">زبانها</string>
    <string name="km">کیلومتر</string>
</resources>

这是我的Values文件夹的结构。

个值     strings.xml 价值观fa-rAF     strings.xml

2 个答案:

答案 0 :(得分:1)

如果您使用应用捆绑包在Play商店中发布,则android应用捆绑包功能会根据优化语言和较小的apk文件将捆绑包拆分为apk。阅读更多here。因此,只有与用户语言环境匹配的apk才会安装在设备上。因此,动态更改语言将不起作用,因为已安装的apk将仅包含与用户电话的语言环境相同的语言。 为防止基于语言进行拆分,您需要在以下的 app build.gradle文件中添加以下内容。

android {
  ...
  ...
  bundle {
    language {
        enableSplit = false
    }
}

}

答案 1 :(得分:0)

我遇到了完全相同的问题。 您的代码没有错。

这给了我艰难的时光,但我终于想通了。

当您从Google Play下载应用程序时-尝试设置用户在“设置”中定义的“语言”列表中不存在的语言环境时-该应用程序将使用默认的strings.xml

向遇到此问题的人提问,将波斯语添加到设置的“语言”列表中-然后他必须卸载该应用程序-并重新安装它(这很糟Google)-该应用程序将使用您的strings.xml值-fa-rAF。

当您考虑它时-它具有某种意义。

无论如何-如果很关键,您可以考虑在运行时检查文本并向用户显示一条消息,并指示他解决问题。

祝你好运