Explorar o código

Bug 1779: Cannot switch back to English after changing language on non-US English system

https://winscp.net/tracker/1779
(cherry picked from commit 8087b408006390abb63b9c561621f103e44018d4)

Source commit: a4cf37c0919cceaefa191069049be3d546dfabd8
Martin Prikryl %!s(int64=6) %!d(string=hai) anos
pai
achega
6a34dd9cd8

+ 1 - 1
source/forms/About.cpp

@@ -199,7 +199,7 @@ void __fastcall TAboutDialog::DoLoadThirdParty()
   UnicodeString ThirdParty;
   UnicodeString Br = "<br/>\n";
 
-  if (GUIConfiguration->AppliedLocale != GUIConfiguration->InternalLocale())
+  if (!GUIConfiguration->UsingInternalTranslation())
   {
     UnicodeString TranslatorUrl = LoadStr(TRANSLATOR_URL);
     UnicodeString TranslatorInfo = LoadStr(TRANSLATOR_INFO2);

+ 17 - 5
source/windows/GUIConfiguration.cpp

@@ -825,7 +825,9 @@ HINSTANCE __fastcall TGUIConfiguration::LoadNewResourceModule(LCID ALocale,
 {
   UnicodeString LibraryFileName;
   HINSTANCE NewInstance = 0;
-  bool Internal = (ALocale == InternalLocale());
+  LCID AInternalLocale = InternalLocale();
+  bool Internal = (ALocale == AInternalLocale);
+  DWORD PrimaryLang = PRIMARYLANGID(ALocale);
   if (!Internal)
   {
     UnicodeString Module;
@@ -855,7 +857,6 @@ HINSTANCE __fastcall TGUIConfiguration::LoadNewResourceModule(LCID ALocale,
     }
     else
     {
-      DWORD PrimaryLang = PRIMARYLANGID(ALocale);
       DWORD SubLang = SUBLANGID(ALocale);
       DebugAssert(SUBLANG_DEFAULT == SUBLANG_CHINESE_TRADITIONAL);
       // Finally look for a language-only translation.
@@ -875,6 +876,13 @@ HINSTANCE __fastcall TGUIConfiguration::LoadNewResourceModule(LCID ALocale,
     }
   }
 
+  // If the locale is non-US English and we do not have that translation (and it's unlikely we ever have),
+  // treat it as if it were US English.
+  if (!NewInstance && !Internal && (PrimaryLang == static_cast<DWORD>(PRIMARYLANGID(AInternalLocale))))
+  {
+    Internal = true;
+  }
+
   if (!NewInstance && !Internal)
   {
     throw Exception(FMTLOAD(LOCALE_LOAD_ERROR, (int(ALocale))));
@@ -1001,17 +1009,21 @@ bool __fastcall TGUIConfiguration::GetCanApplyLocaleImmediately()
     (Screen->DataModuleCount == 0);
 }
 //---------------------------------------------------------------------------
+bool __fastcall TGUIConfiguration::UsingInternalTranslation()
+{
+  return FLocaleModuleName.IsEmpty();
+}
+//---------------------------------------------------------------------------
 UnicodeString __fastcall TGUIConfiguration::AppliedLocaleCopyright()
 {
   UnicodeString Result;
-  if ((FAppliedLocale == 0) || (FAppliedLocale == InternalLocale()))
+  if (UsingInternalTranslation())
   {
     DebugFail(); // we do not expect to get called with internal locale
     Result = UnicodeString();
   }
   else
   {
-    DebugAssert(!FLocaleModuleName.IsEmpty());
     Result = GetFileFileInfoString(L"LegalCopyright", FLocaleModuleName);
   }
   return Result;
@@ -1020,7 +1032,7 @@ UnicodeString __fastcall TGUIConfiguration::AppliedLocaleCopyright()
 UnicodeString __fastcall TGUIConfiguration::AppliedLocaleVersion()
 {
   UnicodeString Result;
-  if ((FAppliedLocale == 0) || (FAppliedLocale == InternalLocale()))
+  if (UsingInternalTranslation())
   {
     // noop
   }

+ 2 - 1
source/windows/GUIConfiguration.h

@@ -233,6 +233,7 @@ protected:
   virtual int __fastcall GetResourceModuleCompleteness(HINSTANCE Module);
   virtual bool __fastcall IsTranslationComplete(HINSTANCE Module);
   static int __fastcall LocalesCompare(void * Item1, void * Item2);
+  LCID __fastcall InternalLocale();
   bool __fastcall DoSaveCopyParam(THierarchicalStorage * Storage, const TCopyParamType * CopyParam, const TCopyParamType * Defaults);
 
 public:
@@ -245,7 +246,7 @@ public:
 
   HANDLE __fastcall ChangeToDefaultResourceModule();
   HANDLE __fastcall ChangeResourceModule(HANDLE Instance);
-  LCID __fastcall InternalLocale();
+  bool __fastcall UsingInternalTranslation();
   UnicodeString __fastcall AppliedLocaleCopyright();
   UnicodeString __fastcall AppliedLocaleVersion();
   TStoredSessionList * __fastcall SelectPuttySessionsForImport(TStoredSessionList * Sessions, UnicodeString & Error);