具有应用内语言环境更改的Android App Bundle [英] Android App Bundle with in-app locale change

查看:220
本文介绍了具有应用内语言环境更改的Android App Bundle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我需要从应用程序内部更改应用程序区域设置时(例如,在应用程序内部进行语言更改设置),我遇到了AAB的问题,问题是AAB仅为我提供了设备语言资源,例如例如:

I've a problem with AAB when I need to change the app locale from within the app itself(i.e. have the language change setting inside the app), the issue is that the AAB gives me only my device languages resources, for example:

我的设备中安装了英语和法语,因此Aab仅向我提供英语和法语的资源,

my device has English and French languages installed in it, so AAb gives me only the resources for English and French,

但是在应用程序内部,可以选择在英语,法语和印尼语之间切换语言

but from within the app itself there is a choice to switch the language between English, French, and Indonesian,

在这种情况下,当将语言更改为英语或法语时,一切运行正常,但是当将其更改为印度尼西亚语时,该应用程序只是进入崩溃循环,因为它一直在寻找印度尼西亚语,但找不到.

in that case, when changing the language to English or French everything is working perfectly, but when changing it to Indonesian, the app simply enters a crash loop as it keep looking for Indonesian language but it can't find.

这里的问题是,即使我重新启动了该应用程序,由于该应用程序仍在寻找缺少的语言资源,它也会再次进入崩溃循环,并且这里唯一的解决方案是清除现金或重新安装这些解决方案,普通用户将无法通过.

The problem here is that even if I restarted the app, it enters the crash loop again as the app is still looking for the missing language resources, and here the only solution is to clear cash or reinstall which are the solutions that the normal user won't go through.

只需提一下,这就是我通过应用程序更改语言环境的方式:

Just to mention it, this is how I change the locale through the app:

    // get resources
    Resources res = context.getResources();
    // create the corresponding locale
    Locale locale = new Locale(language); // for example "en"
    // Change locale settings in the app.
    android.content.res.Configuration conf = res.getConfiguration();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        conf.setLocale(locale);
        conf.setLayoutDirection(locale);
    } else {
        conf.locale = locale;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        context.getApplicationContext().createConfigurationContext(conf);
    }
    res.updateConfiguration(conf, null);


P.S.将该应用程序构建为APK时,可以完美运行.


P.S. The app is working perfectly when build it as APK.

推荐答案

PlayCore API 现在支持按需下载另一种语言的字符串: https://developer.android.com/guide/app-bundle/playcore#lang_resources

The PlayCore API now supports downloading the strings for another language on-demand: https://developer.android.com/guide/app-bundle/playcore#lang_resources

替代解决方案(不利):

您可以通过在build.gradle中添加以下配置来禁用按语言拆分

You can disable the splitting by language by adding the following configuration in your build.gradle

android {
    bundle {
        language {
            // Specifies that the app bundle should not support
            // configuration APKs for language resources. These
            // resources are instead packaged with each base and
            // dynamic feature APK.
            enableSplit = false
        }
    }
}

后一种解决方案将增加应用程序的大小.

This latter solution will increase the size of the app.

这篇关于具有应用内语言环境更改的Android App Bundle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