Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inconsistent language between ui components #31

Open
mukswilly opened this issue May 27, 2020 · 10 comments
Open

inconsistent language between ui components #31

mukswilly opened this issue May 27, 2020 · 10 comments

Comments

@mukswilly
Copy link

Screenshot_20200527-102150
Screenshot_20200527-102244
components of the app that use strings directly in xml eg the layouts correctly respond to language changes, however, Strings pulled by getString(R.string.xxx) remain to the system locale language

@YarikSOffice
Copy link
Owner

YarikSOffice commented May 29, 2020

Hi @napsterphantom ,

Do you use context.createConfigurationContext(config) somewhere in your app to create a localized context?

Could you please provide a sample project reproducing the issue since there are a couple of similar issues reported already, but I still can't identify the problem without seeing the code.

Thanks in advance!

@mirrorlarry
Copy link

@napsterphantom , I also have the same problem in my app while using this library. Language inconsistency. but it does not always happen.

This is from my Application onCreate() method.
Lingver.init(this, Constants.LOCALE_MYANMAR) val language = pref.getLocaleLanguage(Constants.KEY_LOCALE_LANGUAGE, Constants.LOCALE_MYANMAR) Lingver.getInstance().setLocale(this, language)

Setting.. when user changes the langauge.

pref.saveToSharedPref(Constants.KEY_LOCALE_LANGUAGE, list[selectedItem].first) Lingver.getInstance().setLocale(this, list[selectedItem].first) dialog.dismiss() val i = Intent(this, SplashScreenActivity::class.java) startActivity(i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)) System.exit(0)
Thanks

@aconsuegra
Copy link

I can consistently reproduce this issue if device language is different than the one chosen in the app and then I open any browser intent and come back to the app. Any possible workaround?

@YarikSOffice
Copy link
Owner

@aconsuegra could you clarify what is your browser intent?
do you open a build-in WebView or intent for an external browser like Google Chrome?

there is a caveat while using web view, you can read more on that in the README.

@YarikSOffice
Copy link
Owner

@mirrorlarry I see an issue in your sample code. After setting a locale you immediately kill the app process by System.exit(0), potentially preventing shared preferences to successfully persist the setting since it's done asynchronously (on a background thread).

For most of the cases, just restarting the activity back stack (FLAG_ACTIVITY_CLEAR_TASK/FLAG_ACTIVITY_NEW_TASK) is enough to apply new locale, no need to restart a whole app process.

If you indeed need to restart a whole process, you can provide a custom implementation for LocaleStore and persist the setting synchronously just before killing the app.

@aconsuegra
Copy link

@YarikSOffice You are right, my issue is solved after applying the suggested fix

@mirrorlarry
Copy link

@napsterphantom , I also have the same problem in my app while using this library. Language inconsistency. but it does not always happen.

This is from my Application onCreate() method.
Lingver.init(this, Constants.LOCALE_MYANMAR) val language = pref.getLocaleLanguage(Constants.KEY_LOCALE_LANGUAGE, Constants.LOCALE_MYANMAR) Lingver.getInstance().setLocale(this, language)

Setting.. when user changes the langauge.

pref.saveToSharedPref(Constants.KEY_LOCALE_LANGUAGE, list[selectedItem].first) Lingver.getInstance().setLocale(this, list[selectedItem].first) dialog.dismiss() val i = Intent(this, SplashScreenActivity::class.java) startActivity(i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)) System.exit(0)
Thanks

@aconsuegra could you clarify what is your browser intent?
do you open a build-in WebView or intent for an external browser like Google Chrome?

there is a caveat while using web view, you can read more on that in the README.

@mirrorlarry I see an issue in your sample code. After setting a locale you immediately kill the app process by System.exit(0), potentially preventing shared preferences to successfully persist the setting since it's done asynchronously (on a background thread).

For most of the cases, just restarting the activity back stack (FLAG_ACTIVITY_CLEAR_TASK/FLAG_ACTIVITY_NEW_TASK) is enough to apply new locale, no need to restart a whole app process.

If you indeed need to restart a whole process, you can provide a custom implementation for LocaleStore and persist the setting synchronously just before killing the app.

Thank you

@jemshit
Copy link

jemshit commented Feb 1, 2021

In my case it was initialize Admob lately, instead of inside App#onCreate.
I don't know what they doing in that method and causing bug.

@SergiiLitvinenko
Copy link

SergiiLitvinenko commented Apr 15, 2021

Had similar problems after Webwiew was opened inside app. Some ui elements like button texts were not translated. Calling Lingver.getInstance().setLocale(...) in onCreateView of Fragment with Webwiew solved the problem

@sarankumar-ns
Copy link

I also faced this issue. For my use case, I used Custom Tab Intent by androidx browser library to launch the URL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants