简体   繁体   中英

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

Since internationalization is based on GNU gettext, my assuption would be that the windows implementation slightly differs form the unix one, so the LANGUAGE variable is read at startup before any of your code is executed. The only work around I can think of is to call your program with a script that sets the LANGUAGE variable.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM