Skip to content

Support standard library locale module #1150

@mhsmith

Description

@mhsmith

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.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions