Giter Site home page Giter Site logo

Comments (5)

B3nedikt avatar B3nedikt commented on August 29, 2024

You probably enabled splitting for your aab. Just add this to your build.gradle:

android {
    bundle {
        language {
            // We want to be able to switch the locale at runtime using AppLocale!
            enableSplit = false
        }
    }
}

I may add this to the Readme ;)
Does this fix it for you?

from applocale.

arif2k17 avatar arif2k17 commented on August 29, 2024

Hi, Extremely sorry for the late response. I was out of town. Yes that solves the issue but this solution is discouraged by google as it skip the benefit of .aab file. Using this solution increases the app size. I was wondering if you could use PlayCore library which is recommended by google for App locale changes.

Documentation URL: https://developer.android.com/guide/playcore/dynamic-delivery#lang_resources

I think adding this feature will make this library A complete & perfect library for In-App-Lang-Picker. If i wasn't a beginner in Android App Development i would send a pull request and add this feature :( I was wondering you could do it easily.

Please let me know if you can add this feature so that i can use this library for each of projects.
Please add that feature.
Anyway, Big thanks for what you did to help developers like me. Thank you.

from applocale.

B3nedikt avatar B3nedikt commented on August 29, 2024

No problem you´re welcome :) Yes, this disables splits for languages and will lead to a bigger app size. But if you don´t support that many languages, the size difference is marginal, as we are only talking about a few XML files here. Most of the savings from using the aab file format comes from large binary files like images, native libs etc. When you have a large app with many languages supported this might me a different issue though.

I may integrate the lib with PlayCore in some way, however I am not sure how as I don´t want the lib to depend on the Play Core library directly. Maybe an extra artifact which automatically installs/uninstalls languages.

For now I would suggest to just use the PlayCore library manually. With AppLocale this would look like this:

Adjust your Application:

class MyApplication : SplitCompatApplication() {
    
        override fun attachBaseContext(base: Context) {
            super.attachBaseContext(base)

            SplitCompat.install(this)
        }
}

Your base activity:

abstract class BaseActivity : AppCompatActivity() {

    override fun attachBaseContext(newBase: Context) {
        super.attachBaseContext(ViewPumpContextWrapper.wrap(AppLocale.wrap(newBase)))

        SplitCompat.installActivity(this)
    }

    override fun getResources(): Resources {
        return AppLocale.wrap(baseContext).resources
    }
}

And when you want to change the locale:

        val newLocale = Locale.FRENCH

        val request = SplitInstallRequest.newBuilder()
                .addLanguage(newLocale)
                .build()

        val splitInstallManager = SplitInstallManagerFactory.create(this)
        splitInstallManager.startInstall(request)
                .addOnFailureListener { error ->
                    // Handle the error
                }
                .addOnCompleteListener {
                    AppLocale.desiredLocale = newLocale
                }

Do not forget to handle possible network errors, you´re users might try to change the app language when they are offline ;)

from applocale.

arif2k17 avatar arif2k17 commented on August 29, 2024

Thanks mate :)

from applocale.

B3nedikt avatar B3nedikt commented on August 29, 2024

Finally got the time to document this in the Readme ;)

from applocale.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.