Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Internationalization / January 2007

Tip: Looking for answers? Try searching our database.

Where does Thread.CurrentThread.CurrentUICulture get its initial value from?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Scott Hermes - 18 Jan 2007 17:21 GMT
Hi,

Where does Thread.CurrentThread.CurrentUICulture get its intial value
from and how can I view or change that value without using .NET?

I recently had a web service that was reading the
Thread.CurrentThread.CurrentUICulture.LCID and using that value to
perform some look ups. On my last deploy to QA, it failed because the
Thread.CurrentThread.CurrentUICulture.LCID had changed from 1033
(en-US) to 9 (en). I patched over the problem by explicitly setting the
uiCulture in the web.config

  <globalization culture="en-US" uiCulture="en-US" />

This has solved my problem but I am still curious what changed in the
environment to cause this value to change. I have been trying to
determine where Thread.CurrentThread.CurrentUICulture gets its initial
value from. I think the answer is the UI Culture is selected when the
OS is installed. This web service is running on Windows 2003 so MUI is
not available.

This is the most definitive resource that I have found to date:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cp
conusingcurrentuicultureproperty.asp


Implicitly Setting the CurrentUICulture Property
If the CurrentUICulture property is not set explicitly in an
application's code, it is set by default when the application starts.
It is set by the GetUserDefaultUILanguage function on Windows 2000 and
Windows XP Multilingual User Interface (MUI) products where the end
user can set their UI language. If the user's UI language is not set,
it will be set by the system-installed language, which is the language
of the operating system's resources.

I wrote a small console application to interrogate the likely suspects
and they all returned en-US or 1033.

Thanks,

Scott

PS Here is a copy of the program that I ran

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Runtime.InteropServices;

namespace ConsoleThread
{
   class Program
   {
       [DllImport("kernel32.dll", SetLastError = true)]
       static extern int GetUserDefaultLCID();

       [DllImport("kernel32.dll", SetLastError = true)]
       static extern int GetThreadLocale();

       [DllImport("kernel32.dll", SetLastError = true)]
       static extern short GetSystemDefaultLangID();

       [DllImport("kernel32.dll", SetLastError = true)]
       static extern short GetUserDefaultUILanguage();

       [DllImport("kernel32.dll", SetLastError = true)]
       static extern short GetSystemDefaultUILanguage();

       static void Main(string[] args)
       {
           int lcid = GetUserDefaultLCID();
           short systemLcid = GetSystemDefaultLangID();
           short defaultUIlanguage = GetUserDefaultUILanguage();
           short systemDefaultUiLanguage =
GetSystemDefaultUILanguage();
           int threadLocale = GetThreadLocale();

           Console.WriteLine(".Net
Methods\n----------------------------");
           Console.WriteLine("(installed)
System.Globalization.CultureInfo.InstalledUICulture = {0}",
System.Globalization.CultureInfo.InstalledUICulture.Name);
           Console.WriteLine("(installed)
System.Globalization.CultureInfo.InstalledUICulture.LCID = {0}",
System.Globalization.CultureInfo.InstalledUICulture.LCID);
           System.Console.WriteLine("Thread UI Culture Name = {0}",
Thread.CurrentThread.CurrentUICulture.Name);
           System.Console.WriteLine("Thread  UI Culture LCID = {0}",
Thread.CurrentThread.CurrentUICulture.LCID);
           Console.WriteLine("\nWin 32
Methods\n----------------------------");
           Console.WriteLine("GetUserDefaultLCID = {0}", lcid);
           Console.WriteLine("GetThreadLocale = {0}", threadLocale);
           Console.WriteLine("GetUserDefaultUILanguage = {0}",
defaultUIlanguage);
           Console.WriteLine("(installed) GetSystemDefaultLangID =
{0}", systemLcid);
           Console.WriteLine("(installed) systemDefaultUiLanguage =
{0}", systemDefaultUiLanguage);
           Console.Read();
       }
   }
}
Aldo Donetti [MS] - 25 Jan 2007 01:04 GMT
Hi Scott, I really don't think the UI LCID can be changed.
Also, MUI is available on Windows 2003 and I suspect that's your case -
http://www.microsoft.com/globaldev/DrIntl/faqs/MUIFaq.mspx.
If I may, I suggest you check the logic of your lookup because you are
looking for English resources assuming that the LCID of the UI is 1033 (==
English US). In any case should expect a UICulture to be neutral (e.g. "en"
or "it", not necessarily specific e.g. "en-US" or "it-IT")

Aldo

-- This posting is provided "AS IS" with no warranties, and confers no
rights.

--------------------
| From: "Scott Hermes" <scotthermes@gmail.com>
| Newsgroups: microsoft.public.dotnet.internationalization
| Subject: Where does Thread.CurrentThread.CurrentUICulture get its initial
value from?
| Date: 18 Jan 2007 09:21:00 -0800
| |
[quoted text clipped - 20 lines]
|
| This is the most definitive resource that I have found to date:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconusingcurrentuicultureproperty.asp

| Implicitly Setting the CurrentUICulture Property
| If the CurrentUICulture property is not set explicitly in an
[quoted text clipped - 74 lines]
|     }
| }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.