Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the Windows locale ID (LCID) the same as the USB language ID?

I am developing a tool in C# which allows the user to configure the USB string descriptors for a USB device. One of the string descriptor is the language ID. I want the UI to display the list of language names instead of the cryptic language IDs. I could not find any API which would get me the USB {language ID - Language name} map.

When I looked at Windows locale ID (LCID), the LCID and usb language ID seems to be the same (inference from few entries that I compared).

So, my questions are

  1. Is LCID and USB language ID same?
  2. If yes to (1), are there any pitfalls in using it?
like image 702
Palladin Avatar asked Mar 15 '13 05:03

Palladin


1 Answers

They are indeed closely related, but they are not exactly the same.

According to the documentation linked by Ankur:

the LanguageID parameter specifies the language ID (the same values are used as in Microsoft Win32 LANGID values).

A LANGID value forms part of a Win32 LCID value. You can see this by studying the documentation for LCIDs:

Each locale has a unique identifier, a 32-bit value that consists of a language identifier and a sort order identifier.

So the two values are not completely interchangeable. By varying the sort order identifier (the other part of an LCID value), you can end up with multiple LCID values that all represent the same language (i.e., have the same LANGID).

Treating the two as equivalent might work most of the time (which explains the results of your visual inspection), but it might also break. I would advise not relying on assumptions and doing the bit of extra work required to ensure that you're consistent with the documentation and your code is robust.

The Win32 SDK headers provide a handful of macros to help you interconvert between LCIDs and LANGIDs. You can look these up in the headers and convert them to C# helper functions. The ones you are interested in here are:

  • The MAKELCID macro accepts a language identifier (LANGID) and a sort order identifier, and combines them to generate an LCID. Since you don't care about the sort order identifier, you can use SORT_DEFAULT for this to indicate the default sort order for that language.

  • The LANGIDFROMLCID macro, which extracts a language identifier (LANGID) from an LCID value.

Using one of these helper functions will ensure that you get valid results when you call one of the NLS APIs that accept an LCID parameter.

like image 102
Cody Gray Avatar answered Oct 22 '22 09:10

Cody Gray