Android Play商店本地化问题

Azi*_*lah 5 android-studio

我正在开发一个android项目,并且用两种语言本地化了我的应用程序,问题是,当我直接从android studio运行我的应用程序但在Google Play商店中上传项目并从Play商店下载该应用程序时,它运行良好它的本地化在某些版本的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;
    }
Run Code Online (Sandbox Code Playgroud)

这是我的英文版面文件。

<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>
Run Code Online (Sandbox Code Playgroud)

这是我的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>
Run Code Online (Sandbox Code Playgroud)

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

值strings.xml值-fa-rAF strings.xml

shi*_*ijo 8

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

android {
  ...
  ...
  bundle {
    language {
        enableSplit = false
    }
  }
}
Run Code Online (Sandbox Code Playgroud)


Gal*_*Rom 3

我遇到了完全相同的问题。你的代码没有任何问题。

这让我很困难,但我终于想通了。

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

要求遇到此问题的人将波斯语添加到设置中的语言列表中 - 然后他必须卸载该应用程序 - 并再次重新安装 - 该应用程序将使用您的 strings.xml 值-fa-rAF。

当你思考它时——它有一定的意义。

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

祝你好运