After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 675554 - language environment variables (LANG, LANGUAGE, etc.) are always overridden in Windows.
language environment variables (LANG, LANGUAGE, etc.) are always overridden i...
Status: RESOLVED FIXED
Product: GIMP
Classification: Other
Component: General
2.8.0
Other Windows
: Normal normal
: 2.8
Assigned To: Jehan
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2012-05-06 08:21 UTC by sylvie.alexandre
Modified: 2013-10-19 13:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch for the LANG environment variable (22.38 KB, patch)
2013-01-18 08:35 UTC, Pavel
needs-work Details | Review
Set the UI language using LANG environment variable (1.20 KB, patch)
2013-01-18 14:53 UTC, Pavel
none Details | Review
Remove outdated code (22.49 KB, patch)
2013-10-06 13:04 UTC, Jehan
none Details | Review
Do not let Windows default UI lang override locale's UI language if explicitly set. (1019 bytes, patch)
2013-10-07 11:20 UTC, Jehan
none Details | Review

Description sylvie.alexandre 2012-05-06 08:21:06 UTC
The LANG environment variable does not work in Windows.
O.S = Windows 7 64-bit
Gimp versions = 2.7.x  /  2.8.0 RC1  /  2.8.0 (SourceForge & Partha).

Note: 
This variable works well with 
- Linux Gimp 2.8.0
- Windows Gimp 2.6.x

Thank you.
Comment 1 Jernej Simončič 2012-05-06 08:36:43 UTC
Can't confirm - works fine here (setting LANG even overrides the language set in Preferences for me, which IMHO is a bug).
Comment 2 sylvie.alexandre 2012-05-06 09:18:21 UTC
Bonjour,

I did a test on another computer with Windows 7 32-bit.
The problem is the same:
- The LANG environment variable works with Gimp 2.6.12 SourceForge
- This variable does not work with Gimp 2.8.0 SourceForge.

Thank you.
Comment 3 Massimo 2012-05-08 11:15:30 UTC
LANG is not the only environment variable that is checked.

You should check that if any of: LC_ALL, LC_MESSAGES, LC_CTYPE or
LANGUAGE, is set, it is set to the same value as your desired LANG.

Different subsytems check these variables with different priorities.
Comment 4 sylvie.alexandre 2012-05-08 11:55:32 UTC
Bonjour,

O.S. = Windows 7 64-bit (french)
Tests of 4 environmental variables (value = en)


Tests : LC_ALL / LC_MESSAGES / LANGUAGE

 - Works with Gimp 2.6.10 64bit SourceForge
 - Works with Gimp 2.6.12 SourceForge
 - Does not work with Gimp 2.8.0 (32bit & 64bit) SourceForge.
 - Does not work with Gimp 2.7.6 (32bit & 64bit) Partha.


Tests : LC_CTYPE
 - Does not work with all versions of Gimp tested


Thank you
Comment 5 Massimo 2012-05-08 16:46:30 UTC
If I understand correctly, you want to see english menus etc
on a computer with settings defaulting to french.

In gimp-2.8 you should select "English [en_US]" from the list
under Languages in the preferences dialog. 

That is, from the menu Edit->Preferences, you choose Interface
on the list to the left, and in Languages the language of 
your choice.

Doesn't work that way? 

And when you say it doesn't work, do you mean all menus are 
in french?
Comment 6 Michael Schumacher 2012-05-08 16:59:53 UTC
That is impractical if you want to start GIMP in several different languages - it would t least be good to know whether the environment handling has been removed, or if it is just broken.
Comment 7 Massimo 2012-05-08 17:46:59 UTC
Is it broken? at first I thought that perhaps the environment
contained an env var shadowing LANG, because Jernej said it is working
for him, and because the code does not show anything particularly suspect

Does it work for you? What exactly doesn't work?

The environment handling in Windows is problematic because
msvcrt does not care about it, and so every lib is somewhat wrapping
the locale initialization to honour this settings, but it is possible
that somewhere something is wrong.
Comment 8 Michael Schumacher 2012-05-08 21:05:03 UTC
set LANG=hfr
gimp-2.8.exe

This used to set the language to French (and probably some other locale-dependent stuff, too, but I never cared).

However, when playing around , I noticed the following:

set LANG=he
gimp-2.8.exe

uses the translations' language set in the preference, but switches to RTL mode nevertheless.

