Programmatically finding the current language/culture of ArcMap

3007
4
11-18-2011 07:46 AM
DenisRoose1
New Contributor II
In ArcGIS 10, users can select in which language they want the ArcMap interface to be displayed: English, French, Spanish, Chinese, etc.

As an ArcObjects developer, how do I programmatically determine what is the language and culture (date, number formats, abbreviations for cardinal directions, etc.) currently in use by ArcMap? What's the interface to use? It should be easy but... I can't find it. I would have expected to find it as a member of ESRI.ArcGIS.RuntimeManager.ActiveRuntime, but apparently it's not there. It doesn't seem to be in the ArcMapUI namespace either.

I am looking for the equivalent to .NET's System.Globalization.CultureInfo.CurrentCulture.EnglishName (& other such cultural properties). The PC culture can be different from that of ArcMap.

Thanks,
Dennis
0 Kudos
4 Replies
AlexanderGray
Occasional Contributor III
The registry key "HKEY_CURRENT_USER\Software\ESRI\UILANGID." has this information.  This causes some grief because I use standard .NET resources and resources.fr.  In ArcGIS 10, the process keeps the culture of regional setting but uses the language of the registry key.  This is great for an application that needs to be switchable without changing the regional setting and affect other applications (as is our case.)  On the other hand, it is difficult to predict when our code gets first used. In the extensions, commands and other components registered to be started by the ArcGIS application, you have to check if the uiculture of the process has been set to the same language as ArcMap, so .net can load your resources correctly.  Then the question is do you really want to check the registry each time...  You can alter the resources's code file, but it is auto-generated so any change there gets quickly overwritten.  You can make your own resource manager.   You can also make your own static uiculture checker/setter class.

This leads to some convoluted code but is workable.  In ArcGIS 9.3 it was worse because some strings used the regional settings, which is the culture of the process, while .net resources used uiculture; so you had to set the uiculture to the culture of the process.

Date formats, decimal separators and all that are inherited from the system culture or regional settings.  You can have the ArcMap language as French and keep the date formats as English.
0 Kudos
DenisRoose1
New Contributor II
Thanks for the valuable information Alexander.

I was hoping to do this in managed code as well. I'll research some more before "settling" on unmanaged code.

It's good to know (& odd) that the language is handled differently from the remaining cultural settings. It appears that abbreviations for cardinal directions are handled as language, at least when it comes to the following dynamic text: <dyn type="dataframe" name="MyDataFrame" property="upperleft" units="dms"/> where West is abbreviated correctly as O (for Ouest) in the French ArcMap. As you mentioned though, the decimal character on an United States PC is a point and not a comma as it would normally be in France.

The visible part of my extension is an Esri add-in, which seems to make it easier to localize than in your description (see: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/Localizing_add_ins/0001...).

Thanks again
0 Kudos
AlexanderGray
Occasional Contributor III
I haven't done anything with add-ins yet, that is pretty interesting.  You would still have to deal with message boxes and other text feed back sent to the users.
0 Kudos
DenisRoose1
New Contributor II
Here is my code:

Friend Function GetArcgisCurrentLanguageInNlsEnglish() As String
  '
  'PURPOSE: Returns the NLS English name of the current ArcMap interface language
  '=======
  '
  'RETURNS:
  '=======
  'The English name returned is that of a locale as specified in the Windows 7 National Language Support (NLS) API Reference [uses parentheses];
  'NOT the language name as expressed in the Win32_OperatingSystem WMI class documentation [which uses dashes mostly].
' If the language is not yet supported by this function, it returns "Unknown Language"
  '
  'DEPENDENCIES:
  '===========
  'ArcGIS 10.0's language key: HKEY_CURRENT_USER\Software\ESRI\UILANGID
  'ArcGIS 10.0's six supported languages
  'VB.NET
  'In the module declaration section, add: Imports Microsoft.Win32
  '
  'SOURCES:
  '========
  'http://forums.arcgis.com/threads/44153-Programmatically-finding-the-current-language-culture-of-ArcM... HKEY_CURRENT_USER\Software\ESRI\UILANGID
  'http://www.codeproject.com/KB/vb/registry_with_vb.aspx: General registry structure
  'http://msdn.microsoft.com/en-us/library/aa289494(v=vs.71).aspx: Accessing registry key values in managed .NET
  'http://msdn.microsoft.com/en-us/goglobal/bb896001: National Language Support (NLS) API Reference
  'http://msdn.microsoft.com/en-us/library/windows/desktop/aa394239(v=vs.85).aspx: Win32_OperatingSystem WMI class
  '
  'HISTORY:  20111118: First version.
  '=======
  '
  Dim regKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\ESRI", False)  'Read access only to registry
  '
  'iLanguageId is the integer representation of Microsoft operating system language LCID; UILANGID is a registry value of type REG_DWORD
  Dim iLanguageId As Int32 = regKey.GetValue("UILANGID")
  '
  regKey.Close()
  '
  MessageBox.Show("iLanguageId: " & iLanguageId.ToString)
  Select Case iLanguageId
   Case 7
    Return "German"                     'Culture Name: de
   Case 9
    Return "English"                    'Culture Name: en
   Case 10
    Return "Spanish"                    'Culture Name: es
   Case 11
    Return "Japanese"                   'Culture Name: ja
   Case 12
    Return "French"                     'Culture Name: fr
   Case 2052
    Return "Chinese (Simplified, PRC)"  'Culture Name: zh-CN 
    'Note that ArcMap lists only "Chinese (Simplified)", which is not correct as that iLanguageId is 4, not 2052.
   Case Else
    Return "Unknown Language"
  End Select

End Function
0 Kudos