Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle dynamic language change within the app on android app bundle

I have used the latest android packing format bundle and shipped my app to beta channel,bundles reduced ~60% of app size which was really awesome ,

my app has support for english and arabic (can be switched within the app on fly)

now the problem : AFAIK the base apk will only have resources for the users language during app download (if at time of download,if the language was english.only string-en.xml gets downlaoded)

so how do i handle the situation where in user switch the language within the app ..

please let me know..

like image 660
al_mukthar Avatar asked Jun 27 '18 03:06

al_mukthar


People also ask

Can I change the language of a single app android?

Once Android 13 is up and running, you can change the language of an individual app by going to Settings, Apps, and choosing the platform you want to change. Scroll down, and right below Battery you should see an entry for Language, which will be set to System default.

What is dynamic app in Android?

Dynamic applications are in some way reliant on an online server or database. When connected, these apps are loaded from a central server so that any iterative changes to development, design or functionality are rolled out across all devices simultaneously.


3 Answers

AFAIK you can do it by using the bundle block to control which types of configuration APKs you want your app bundle to support.

Based on the documentation:

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
        }
    }
}
like image 67
Sagar Avatar answered Oct 19 '22 17:10

Sagar


With the Play Core library version 1.4.0, you can request the Play Store to install resources for a new language configuration on demand and immediately start using it.

// 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);

For more informations: https://developer.android.com/guide/app-bundle/playcore#lang_resources

like image 10
Simon Avatar answered Oct 19 '22 18:10

Simon


Currently I only find that by changing the device language in the system settings, your app will automatically download the additional language APK from Play Store given that you have included that language's resource in your app bundle. Still trying to find if I can manually submit a request for additional language through PlayCore Library within my app...

like image 3
littledog Avatar answered Oct 19 '22 17:10

littledog