So it could be that the environment variable is taken into account, but (partially) overruled by the preference setting...
Comment 9 sylvie.alexandre 2012-05-08 22:49:01 UTC
(In reply to comment #5)
> If I understand correctly, you want to see english menus etc
> on a computer with settings defaulting to french.
> 
> In gimp-2.8 you should select "English [en_US]" from the list
> under Languages in the preferences dialog. 
> 
> That is, from the menu Edit->Preferences, you choose Interface
> on the list to the left, and in Languages the language of 
> your choice.
> 

> Doesn't work that way? 
Yes, it's working correctly via the preferences menu.

> 
> And when you say it doesn't work, do you mean all menus are 
> in french?
Yes.


Bonjour,

After several attempts with Gimp 2.8 I note that the positioning via the "preferences" menu always has priority. 
The operating environment variables is inhibited:
- Either the positioning via the Control Panel.
- By using a file .bat 
set LANG=en
start gimp-2.8.exe

Thank you.
Comment 10 Massimo 2012-05-09 16:17:12 UTC
Yes, setting the language via env vars is broken, at least on Win7 64 bits.

Anyway, to start GIMP in several different languages with a     
double click on a desktop icon it is enough to start GIMP passing
on the command line --gimprc="gimprc file with language of choice"

That is, I created in my .gimp-2.8 dir a file "gimprc.en" whose content is:

# GIMP gimprc.en

(language "en")

# end of gimprc


a file "GIMP in english.bat" whose content is:

start /D"%ProgramFiles%\GIMP 2\bin" gimp-2.8.exe --gimprc="%HOMEDRIVE%\%HOMEPATH%\.gimp-2.8\gimprc.en"


and a link on the desktop pointing to the bat file for which I could choose             
an icon from gimp-2.8.exe (but it would be better to draw a new icon 
with Wilber in foreground and the union jack in background)

and double clicking on this link starts GIMP with english translations.

I tried Gaussian blur filter and it shows english translations.

English, French, Italian, are 'left to right' langauges, so it is still possible
that text direction is coming from the system settings.
Comment 11 sylvie.alexandre 2012-05-09 21:34:41 UTC
(In reply to comment #10)
> Yes, setting the language via env vars is broken, at least on Win7 64 bits.
> 
> Anyway, to start GIMP in several different languages with a     
> double click on a desktop icon it is enough to start GIMP passing
> on the command line --gimprc="gimprc file with language of choice"
> 
> That is, I created in my .gimp-2.8 dir a file "gimprc.en" whose content is:
> 
> # GIMP gimprc.en
> 
> (language "en")
> 
> # end of gimprc
> 
> 
> a file "GIMP in english.bat" whose content is:
> 
> start /D"%ProgramFiles%\GIMP 2\bin" gimp-2.8.exe
> --gimprc="%HOMEDRIVE%\%HOMEPATH%\.gimp-2.8\gimprc.en"
> 
> 
> and a link on the desktop pointing to the bat file for which I could choose     
> an icon from gimp-2.8.exe (but it would be better to draw a new icon 
> with Wilber in foreground and the union jack in background)
> 
> and double clicking on this link starts GIMP with english translations.
> 
> I tried Gaussian blur filter and it shows english translations.
> 
> English, French, Italian, are 'left to right' langauges, so it is still
> possible
> that text direction is coming from the system settings.


Bonjour,

Thank you for research and solution.
I hope the operation by environment variable will be restored because it is very useful when you have many versions of Gimp on a computer.
Cordially.
Comment 12 Pavel 2013-01-18 08:32:59 UTC
Although I don't fully understand the need for this environment variable, when setting the language via Preferences works fine, the patch is pretty simple. I'll attach the modified language.c file for review. With this patch the language is selected using the Preferences, however, if the environment variable LANG exists (either in the user or in the system profile), it will override the language from Gimp preferences.
Comment 13 Pavel 2013-01-18 08:35:49 UTC
Created attachment 233733 [details] [review]
Patch for the LANG environment variable

The patch is just before the end of "#ifdef G_OS_WIN32" directive. I am only not sure whether envlang does not need to be freed.
Comment 14 Jernej Simončič 2013-01-18 09:14:27 UTC
I still think that Preferences should have absolute priority - if you want to use environment, set that to "System language", but do not override any other choice.

Typical GIMP user does not know about environment variables, and if LANG is set for some reason on his system (I have seen installers do that), he should be able to override it through the Preferences setting, not by having to poke around Control Panel (where he may not even have permission to change the variable, if it's set on system level).
Comment 15 Michael Natterer 2013-01-18 09:19:51 UTC
Comment on attachment 233733 [details] [review]
Patch for the LANG environment variable

Pavel, please attach a patch, not the entirel file.
Comment 16 Michael Schumacher 2013-01-18 14:23:11 UTC
Is this now effectively back to the way it was before the language selector was there? 

I definitely want support for this back, but I'm not sure if "Although I don't fully understand the need for this environment variable" is a good base for a patch :)

Pavel, how many and what tests did you run?
Comment 17 Pavel 2013-01-18 14:28:07 UTC
(In reply to comment #14)
> I still think that Preferences should have absolute priority - if you want to
> use environment, set that to "System language", but do not override any other
> choice.
> 
> Typical GIMP user does not know about environment variables, and if LANG is set
> for some reason on his system (I have seen installers do that), he should be
> able to override it through the Preferences setting, not by having to poke
> around Control Panel (where he may not even have permission to change the
> variable, if it's set on system level).

Yes, I understand. I'll try to post a patch fulfilling this requirement, as
soon as I manage to create one.
Comment 18 Pavel 2013-01-18 14:37:56 UTC
Michael, I tested it on Windows XP SP3. The patch is so simple that I believe it will work on other systems too. As long as the function g_getenv works properly.
Comment 19 Pavel 2013-01-18 14:53:21 UTC
Created attachment 233761 [details] [review]
Set the UI language using LANG environment variable

The patch follows Jernej's idea now - if the UI language in Gimp preferences is set to System Default, the LANG environment variable is used to set the UI language, if it exists. If the preference language is set to anything else than System Default, then LANG environment variable is ignored.
Comment 20 Michael Schumacher 2013-01-25 21:19:04 UTC
I'm not sure if this is complete.

Is your patch really how it was before the language could be set via the UI? 

What about LANGUAGE, for example? See http://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html
Comment 21 Pavel 2013-01-26 19:10:40 UTC
I think the best is to test it. Basically all environment variables are overridden by preference on all platforms. Then only on Windows and if the language is not set by preferences, the patch searches for the LANG environment variable, nothing else. If it finds it, it uses it and finishes setting the language. If there is no LANG environment variable, it runs the hack to find the user default UI language - this part was already in the code. So I believe the logic is OK.

The only thing I am not sure about is whether the variable got through g_getenv should be freed or not.
Comment 22 Jehan 2013-10-06 13:01:31 UTC
Hi,

thanks for the patch, but I think that's not the right fix.
The right fix would be to remove the whole bunch of FIXME code in there, which was overriding the environment variables on Windows and doing some complicated but useless stuff. :-)

The comment in our current codebase claims that gettext can't pick the right language in Windows. Well this may have been true in some old version of Windows, or maybe with some specific implementation we may have had in the past, but from my test 2 minutes ago, that's not true anymore with our current implementation and Windows 7. :-)

The link in the comment seems also completely unrelated and/or outdated. It discusses about using GetLocaleInfo(). But that's not the way to set the language, and fortunately that's not what we do anyway. We do it with setlocale (LC_ALL, "");
This is the portable way. So whatever this link says, it should not impact our code. :p

Also to confirm with documentation too, I checked Microsoft docs. It says here, on setlocale docs that the portable way is supposed to work: http://msdn.microsoft.com/en-us/library/x99tb11d%28v=vs.90%29.aspx
«
setlocale( LC_ALL, "" );

    Sets the locale to the default, which is the user-default ANSI code page obtained from the operating system.
»

Now it seems Windows' API may be compliant since Windows XP/2000 and above: http://msdn.microsoft.com/en-us/library/sk54f3f5%28v=vs.90%29.aspx

Maybe this old outdated code was meant for Windows 98 or older? I can't test, I don't have such OS. But I would say that we should not care for that old OS, should we?

So I have tested. By removing this outdated specific Windows code, setting LANG, LANGUAGE, (or other common env variable) now works (provided there is no language settings in gimprc of course). And not setting it, the OS language is used (my Windows is in Korean, and GIMP started in Korean by default, as usual).
Comment 23 Jehan 2013-10-06 13:04:49 UTC
Created attachment 256571 [details] [review]
Remove outdated code

And the patch!
Comment 24 Jernej Simončič 2013-10-06 18:53:21 UTC
Are you confusing the locale settings and UI language? Because if my Windows UI language is English, but locale (date/time, currency etc.) is Slovenian, GIMP should default to English UI, and not to Slovenian one (which it does if we let gettext do the choosing).
Comment 25 Jehan 2013-10-07 01:38:54 UTC
Hi,

I don't think I confuse them. Locales and UI languages are completely linked.
There is not 1 locale. Locales are a set of several values.
There is indeed 1 for time (LC_TIME), 1 for currency (LC_MONETARY), many others, and finally the language of the UI (LANG and LANGUAGE).

See http://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html#The-LANGUAGE-variable

What it means is that you can perfectly have a system with text in Slovenian but time in English format, etc. Locales are a set, and you can mix the settings however you like.

Now Windows is probably particular, since they don't rely on these locales as a base. They have settings elsewhere. But it's ok since the Windows' setlocale() API will check these settings if there is no locale variable set. So it is all good. The variable will be used and override the globale OS lang only if they exist. Exactly what the users want in this ticket.

setlocale() and gettext are supposed to take care of all these details. We should not have to do specifics if possible and add any logics ourselves (this logics was broken, and the previous patch was trying to make a new workaround to an existing broken workaround, getting the OS logics even further apart). Maybe a long time ago, these calls were broken on Windows, no idea. But now they are working well on Windows 7, at least (which means hopefully any earlier Windows too).
Comment 26 Jernej Simončič 2013-10-07 06:25:45 UTC
> I don't think I confuse them. Locales and UI languages are completely linked.

Not really - the settings are completely separate

> What it means is that you can perfectly have a system with text in Slovenian
> but time in English format, etc. Locales are a set, and you can mix the
> settings however you like.

Exactly. And if my UI language is English, but other locale settings are Slovenian, GIMP should respect that, and appear in English by default. The code you're trying to remove was added specifically to address this problem in GIMP 2.8 - it wasn't present before, and we had users complaining that GIMP appeared in wrong language.

While overriding environment variables is an unfortunate side-effect, IMHO this is less problematic than using the wrong language by default simply because as you said, Windows does not rely on environment variables for these settings. For users that want a different language, they can change that through Preferences.
Comment 27 Jehan 2013-10-07 06:52:27 UTC
Hi,

> Not really - the settings are completely separate

Yes but Windows implementation of setlocale() apparently still supports both: Windows settings for language and the environment variable. At least according to what I understand from the official Microsoft doc and various links I found, and from my tests. And that's what matters.
At least since Windows 2000, it would seem (again if I get the doc correctly).

> Exactly. And if my UI language is English, but other locale settings are Slovenian, GIMP should respect that, and appear in English by default.

Have your tried lately with the removed code? Here it worked well. My Windows 7 is Korean and I got a Korean GIMP by default.
I see the commit which added this was in mid-2011. Maybe Windows evolved since then? Anyway on my unique test here, it seemed to work very well without this code.

Now I don't have other than Windows 7, and I don't seem to change the language (seems you need Windows Ultimate or Enterprise edition to be able to do so). So I can't test much more variants.

> The code you're trying to remove was added specifically to address this problem in GIMP 2.8 - it wasn't present before, and we had users complaining that GIMP appeared in wrong language.

Do you know which language and which Windows OS they were using, by any chance?

> While overriding environment variables is an unfortunate side-effect, IMHO this is less problematic than using the wrong language by default simply because as you said, Windows does not rely on environment variables for these settings.
> For users that want a different language, they can change that through
Preferences.

I know, but there are apparently use cases for this. As Michael Schumacher said above, the preferences are impractical for people who want to start GIMP in various languages (it implies going in menus, a GIMP restart, ec.).
I don't see why we could not have it all on Windows: good default, preferences through UI, and environment variables. After all, we have such on Linux.

Anyway I don't say your code is wrong. Just I am trying to understand when it is useful, on which exact platform, or maybe for some specific problematic languages. Because my tests show very different results to your statement. But that's a very limited test (Windows 7/Korean), so I definitely won't exclude that it may be a problem somewhere else.
Comment 28 Jehan 2013-10-07 11:20:50 UTC
Created attachment 256618 [details] [review]
Do not let Windows default UI lang override locale's UI language if explicitly set.

Ok after discussing with ender on IRC, it seems the main problem was that setlocale() would use this "Language for non-unicode programs" setting if it is set to something different than the main OS language. I don't really understand what this setting is for, but apparently it should not be used for UI localization, according to the linked msdn blog. Anyway there are so many inconsistencies and bad design in this Windows API. I will not care much more, so let's keep this code, why not. That's still a bad idea to keep a list on our own, which will be necessarily a hell to maintain.

So here is another fix to the current issue. We still don't want to just check LANG and return earlier, because it would be a wrong re-implementation to gettext language selection.
See this page for more info on the algorithm: http://www.gnu.org/software/gettext/manual/html_node/Locale-Environment-Variables.html#Locale-Environment-Variables
Basically it would search LANGUAGE, LC_ALL, LC_MESSAGES and LANG (in this order). And in any case, it any one of these env variables were present, the system would already be properly localized. No need to re-run setlocale (LC_ALL, ""); and certainly not to set the LANGUAGE variable to the LANG value ourself.
Comment 29 Jehan 2013-10-09 08:01:26 UTC
As I think the last patch does suit everyone, could any Windows user test it too? :-)
Comment 30 Jehan 2013-10-15 02:28:50 UTC
Ok,

I felt that maybe potential testers could need some binaries to speed this up. :-)
I've uploaded a zip file containing my own cross-compiled build or master babl/gegl/gimp + this small patch here: http://girinstud.io/up/w64.zip

I won't keep this file up for long though, because it is 119 Mo, and I don't want users to download it at will from this link, as though it was an official build. It is a development build, with minimal options.

Basically you can see that the language detection works same as before if GIMP is set in System Language. But now it can also be overridden by LANGUAGE, LC_ALL, LC_MESSAGES or LANG.
Of course if you set a language other than System Language in the preferences, these environment variables have no effect anymore.
Comment 31 sylvie.alexandre 2013-10-15 08:59:08 UTC
(In reply to comment #30)
Bonjour,

Thank you for the correction.
I downloaded "w64.zip" to test your nodifications.
I will make a new post with my results.

Bonne journée, merci.
Comment 32 sylvie.alexandre 2013-10-15 09:53:23 UTC
(In reply to comment #30)

Bonjour,

About version "w64.zip" :

My tests are good, thank you for your work :o)

My tests are done with :  Windows 8 Pro 64 bit  - Language = French

- By clicking "gimp-2.9.exe" -> Gimp is in French


- By clicking "gimp_en.bat" -> Gimp is in English 
Contents of the "gimp_en.bat" file :
set lang=en
start gimp-2.9.exe


- By clicking "gimp_es.bat" -> Gimp is in Spanish
Contents of the "gimp_es.bat" file :
set lang=es
start gimp-2.9.exe


- Activating the system variable "lang" environment through control panel (value lang = de)  :
By clicking "gimp-2.9.exe" -> Gimp is German
By clicking "gimp_en.bat" -> Gimp is in English 
By clicking "gimp_es.bat" -> Gimp is in Spanish


- Activating the user variable "lang" environment through control panel (value lang = it)  :
By clicking "gimp-2.9.exe" -> Gimp is Italian
By clicking "gimp_en.bat" -> Gimp is in English 
By clicking "gimp_es.bat" -> Gimp is in Spanish


- The preference setting has priority.


*****

Note: The user directory of Gimp is "C:\Users\[user]\AppData\Roaming\GIMP\2.9"
Comment 33 Jehan 2013-10-15 11:12:31 UTC
Bonjour Sylvie,

Thanks for checking. I'll push this then, and will also backport to GIMP 2.8, so that the next bugfix release for 2.8 will have the fix too.

I would also advise to not keep this development version for daily usage. There would be a lot of unfixed issue there. :-) Hopefully the next bugfix stable release should not be too long to arrive anyway.

About the note: yes the user directory will move for the next major release because it has been considered more consistent to the Windows os for the data to be in the roaming application data folder.
Comment 34 Jehan 2013-10-15 11:35:09 UTC
Author: Jehan <jehan@girinstud.io>
Date:   Tue Oct 8 00:17:56 2013 +1300

    Bug 675554 - fix overriden language environment variables on Windows.
    
    If any of the locale environment variables used for UI language is set
    (LANGUAGE, LC_ALL, LC_MESSAGES and LANG), do not let Windows' default UI
    language override these.
    Language set in GIMP preferences still have higher priority.
Comment 35 sylvie.alexandre 2013-10-19 13:20:53 UTC
Bonjour,

My tests are good with Gimp 2.8.7 64bit Windows.

Environment:
Windows 8.1 Pro. 64-bit
Gimp 2.8.7 64bit compilation on Windows with Mingw-w64 and GCC 4.8.1

Thank you :o)