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

Support standard library locale module #1150

Open
mhsmith opened this issue May 9, 2024 · 2 comments
Open

Support standard library locale module #1150

mhsmith opened this issue May 9, 2024 · 2 comments

Comments

@mhsmith
Copy link
Member

mhsmith commented May 9, 2024

From beeware/toga#2562:

Hello, how can I recognize the current language with locale.getlocale()?
When i try it on android, it only returns ('en_US', 'UTF-8'), even if default language was set to an other language.

I don't think Android sets any of the standard LC_... environment variables, but we can get this information from the Android API:

# In a Toga app, the equivalent of `context` is `app._impl.native`, 
# where `app` is your `toga.App` object.
str(context.getResources().getConfiguration().getLocales().get(0))

This will return a string in the form en_US, which can be passed to locale.setlocale.

@freakboy3742
Copy link

Is this not something that could/should be upstreamed into CPython itself? Or is this a case where because the usual C API isn't honored, fixing it would require the use of a Java API, would require either CPython to adopt Chaquopy (or another JNI wrapper), or the implementation of locale to replicate enough raw JNI handling to satisfy the API call?

There's a broad analog of this with the iOS implementation of webbrowser - that code does the bare minimum ctypes invocation to call the native Objective C API to launch the browser. Would something analogous to that be possible for Android (both for webbrowser, and for locale?)

At the very least, it seems like there should be a note in the CPython docs that locale has limitations on Android.

@mhsmith
Copy link
Member Author

mhsmith commented May 10, 2024

Would something analogous to that be possible for Android (both for webbrowser, and for locale?)

Yes, but as with webbrowser (#1149), an upstream implementation would need to use a non-public API to get a reference to the context.

At the very least, it seems like there should be a note in the CPython docs

I'll include it in a future docs PR when I update the "Availability" markers for Android.

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

2 participants