This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: gettext.install() ignores previous call to locale.setlocale()
Type: Stage:
Components: Library (Lib) Versions: Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: a.badger, fmoreau, jwilk
Priority: normal Keywords:

Created on 2013-12-21 16:15 by fmoreau, last changed 2022-04-11 14:57 by admin.

Messages (2)
msg206762 - (view) Author: Francis Moreau (fmoreau) Date: 2013-12-21 16:15
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.
msg342258 - (view) Author: Toshio Kuratomi (a.badger) * Date: 2019-05-12 14:29
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.
History
Date User Action Args
2022-04-11 14:57:55adminsetgithub: 64243
2019-05-12 14:29:47a.badgersetnosy: + a.badger
messages: + msg342258
2013-12-21 16:35:23jwilksetnosy: + jwilk
2013-12-21 16:15:20fmoreaucreate