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

Global locale changer #55

Open
SKART1 opened this issue Mar 13, 2017 · 8 comments
Open

Global locale changer #55

SKART1 opened this issue Mar 13, 2017 · 8 comments

Comments

@SKART1
Copy link
Contributor

SKART1 commented Mar 13, 2017

Could you please implement possibility of changing global locale like it is done in Custom Locale
app

It may be used in tests which use locale-dependent WebView

@Kisty
Copy link
Contributor

Kisty commented Mar 13, 2017

I believe the library already does application-scoped locale changing already. Does this help your use-case or does it require device-scoped locale?

https://github.com/linkedin/test-butler/blob/master/test-butler-library/src/main/java/com/linkedin/android/testbutler/TestButler.java#L221

@SKART1
Copy link
Contributor Author

SKART1 commented Mar 13, 2017

WebView does not use application-scoped locale, it uses device-scoped. I have tried to use method you have mentioned, but it does not take affect

@Kisty
Copy link
Contributor

Kisty commented Mar 13, 2017

Have you tried doing the locale change in setUp()? Could be that the locale needs to be changed before the activity is loaded.

@SKART1
Copy link
Contributor Author

SKART1 commented Mar 13, 2017

@Kisty Yep - tried in custom Runner

@Kisty
Copy link
Contributor

Kisty commented Mar 13, 2017

That's strange. How are you getting the locale in the WebView document?

@SKART1
Copy link
Contributor Author

SKART1 commented Mar 13, 2017

@Kisty
url[0] = webView.getUrl();

And it returns url with device-scoped locale

@Kisty
Copy link
Contributor

Kisty commented Mar 13, 2017

Also, it looks like the way WebView behaves on Android 7.0 has changed. To test this out, can you try running the app on a API 23 emulator?

The Solution:

The only way to solve this problem is to reset the default locale manually in every Activity, or at least every Activity that has a WebView.

public static void setLocale(Locale locale){
    Locale.setDefault(locale);
    Context context = MusafirApplication.getInstance();
    final Resources resources = context.getResources();
    final Configuration config = resources.getConfiguration();
    config.setLocale(locale);
    context.getResources().updateConfiguration(config,
            resources.getDisplayMetrics());
}

Call the above method before calling setContentView(...) in the onCreate() method of all your Activities.

As an addendum, Chrome custom tabs are now the preferred way of rendering in-app web pages.

http://stackoverflow.com/a/40675539/818821

@drewhannay
Copy link
Contributor

Before open sourcing Test Butler, we had tried setting the global locale and found it to be extremely flaky. That said, I don't remember the details of how we were setting it and this was before Test Butler was signed as a system-level app (so there may be alternate approaches that are now available to us).

I'm open to trying to add this again. Not sure when I'll have time to get to it, so if someone is interested in picking this up, let me know.

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

No branches or pull requests

3 participants