在android app bundle上处理app中的动态语言更改

al_*_*har 15 android localization apk

我使用了最新的android包装格式捆绑包,并将我的应用发送到Beta渠道,捆绑减少了应用大小的〜60%,这真是太棒了,

我的应用程序支持英语和阿拉伯语(可以在应用程序中即时切换)

现在的问题是:AFAIK基本apk将仅在应用程序下载期间具有用于用户语言的资源(如果在下载时,如果语言是英语,则只会对string-en.xml进行废弃)

所以我该如何处理用户在应用内切换语言的情况..

请告诉我..

Sag*_*gar 16

AFAIK可以通过使用捆绑软件块来控制您希望应用捆绑软件支持的配置APK类型。

根据文档:

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


Sim*_*mon 8

使用 Play 核心库版本 1.4.0,您可以请求 Play 商店按需安装新语言配置的资源并立即开始使用它。

// Creates a request to download and install additional language resources.
SplitInstallRequest request =
    SplitInstallRequest.newBuilder()
        // Uses the addLanguage() method to include French language resources in the request.
        // Note that country codes are ignored. That is, if your app
        // includes resources for “fr-FR” and “fr-CA”, resources for both
        // country codes are downloaded when requesting resources for "fr".
        .addLanguage(Locale.forLanguageTag("fr"))
        .build();

// Submits the request to install the additional language resources.
splitInstallManager.startInstall(request);
Run Code Online (Sandbox Code Playgroud)

更多信息:https : //developer.android.com/guide/app-bundle/playcore#lang_resources