[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pnet-developers] [bug] Thread.CurrentThread.CurrentUICulture has no eff
From: |
Bruno Haible |
Subject: |
[Pnet-developers] [bug] Thread.CurrentThread.CurrentUICulture has no effect on ResourceManager |
Date: |
Thu, 18 Dec 2003 15:38:59 +0100 |
User-agent: |
KMail/1.5 |
Using pnet-0.6.0.
The MS documentation says:
- About ResourceManager:
"... GetString methods. By default, these methods return the resource for
the culture determined by the current cultural settings of the thread that
made the call. (See Thread.CurrentUICulture for more information.)"
- About Thread.CurrentUICulture:
"Gets or sets the current culture used by the Resource Manager to look up
culture-specific resources at run time."
- About Culture.CurrentUICulture:
"Gets the CultureInfo that represents the current culture used by the
Resource Manager to look up culture-specific resources at run time. ...
The culture is a property of the executing thread. This property returns
Thread.CurrentUICulture."
From this one can conclude that changing Thread.CurrentUICulture should
have an effect on the ResourceManager's GetString calls. Test case:
============================= hello.cs ===========================
using System;
using System.Threading;
using System.Resources;
using System.Globalization;
using System.Reflection;
class Hello {
static void OutputIn(string locale) {
Thread.CurrentThread.CurrentUICulture = new CultureInfo(locale);
ResourceManager rm =
new ResourceManager("hello", Assembly.GetExecutingAssembly());
Console.WriteLine(rm.GetString("Hello World!"));
}
static void Main() {
OutputIn("fr-FR");
OutputIn("de-DE");
}
}
========================== hello.resx ==============================
<?xml version="1.0" encoding="utf-8" ?>
<root>
<resheader name="ResMimeType">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="Version">
<value>1.0.0.0</value>
</resheader>
<resheader name="Reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms,
Version=1.0.3102.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="Writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms,
Version=1.0.3102.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Hello World!">
<value>Hello World!</value>
</data>
</root>
========================== hello.de.resx ===========================
<?xml version="1.0" encoding="utf-8" ?>
<root>
<resheader name="ResMimeType">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="Version">
<value>1.0.0.0</value>
</resheader>
<resheader name="Reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms,
Version=1.0.3102.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="Writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms,
Version=1.0.3102.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Hello World!">
<value>Hallo Welt!</value>
</data>
</root>
====================================================================
$ resgen hello.resx hello.resources
$ resgen hello.de.resx hello.de.resources
$ cscc -fresources=hello.resources -fresources=hello.de.resources hello.cs -o
hello.exe
$ LANG=C ilrun hello.exe
Hello World!
Hello World!
Expected:
$ LANG=C ilrun hello.exe
Hello World!
Hallo Welt!
The reasons are:
1) ResourceManager uses CultureInfo.CurrentCulture, but it should use
CultureInfo.CurrentUICulture instead.
2) The CultureInfo.CurrentCulture and CultureInfo.CurrentUICulture getters
should make an indirection to the Thread.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pnet-developers] [bug] Thread.CurrentThread.CurrentUICulture has no effect on ResourceManager,
Bruno Haible <=