Android studio Android play商店本地化问题

Android studio Android play商店本地化问题,android-studio,Android Studio,我正在从事一个android项目,我用两种语言对我的应用程序进行了本地化,问题是当我直接从android studio运行我的应用程序时,它工作正常,但当我在google play store上传我的项目并从play store下载应用程序时,它的本地化在某些版本的android中不起作用 这是我设置本地语言的java代码。 private static Context updateResources(Context context) { Locale locale = ne

我正在从事一个android项目,我用两种语言对我的应用程序进行了本地化,问题是当我直接从android studio运行我的应用程序时,它工作正常,但当我在google play store上传我的项目并从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>
<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>
这是我的英文布局文件。

 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>
<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>

更新
新版本
现在有了
您确定要注销吗?
注销?
语言文字
公里
这是我的Persion布局文件。

 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>
<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>

به روز رسانی 
نسخه جدید
موجود است
آیا مطمئین هستید که خارج میشوید؟ 
خروج؟
زبانها
کیلومتر
这是“我的价值观”文件夹的结构。

 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>
<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>
价值观 strings.xml 英国皇家空军
xml

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

这让我很难受,但我终于明白了

当您从Google play下载应用程序时,如果您试图设置用户在设置中定义的语言列表中不存在的区域设置,则应用程序将使用默认的strings.xml

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

当你思考它时,它有一些意义

无论如何,如果它是关键的,你可以考虑检查运行时的文本并向用户显示一条消息并指示他解决这个问题。p>


祝您好运

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

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

我认为当您要生成签名包或APK时,您选择“Android应用包”,您必须选择“APK”,因为您使用的是strings.xml本地化,您可以阅读更多内容


谢谢你的回答我也这么做了,你说,当我把波斯人语言添加到语言列表中时,它工作得很好,但我想解决这个问题,但它不工作。因为我使用了设备语言列表中不可用的另一种语言(普什图语),因为普什图语不起作用。@Azizullah我没有找到解决方法。。。我想你将不得不接受这个限制这对我来说很有效,但有一件事你忘了提到,手机必须支持阿拉伯语。有时用户必须下载语言本身。(默认为英语)