Author Topic: How can i get the current Language Name of AutoCAD (only managed C++ code)  (Read 3936 times)

0 Members and 1 Guest are viewing this topic.

melomayo

  • Guest
I am still looking for a comfortable solution.
Before I load any AutoCAD Linetype, must firstly checked of current AutoCAD version and current Language Pack.
How can I do this? any ideas ?  :-o  :?

Code - C++: [Select]
  1. static void print_LocalInfo ( void )
  2. {
  3. //
  4. // Get RoamableRootFolder :
  5. // "C:\Users\[loginname]\AppData\Roaming\Autodesk\AutoCAD 2015\R20.0\enu\"
  6. //
  7.  
  8. const ACHAR* pRoamableRootFolder;
  9.  
  10. acdbHostApplicationServices()->getRoamableRootFolder( pRoamableRootFolder );
  11.  
  12. // [b]How can i get the Language Name with unmanaged C++ ?[/b]
  13. // ISO 639x Value : Language Name
  14.  
  15. CString ENU = "ENU";
  16. CString DEU = "DEU";
  17.  
  18. // [b]How can i get the Culture Name with unmanaged C++ ?[/b]
  19. //
  20. // "en-US" // English - United States
  21. // "de-DE" // German  - Germany
  22.  
  23. CString rf = pRoamableRootFolder;
  24. CString ts = rf.Mid(rf.GetLength() - ENU.GetLength() - 1, ENU.GetLength());
  25.  
  26. ::acutPrintf(_T("\nYour Language is: %s"), (ENU == ts.MakeUpper()) ? L"Englisch" : L"Deutsch");
  27. }
  28.  

Reference : see also National Language Support - (NLS) API Reference Information for Windows 7

exmachina

  • Guest
Maybe this can be done using AcRxDynamicLinker::ProductLcid.

nullptr

  • BricsCAD
  • Needs a day job
  • Posts: 6713
  • AKA Daniel
there is a locale system variable too (getvar "locale")

melomayo

  • Guest
Maybe this can be done using AcRxDynamicLinker::ProductLcid.

Hi Jar,

thanks for your help, with method
Code - C++: [Select]
  1. acrxDynamicLinker->ProductLcid()

I get following result:

AutoCAD English: ProductLcid = 1033
AutoCAD Englisch with German Language Pack: ProductLcid = 1031

Kean Walmsley has written an .NET example:
Determining AutoCADís language using .NET:  http://through-the-interface.typepad.com/through_the_interface/2014/03/determining-autocads-language-using-net.html

Code - C#: [Select]
  1. using System.Globalization;
  2. using Autodesk.AutoCAD.ApplicationServices;
  3. using Autodesk.AutoCAD.Runtime;
  4.  
  5. namespace LanguageInfo
  6. {
  7.  public class Commands
  8.  {
  9.    [CommandMethod("LANG")]
  10.    public static void WhichLanguage( )
  11.    {
  12.      var cult = new CultureInfo(SystemObjects.DynamicLinker.ProductLcid);
  13.      Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage( "\nLanguage of your AutoCAD product is {0}.", cult.EnglishName );
  14.    }
  15.  }
  16. }
  17.  

My question is how can I use similar class CultureInfo in C++/ARX  (not CLR) ?
How can i use the function ::GetLocaleInfo for determine the LocalId?

melomayo

  • Guest
there is a locale system variable too (getvar "locale")

Hi nullptr,

both version give me the same result

AutoCAD English: (getvar "LOCALE") = "DEU"
AutoCAD Englisch with German Language Pack: (getvar "LOCALE") =  "DEU"

thanks for your help  :-)

melomayo

  • Guest
I have following code form Google,
maybe is that usefull
 
The Original Source code is from J. Michael McGarrah ( mcgarrah@mcgarware.com )

