An easy way to dynamically replace Strings of your Android App or provide new languages Over-the-air without needed to publish a new release on Google Play.
Apache License 2.0
511
stars
37
forks
source link
getPhilologyRepository function always giving locale as Englies #39
Describe the bug
I have integrated this library in the Application class as mentioned in the docs but I am facing an issue that always I am getting language as English inside getPhilologyRepository function.
In my app, we set the language based on the user profile after login. For Arabic users, it changes to LTR, and for English users, it changes to RTL layout with respective languages. So user can change language in respective settings and I am setting the default language as per the user. As long as the user is logged in the default language will be the one he has set. Once he logs out it will be English.
I am not sure if this causes since I am setting up the logic in the application class and need your advice.
class SampleApp : Application(), HasAndroidInjector {
@Inject
lateinit var androidInjector: DispatchingAndroidInjector<Any>
override fun onCreate() {
super.onCreate()
Cyanea.init(this, resources)
val calligraphyConfig = CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/poppins_regular.ttf")
.setFontAttrId(R.attr.fontPath)
.build()
Philology.init(MyPhilologyRepositoryFactory)
ViewPump.init(
ViewPump.builder()
.addInterceptor(CalligraphyInterceptor(calligraphyConfig))
.addInterceptor(PhilologyInterceptor)
.build()
)
if (BuildConfig.DEBUG) {
Timber.plant(DebugTree())
}
`}`
override fun attachBaseContext(base: Context) {
super.attachBaseContext(base)
if (null == appComponent) {
appComponent = DaggerAppComponent.builder()
.appModule(AppModule(this))
.build()
appComponent?.inject(this)
}
}
companion object {
var appComponent: AppComponent? = null
private set
}
override fun androidInjector(): AndroidInjector<Any> {
return androidInjector
}
}
object MyPhilologyRepositoryFactory : PhilologyRepositoryFactory {
override fun getPhilologyRepository(locale: Locale): PhilologyRepository {
Timber.tag("Philology").d("getPhilologyRepository -> locale - %s", locale.language)
return when (locale.language) {
ENGLISH -> EnglishPhilologyRepository
ARABIC -> ArabicPhilologyRepository
else -> EnglishPhilologyRepository
}
}
}
Describe the bug I have integrated this library in the Application class as mentioned in the docs but I am facing an issue that always I am getting language as English inside getPhilologyRepository function.
In my app, we set the language based on the user profile after login. For Arabic users, it changes to LTR, and for English users, it changes to RTL layout with respective languages. So user can change language in respective settings and I am setting the default language as per the user. As long as the user is logged in the default language will be the one he has set. Once he logs out it will be English.
I am not sure if this causes since I am setting up the logic in the application class and need your advice.