Handle dynamic language change within the app on android app bundle
Asked Answered
C

3

34

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

Collier answered 27/6, 2018 at 3:34 Comment(0)
D
47

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
        }
    }
}
Doddering answered 27/6, 2018 at 4:5 Comment(6)
i guess,this will be having a negative impact on app size then...??wont this ?Collier
@al_mukthar Its your requirement right? It will add all the string resources and might result in increase of sizeDoddering
its ok if its around ~2mb ..will it go above this ?Collier
@al_mukthar It all depends on the number of strings you have and number of locale you support. Check out this blog for more details.Doddering
thanks sagar for pointing in the right direction,ingfact i have only one locale extra,ie arabic..and resources are not that big to increase the app size too much...accepting your answer..Collier
This still works but the documentation is pretty hidden: developer.android.com/guide/app-bundle/…Airship
F
10

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

Freestone answered 28/3, 2019 at 12:0 Comment(0)
P
3

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

Painting answered 20/9, 2018 at 11:0 Comment(4)
Did you find a solution to trigger the download of the language manually?Martie
I've asked Google about this. Currently you can't. But they say they are working on it, and will add this feature in the future.Painting
What happens with no connectivity? Assuming new lang is delayed in this case.Cooke
Yes the downloading will be postponed at some point later. But this is handled by the Play Framework, so we don't really know when exactly.Painting

© 2022 - 2024 — McMap. All rights reserved.