FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gettext.install() ignores previous call to locale.setlocale() · Issue #64243 · python/cpython · GitHub

Repository navigation

gettext.install() ignores previous call to locale.setlocale() #64243

Open

Description

mannequin
BPO 20044
Nosy @jwilk, @abadger

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2013-12-21.16:15:20.607>
labels = ['library']
title = 'gettext.install() ignores previous call to locale.setlocale()'
updated_at = <Date 2019-05-12.14:29:47.179>
user = 'https://bugs.python.org/fmoreau'

bugs.python.org fields:

activity = <Date 2019-05-12.14:29:47.179>
actor = 'a.badger'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2013-12-21.16:15:20.607>
creator = 'fmoreau'
dependencies = []
files = []
hgrepos = []
issue_num = 20044
keywords = []
message_count = 2.0
messages = ['206762', '342258']
nosy_count = 3.0
nosy_names = ['jwilk', 'a.badger', 'fmoreau']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue20044'
versions = ['Python 2.7']

Linked PRs

Activity

  1. fmoreau commented on Dec 21, 2013

    fmoreaumannequin
    MannequinAuthor

    It seems that gettext.install() uses environment variables such as LANGUAGE, to find out which language it should use to find the translation file.

    This means that any local settings done by setlocale() previoulsy are ignored.

    I don't think it's the case with the C implementation.

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Dec 21, 2013
  3. abadger commented on May 12, 2019

    abadgermannequin
    Mannequin

    I tested a small C program and found that setlocale takes precedence for LC_ALL, LC_MESSAGES, and LANG but not for LANGUAGE.

    int main(int argc, char **argv) {
        char *message1;
    //setlocale (LC_ALL, "");
    setlocale (LC_ALL, "pt_BR.utf-8");
    bindtextdomain ("testc", "/srv/python/cpython/tmp");
    textdomain ("testc");
    
        message1 = gettext("lemon");
        printf("%s\n", message1);
        return 0;
    }
    $ LC_ALL=es_MX.utf-8 LANGUAGE= LC_MESSAGES=es_MX.utf-8 LANG=es_MX.utf-8 ./test
    limão
    
    $ LANGUAGE=es_MX  LANG=es_MX.utf-8 ./test
    limón

    So this could be considered a bug in the stdlib's gettext. If we fix it, we'll need to make sure that we continue to honor LANGUAGE, though.

  4. transferred this issue fromon Apr 10, 2022
  5. StanFromIreland commented on Feb 23, 2025

    Member
    • locale.setlocale calls _setlocale which sets the variable for the process
    • gettext.find checks the environment variables: LANG, LANGUAGES, LC_ALL, LC_MESSAGES by os.environ.get()

    gettext.find should be modified to fallback to locale.getlocale() which checks the variable for the python process.

  6. added
    triagedThe issue has been accepted as valid by a triager.
    type-bugAn unexpected behavior, bug, or error
    on Feb 25, 2025
  7. picnixz commented on Feb 25, 2025

    Member
  8. tomasr8 commented on Feb 25, 2025

    Member

    I think it makes sense to align our gettext implementation with C, that is, let the result of locale.getlocale override all the environment variables except for LANGUAGE.

    In any case, this part of gettext has no dedicated tests. I have a patch ready which tests gettext._expand_lang but more tests will be needed also for gettext.find. Once there is sufficient coverage we can look into fixing this

  9. StanFromIreland commented on Feb 25, 2025

    Member

    Testing will not be too simple, environment variables are not something we can really control.

  10. tomasr8 commented on Feb 25, 2025

    Member

    I don't think it'll be that bad, we have EnvironmentVarGuard for that :)

  11. StanFromIreland commented on Feb 27, 2025

    Member

    Can I write some tests for find() or do you already have some ready?

  12. tomasr8 commented on Feb 27, 2025

    Member

    Can I write some tests for find() or do you already have some ready?

    Feel free! I will open a PR for _expand_lang but I haven't started on find yet. I opened #130655 for it

  13. removed
    type-bugAn unexpected behavior, bug, or error
    on Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytriagedThe issue has been accepted as valid by a triager.

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL