localize() in inkex.py ignores $LANG from current env on Windows

Bug #1666108 reported by su_v
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Inkscape
New
Undecided
Unassigned

Bug Description

The localize() function in inkex.py to initialize gettext for messages returned by extension scripts seems to ignore $LANG from the current environment on Windows, and overwrites the environment variable with the locale apparently retrieved from the system settings:

        import locale
        current_locale, encoding = locale.getdefaultlocale()
        os.environ['LANG'] = current_locale

Tested on Windows 10:

1) set LANG in the CMD shell before launching inkscape:

C:\Users\su_v\Programs\inkscape> set LANG=de_CH
C:\Users\su_v\Programs\inkscape> inkscape

--> Inkscape's GUI shows with German localization as expected.

2) Launch a second Inkscape instance from within inkscape [*]:

--> GUI language and locale of second instance falls back to en_US (like the system settings).

Reproduced with Inkscape 0.91 (32bit, 64bit), 0.92.1 (32bit, 64bit) and inkscape_trunk_r15113 (64bit) on Windows 10, all versions installed from 7z into custom location and launched from CMD shell.

Notes:
* See also the lengthy discussion in bug #1662531 about the crash of the second inkscape instance (reported separately in bug #1663697 as well) for another issue related to localize() on Windows and a proposed improvement attached in comment https://bugs.launchpad.net/inkscape/+bug/1662531/comments/64
* Possibly locale.getdefaultlocale() was designed to work differently on Windows compared to other platforms, but it sort of feels unexpected (at least to me):
1) set LANG in CMD shell to a locale different from system settings
2) launch python\python.exe as bundled with Inkscape on Windows
3) import os, locale
3) print os.environ['LANG']
4) print locale.getdefaultlocale()
It seems that Python's locale module on Windows ignores LANG from the environment (unlike e.g. python on OS X, and unlike Inkscape itself).
Python documentation:
https://docs.python.org/2/library/locale.html#locale.getdefaultlocale

=====
[*] debug extension to spawn second Inkscape instance:
    https://gitlab.com/su-v/lp1662531

Revision history for this message
su_v (suv-lp) wrote :

Why is it necessary to change $LANG in the environment on Windows at all? A quick test with 0.92.1 r15371 (64bit, 7z) on Windows 10 shows translated error messages from extensions even if line 57 is commented out:

        # os.environ['LANG'] = current_locale

https://bazaar.launchpad.net/~inkscape.dev/inkscape/0.92.x/view/15371/share/extensions/inkex.py#L57

@jazzynico - do you happen to remember why you had to add it for translations of messages from extensions scripts on Windows?

Revision history for this message
Patrick Storz (ede123) wrote :

Is $LANG set on Windows at all? I don't think so...

Therefore if the parent Inkscape process does not set it, it will be unset. Maybe that's why we try to set it manually there?

Revision history for this message
Patrick Storz (ede123) wrote :

P.S. That's probably also the reason why Python ignores the variable on Windows.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.