Comments (5)
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.
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.
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.
Thanks mate :)
from applocale.
Finally got the time to document this in the Readme ;)
from applocale.
Related Issues (16)
- Doesn't persist desired locale. HOT 1
- IllegalStateException: A factory has already been set on this LayoutInflate HOT 2
- NullPointerException: Android Marshamllow (API 23) attachBaseContext HOT 3
- Doesn't work for popup settings menu HOT 2
- Application start error HOT 8
- Locale doesn't change in child of NavigationView HOT 2
- WebEngage Runtime Exception HOT 3
- SearchView not worked HOT 1
- Unable to set the Locale to Arabic HOT 2
- Doesn't work in RecyclerView HOT 1
- Webview is crashing, but not able to reproduce exact case. HOT 1
- AppLocale & PreferenceFragmentCompat HOT 2
- Caused by java.lang.ClassCastException: yb.c cannot be cast to android.app.ContextImpl HOT 4
- How to remove locale change listener? HOT 3
- java.lang.ClassCastException: dev.b3nedikt.app_locale.AppLocaleContextWrapper cannot be cast to android.app.ContextImpl HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from applocale.