Having neither army nor navy, Invariant is apparently just a dialect

by Michael S. Kaplan, published on 2010/03/04 07:01 -05:00, original URI: http://blogs.msdn.com/b/michkap/archive/2010/03/04/9971425.aspx


One of the very first blogs I ever wrote was Where is the locale? "Its Invariant." In where?

All the way back in the end of 2004.

I had maybe ten blogs in this Blog back then, instead of more like 3010 like I have now.

Those were innocent days....

Looking at Windows 7, the locale data for this locale is getting impressive (note the shiny new constants with the same values as many old ones, to assist in consistency and predictability - I'll speak more on this another time):

LCType Value
LOCALE_SLOCALIZEDLANGUAGENAME1,2 Invariant Language
LOCALE_SENGLISHLANGUAGENAME3 Invariant Language
LOCALE_SNATIVELANGUAGENAME4 Invariant Language
LOCALE_SLOCALIZEDCOUNTRYNAME1 Invariant Country
LOCALE_SENGLISHCOUNTRYNAME Invariant Country
LOCALE_SNATIVECOUNTRYNAME Invariant Country
LOCALE_SLOCALIZEDDISPLAYNAME1,5 Invariant Language (Invariant Country)
LOCALE_SENGLISHDISPLAYNAME Invariant Language (Invariant Country)
LOCALE_SNATIVEDISPLAYNAME Invariant Language (Invariant Region)
LOCALE_SABBREVLANGNAME IVL
LOCALE_SABBREVCTRYNAME IVC
LOCALE_SISO639LANGNAME iv
LOCALE_SISO3166CTRYNAME IV
LOCALE_SISO639LANGNAME2 ivl
LOCALE_SISO3166CTRYNAME2 {EMPTY}
LOCALE_IGEOID 2446

Well, we certainly have come a long way.

I mean there is the odd nuance here and there (e.g. the native country name vs. the native display name nominally meant to contain the native country name), but on the whole we now have a fully formed fake locale. It has a language (kind of) and a region/country (kind of). What more could we ask for, really?

Disclaimer: I myself added the first instance of Invariant Country in response to a bug put in related to no return value coming back and a long-ish conversation with the PM on the desired behavior (imagine how much I would enjoy discussing a country that does not exist - not!). But rather than removing it in later versions, they put it in all of other the related fields, so clearly they kept heading down that path rather than not doing so.

So we (by which I mean I) can be perhaps forgiven our (by which I mean my) surprise when the following question came in recently:

An ISV sent me some code which fails under Windows 7, preventing their application from starting. They’re gone into the week-end now and I cannot ask them if it ever ran in Vista, let alone XP...

That said, although I don’t know that much about Globalization related topics, this error message seems clear but I cannot understand why it would fail on Windows 7 and not on XP/Vista.

I should have more information on Monday but meanwhile, I was wondering if you know about any related “breaking” change.

Thanks.

________________________________________
CultureInfo[] cultures=System.Globalization.CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
System.Collections.Generic.List<RegionInfo> r = new System.Collections.Generic.List<RegionInfo>();
foreach (CultureInfo ci in cultures) {
    RegionInfo region = new RegionInfo(ci.LCID);
}
________________________________________
0:000> !pe
Exception object: 01b5d26c
Exception type: System.ArgumentException
Message: There is no region associated with the Invariant Culture (Culture ID: 0x7F).
InnerException: <none>
StackTrace (generated):
    SP       IP       Function
    0042EC24 6575B7BE mscorlib_ni!System.Globalization.RegionInfo..ctor(Int32)+0x2335b2
    0042EC3C 002B971A ISV_Admin!isv.LTP.Admin.OfficeManager.LoadCultureInfo()+0xba
    0042EC60 002B2A1F ISV_Admin!isv.LTP.Admin.OfficeManager..ctor()+0x37
    0042EC6C 002B04CA PAdministrator!isv.LTP.Admin.FrmAdmin.InitializeComponent()+0x2ba
    0042F094 002B01BC PAdministrator!isv.LTP.Admin.FrmAdmin..ctor()+0x14
    0042F0A0 002B00FD PAdministrator!isv.LTP.Admin.Program.Main()+0x8d

StackTraceString: <none>
HResult: 80070057

Hmmm. There is no region associated with the Invariant Culture? Really?

I responded to this saying that as a rule when stuff like this has been coming up in Windows 7 or CLRv4 that it is deemed by the area owners to be by design, even if at times perhaps not expected.

Usually this turned out to be due to the complex efforts to normalize models of behavior that had diverged quite a bit.

The official answer came by soon after my response, confirming this idea I put forth and including the specific reason for this behavior:

The reason that the behavior changed with Win7 is that in Win7, the Invariant Culture is considered to be an installed culture as returned by IsValidLocale(0x7f, LCID_INSTALLED). You can also see this property on the Invariant culture (culture.CultureTypes & CultureTypes.InstalledWin32Cultures).

The Invariant culture is normally included with NeutralCultures enumerations. It is also specifically excluded from SpecificCulture enumerations. However, there is no attempt to remove it from the InstalledWin32Cultures enumeration and since CultureTypes.AllCultures == CultureTypes.NeturalCultures | CultureTypes.SpecificCultures | CultureTypes.InstalledWin32Cultures, the InvariantCulture is showing up as one of the InstalledWin32Cultures.

Hope that helps explain why you are seeing the behavior.

There you have it.

In the managed world it is NEUTRAL despite the fact that it is fully filled in like a specific.

And in the native world it is (startuing in Win7) a SPECIFIC even though in prior versions it was not enumerated at all (which would give someone reason to realize they could have been consistent if they had wanted to).

And they deeemed CultueTypes.InstalledWin32Cultures to be managed way of saying "do some native-ey kind of thing, please!". :-)

Thus in the end, the place that lists a region/country in almost every field where one is indicated is really thought of as not having a country or region.

What was that Yiddish phrase again? Oh yeah! A shprakh iz a dialekt mit an armey un a flot, as I discuss in my updaterd version (A subkultur iz a shprakh mit an armey un a flot).

Clearly, LOCALE_INVARIANT jumped ahead of Yiddish enough to make it in the box, and to have a place in the native (if not the managed) world. :-)

Yet still, lacking a region in the managed world (not to mention lacking both an army and a navy!) I suppose we should think of Invariant as a dialect of English....

 

1 - These are on an English system, so the localized names and english names should be the same. On a localized system they will often be different.
2 - a.k.a. LOCALE_SLANGDISPLAYNAME in versions prior to Windows 7 (new constants to normalize names).
3 - a.k.a. LOCALE_SENGLANGUAGE in versions prior to Windows 7 (new constants to normalize names).
4 - a.k.a. LOCALE_SNATIVELANGNAME in versions prior to Windows 7 (new constants to normalize names).
5 - a.k.a LOCALE_SLANGUAGE in versions prior to Windows 7 (new constants to normalize names).
6 - This is the GEOID value for the United States of America. We don't vary much here, I guess.
7 - Aren't unreferenced footnotes grand?


rs on 4 Mar 2010 9:53 AM:

> I suppose we should think of Invariant as a dialect of English...

I believe you are correct -- according to the table, native Invariants use the same words for "Invariant", "Language", "Country", "Region".


Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

referenced by

2011/07/11 Only ask the question if you have the cache to spend on the answer

go to newer or older post, or back to index or month or day