Search code examples
c#windowsmonogettextgtk#

Mono C# Set CultureInfo not working on Windows


I'm currently facing a bug, that the language of my application can not be set to something different than system default. I use the following Code to set the CultureInfo:

Catalog.Init("AudioCuesheetEditor", Path.GetFullPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + MainClass.CONST_STR_LOCALE_PATH));
[...]
//Set the locale
log.debug("CultureInfo.CurrentCulture = " + CultureInfo.CurrentCulture);
if (Program.getInstance().getObjOption().getStrSelectedLanguage() != null)
{
    log.debug("Program.getInstance().getObjOption().getStrSelectedLanguage() = " + Program.getInstance().getObjOption().getStrSelectedLanguage());
    Thread.CurrentThread.CurrentCulture = new CultureInfo(Program.getInstance().getObjOption().getStrSelectedLanguage());
    if (Environment.OSVersion.Platform == PlatformID.Unix)
    {
        //Mono Linux hack
        Environment.SetEnvironmentVariable("LANGUAGE", Program.getInstance().getObjOption().getStrSelectedLanguage().Replace("-", "_"));
    }
}
Application.Init();
[...]
Application.Run();

This works perfect on linux, but doesn't work with gtk# on Windows. The CultureInfo is changed, but the language doesn't change. Any ideas why?

I get the string with Code like this:

Catalog.GetString("general ready")

I'm not shure, how to find the bug and what is wrong. Anybody who can help, thanks in advance ;).

Whole code can be found here: http://sourceforge.net/p/audiocuesheet/code/HEAD/tree/trunk/src/AudioCuesheetEditor/MainClass.cs

Sven


Solution

  • I found out, that changing the environment variable "LANG" on windows works. So if I set "LANG=en" the application starts with english translation.