Code - C++: [Select]
  1. static void get_LocalInfo ( void )
  2. {
  3. // Retrieves the active input locale identifier.  
  4. HKL hKl = ::GetKeyboardLayout( 0 );
  5.  
  6. // LOWORD of the returned value contains the language identifier.  
  7. LANGID langID = LOWORD((DWORD) hKl );
  8.  
  9. // Retirieve the information about the locale
  10. LCID lcID = MAKELCID( langID, SORT_DEFAULT );
  11.  
  12. const int kLen = 7;
  13. const int sLen = 100;
  14.  
  15. TCHAR chPage         [ kLen     ];
  16. TCHAR szCurrency     [ kLen     ];
  17. TCHAR szVal          [ MAX_PATH ];
  18. TCHAR szFormatString [ sLen     ];
  19.  
  20. // Get currently ised code page.  
  21. ::GetLocaleInfo(lcID, LOCALE_IDEFAULTANSICODEPAGE, chPage, kLen);
  22. int m_iCodePage = atoi((const char *)chPage);
  23.  
  24. // Get default OEM code page.  
  25. ::GetLocaleInfo(lcID, LOCALE_IDEFAULTCODEPAGE, chPage, kLen);
  26. int m_iOEMCodePage = atoi((const char *) chPage);
  27.  
  28. // Get country name in english.  
  29. ::GetLocaleInfo(lcID, LOCALE_SENGCOUNTRY, szVal, MAX_PATH);
  30. CString m_strCountry = szVal;
  31.  
  32. // Get country code -- not sure if this works  
  33. ::GetLocaleInfo(lcID, LOCALE_ICOUNTRY, chPage, kLen);
  34. int m_iCountryCode = atoi((const char *)chPage);
  35.  
  36. // Get language name.  
  37. ::GetLocaleInfo(lcID, LOCALE_SENGLANGUAGE, szVal, MAX_PATH);
  38. CString m_strLanguage = szVal;
  39.  
  40. // Get TimeFormat String  
  41. ::GetLocaleInfo(lcID, LOCALE_STIMEFORMAT, szFormatString, sLen);
  42. CString m_strTimeFormat = szFormatString;
  43.  
  44. // Get Date Format String  
  45. ::GetLocaleInfo(lcID, LOCALE_SLONGDATE, szFormatString, sLen);
  46. CString m_strDateFormat = szFormatString;
  47.  
  48. // Get the string used for local currency.  
  49. ::GetLocaleInfo(lcID, LOCALE_SCURRENCY, szCurrency, kLen);
  50. CString m_strCurrency = szCurrency;
  51.  
  52.  
  53. // Get time format specifier i.e. 12 hour (AM/PM) or 24 hour format  
  54. // is used to indicate time.  
  55. ::GetLocaleInfo(lcID, LOCALE_ITIME, szVal, 3);
  56.  
  57. CString m_strTimeFormatSpecifier = ( atoi ( (const char *) szVal ) == 0 ) ? "AM / PM 12-hour format" : "24-hour format";
  58.  
  59. // Get calendar type
  60. ::GetLocaleInfo( lcID, LOCALE_ICALENDARTYPE, szVal, 3 );
  61.  
  62. CString m_strCalendarType;
  63.  
  64. switch ( atoi( (const char *) szVal ) )
  65. {
  66. case 1:
  67. m_strCalendarType = ("Gregorian - Localized");
  68. break;
  69. case 2:
  70. m_strCalendarType = ("Gregorian - English strings always");
  71. break;
  72. case 3:
  73. m_strCalendarType = ("Year of the Emperor - Japan");
  74. break;
  75. case 4:
  76. m_strCalendarType = ("Year of Taiwan");
  77. break;
  78. case 5:
  79. m_strCalendarType = ("Tangun Era - Korea");
  80. break;
  81. case 6:
  82. m_strCalendarType = ("Hijri - Arabic lunar");
  83. break;
  84. case 7:
  85. m_strCalendarType = ("Thai");
  86. break;
  87. case 8:
  88. m_strCalendarType = ("Hebrew - Lunar");
  89. break;
  90. case 9:
  91. m_strCalendarType = ("Gregorian Middle East French");
  92. break;
  93. case 10:
  94. m_strCalendarType = ("Gregorian Arabic");
  95. break;
  96. case 11:
  97. m_strCalendarType = ("Gregorian Transliterated English");
  98. break;
  99. case 12:
  100. m_strCalendarType = ("Gregorian Transliterated French");
  101. break;
  102. default:
  103. m_strCalendarType = ("Unknown");
  104. }
  105.  
  106. // Get the ID of the language identifier.  
  107. LANGID langId = ::GetSystemDefaultLangID();
  108.  
  109. DWORD dwSize, dwError, dwReturnedSize;
  110.  
  111. ACHAR szLanguage[ MAX_PATH ];
  112.  
  113. // Get the string for the language identifier.  
  114. dwSize = MAX_PATH;
  115. dwReturnedSize = VerLanguageName(langId, szLanguage, dwSize);
  116.  
  117. CString m_strLocaleLocalLanguage;
  118.  
  119. if ( dwReturnedSize <= dwSize )
  120. {
  121. m_strLocaleLocalLanguage = szLanguage;
  122. }
  123.  
  124. // Get time zone information.  
  125. TIME_ZONE_INFORMATION info;
  126. TCHAR szTimezone[31];
  127.  
  128. dwError = ::GetTimeZoneInformation(&info);
  129.  
  130. CString m_strLocaleTimeZone;
  131.  
  132. if ( TIME_ZONE_ID_INVALID != dwError )
  133. {
  134. wsprintf( szTimezone, L"%s", info.StandardName );
  135.  
  136. m_strLocaleTimeZone = szTimezone;
  137. }
  138.  
  139. ::acutPrintf(_T("\n------------------   ") );
  140. ::acutPrintf(_T("\nLOCALE INFORMATION   ") );
  141. ::acutPrintf(_T("\n------------------   ") );
  142. ::acutPrintf(_T("\nCodePage:      %d    "), m_iCodePage              );
  143. ::acutPrintf(_T("\nOEMCodePage:   %d    "), m_iOEMCodePage           );
  144. ::acutPrintf(_T("\nLanguage:      %s    "), m_strLanguage            );
  145. ::acutPrintf(_T("\nDateFormat:    %s    "), m_strDateFormat          );
  146. ::acutPrintf(_T("\nCountry:       %s    "), m_strCountry             );
  147. ::acutPrintf(_T("\nCountryCode:   %d    "), m_iCountryCode           );
  148. ::acutPrintf(_T("\nTimeFormat:    %s    "), m_strTimeFormat          );
  149. ::acutPrintf(_T("\nCurrency:      %s    "), m_strCurrency            );
  150. ::acutPrintf(_T("\nTimeFrmSpec.:  %s    "), m_strTimeFormatSpecifier );
  151. ::acutPrintf(_T("\nCalendarType:  %s    "), m_strCalendarType        );
  152. ::acutPrintf(_T("\nLocalLanguage: %s    "), m_strLocaleLocalLanguage );
  153. ::acutPrintf(_T("\nTimeZone:      %s    "), m_strLocaleTimeZone      );
  154. ::acutPrintf(_T("\n"));
  155.  
  156. }
  157.