Matthias Klose <d...@debian.org> writes:

> It would be good to have a self-contained example to show the
> exact issue.

Enable the "de_AT.UTF-8" locale in "dpkg-reconfigure locales",
copy the attached files to a directory, and run "make check"
there.  The C version outputs "test" with glibc 2.19, but the
Python version fails with Python 3.4.2:

gcc -Wall -Wextra -o 840610 840610.c
mkdir -p de/LC_MESSAGES
msgfmt -o de/LC_MESSAGES/840610.mo de.po
LANGUAGE=de_AT.UTF-8 LC_ALL=C ./840610
test
LANGUAGE=de_AT.UTF-8 LC_ALL=C python3 ./840610.py
Traceback (most recent call last):
  File "./840610.py", line 8, in <module>
    print(gettext.dgettext('840610', 'test'))
UnicodeEncodeError: 'ascii' codec can't encode character '\xfc' in position 2: 
ordinal not in range(128)
Makefile:21: recipe for target 'check' failed
make: *** [check] Error 1

You can also play with commands like

strace -E LANGUAGE=de_AT.UTF-8 -E LC_ALL=C -e file ./840610
strace -E LANGUAGE=de_AT.UTF-8 -E LC_ALL=C.UTF-8 -e file ./840610

which show that, if LC_ALL=C exactly, then glibc doesn't even
attempt to open any 840610.mo file.  This is the special case
that was added in glibc 2.2.1 and has not been implemented
in the Python gettext library, as of Python 3.4.2.

#define _GNU_SOURCE 1
#include <errno.h>
#include <error.h>
#include <libintl.h>
#include <locale.h>
#include <stdio.h>

int
main(void)
{
        if (setlocale(LC_ALL, "") == NULL)
                error(1, errno, "setlocale");
        if (bindtextdomain("840610", ".") == NULL)
                error(1, errno, "bindtextdomain");
        if (puts(dgettext("840610", "test")) == EOF)
                error(1, errno, "puts");
        return 0;
}
#! /usr/bin/python3

import locale
import gettext

locale.setlocale(locale.LC_ALL, '')
gettext.bindtextdomain('840610', '.')
print(gettext.dgettext('840610', 'test'))
msgid ""
msgstr ""
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "test"
msgstr "Prüfung"
#! /usr/bin/make -f

PYTHON = python3
CC = gcc
CFLAGS = -Wall -Wextra

all: 840610 de/LC_MESSAGES/840610.mo

clean:
        rm -f 840610
        rm -rf de

840610: 840610.c
        $(CC) $(CFLAGS) -o 840610 840610.c

de/LC_MESSAGES/840610.mo: de.po
        mkdir -p de/LC_MESSAGES
        msgfmt -o de/LC_MESSAGES/840610.mo de.po

check: all
        LANGUAGE=de_AT.UTF-8 LC_ALL=C ./840610
        LANGUAGE=de_AT.UTF-8 LC_ALL=C $(PYTHON) ./840610.py

Reply via email to