]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/Strings.c
Roll back changes to apply GetBestLanguage() in HiiDataBase. Exact language match...
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiOnUefiHiiThunk / Strings.c
index 6e966192ac2243f4671dff44a0b4bbddd315ceb2..d83750bc9b8f16bd70e89e7a19dffee64e50140b 100644 (file)
@@ -15,42 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 #include "HiiDatabase.h"\r
 \r
-typedef struct {\r
-  CHAR8 *Iso639;\r
-  CHAR8 *Rfc3066;\r
-} ISO639TORFC3066MAP;\r
-\r
-ISO639TORFC3066MAP Iso639ToRfc3066Map [] = {\r
-    {"eng", "en-US"},\r
-    {"fra", "fr-FR"},\r
-};\r
-\r
-CHAR8 *\r
-ConvertIso639ToRfc3066 (\r
-  CHAR8 *Iso638Lang\r
-  )\r
-{\r
-  UINTN Index;\r
-  CHAR8 AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];\r
-  \r
-  AsciiStrnCpy (AsciiLanguage, Iso638Lang, sizeof (AsciiLanguage));\r
-  for (Index = 0; Index < ISO_639_2_ENTRY_SIZE + 1; Index ++) {\r
-       if (AsciiLanguage [Index] == 0) {\r
-               break;\r
-       } else if (AsciiLanguage [Index] >= 'A' && AsciiLanguage [Index] <= 'Z') {\r
-               AsciiLanguage [Index] = (CHAR8) (AsciiLanguage [Index] - 'A' + 'a');\r
-       }\r
-  }\r
-\r
-  for (Index = 0; Index < sizeof (Iso639ToRfc3066Map) / sizeof (Iso639ToRfc3066Map[0]); Index++) {\r
-    if (AsciiStrnCmp (AsciiLanguage, Iso639ToRfc3066Map[Index].Iso639, AsciiStrSize (AsciiLanguage)) == 0) {\r
-      return Iso639ToRfc3066Map[Index].Rfc3066;\r
-    }\r
-  }\r
-\r
-  return (CHAR8 *) NULL;\r
-}\r
-\r
 /**\r
   Test if all of the characters in a string have corresponding font characters.\r
 \r
@@ -65,7 +29,7 @@ ConvertIso639ToRfc3066 (
                          If all glyphs in the string are available, the index is the index of the terminator \r
                          of the string. \r
   @param GlyphBufferSize A pointer to a value. On output, if the function returns EFI_SUCCESS, \r
-                         it contains the amount of memory that is required to store the string¡¯s glyph equivalent.\r
+                         it contains the amount of memory that is required to store the string? glyph equivalent.\r
 \r
   @retval EFI_UNSUPPORTED  The function performs nothing and return EFI_UNSUPPORTED.\r
 **/\r
@@ -126,7 +90,7 @@ GetTagGuidByFwHiiHandle (
   Create or update the String given a new string and String ID.\r
 \r
   @param ThunkContext           The Thunk Context.\r
-  @param Rfc3066AsciiLanguage   The RFC 3066 Language code in ASCII string format.\r
+  @param Rfc4646AsciiLanguage   The RFC 4646 Language code in ASCII string format.\r
   @param NewString              The new string.\r
   @param StringId               The String ID. If StringId is 0, a new String Token\r
                                 is created. Otherwise, the String Token StringId is \r
@@ -142,79 +106,23 @@ GetTagGuidByFwHiiHandle (
 EFI_STATUS\r
 UpdateString (\r
   IN CONST HII_THUNK_CONTEXT        *ThunkContext,\r
-  IN CONST CHAR8                    *Rfc3066AsciiLanguage,\r
+  IN CONST CHAR8                    *Rfc4646AsciiLanguage,\r
   IN       CHAR16                   *NewString,\r
   IN OUT STRING_REF                 *StringId\r
   )\r
 {\r
   EFI_STRING_ID                             NewStringId;\r
-  EFI_STATUS                                Status;\r
 \r
-\r
-  NewStringId = 0;\r
-  \r
-  if (*StringId == 0) {\r
-    //\r
-    // Create a new string token.\r
-    //\r
-    if (Rfc3066AsciiLanguage == NULL) {\r
-      //\r
-      // For all languages in the package list.\r
-      //\r
-      Status = HiiLibNewString (ThunkContext->UefiHiiHandle, &NewStringId, NewString);\r
-    } else {\r
-      //\r
-      // For specified language.\r
-      //\r
-      Status = mHiiStringProtocol->NewString (\r
-                                     mHiiStringProtocol,\r
-                                     ThunkContext->UefiHiiHandle,\r
-                                     &NewStringId,\r
-                                     Rfc3066AsciiLanguage,\r
-                                     NULL,\r
-                                     NewString,\r
-                                     NULL\r
-                                     );\r
-    }\r
-  } else {\r
-    //\r
-    // Update the existing string token.\r
-    //\r
-    if (Rfc3066AsciiLanguage == NULL) {\r
-      //\r
-      // For all languages in the package list.\r
-      //\r
-      Status = HiiLibSetString (ThunkContext->UefiHiiHandle, *StringId, NewString);\r
-    } else {\r
-      //\r
-      // For specified language.\r
-      //\r
-      Status = mHiiStringProtocol->SetString (\r
-                                   mHiiStringProtocol,\r
-                                   ThunkContext->UefiHiiHandle,\r
-                                   *StringId,\r
-                                   Rfc3066AsciiLanguage,\r
-                                   NewString,\r
-                                   NULL\r
-                                   );\r
-    }\r
-  }\r
-  \r
-  if (!EFI_ERROR (Status)) {\r
-    if (*StringId == 0) {\r
-      //\r
-      // When creating new string, return the newly created String Token.\r
-      //\r
-      *StringId = NewStringId;\r
-    }\r
-  } else {\r
+  NewStringId = HiiSetString (ThunkContext->UefiHiiHandle, *StringId, NewString, Rfc4646AsciiLanguage);\r
+  *StringId = NewStringId;\r
+  if (NewStringId == 0) {\r
     //\r
     // Only EFI_INVALID_PARAMETER is defined in HII 0.92 specification.\r
     //\r
-    *StringId = 0;\r
+    return EFI_INVALID_PARAMETER;\r
+  } else {\r
+    return EFI_SUCCESS;\r
   }\r
-\r
-  return Status;\r
 }\r
 \r
 /**\r
@@ -256,19 +164,19 @@ HiiNewString (
   EFI_STRING_ID                             LastStringId;\r
   CHAR8                                     AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];\r
   CHAR16                                    LanguageCopy[ISO_639_2_ENTRY_SIZE + 1];\r
-  CHAR8                                     *Rfc3066AsciiLanguage;\r
+  CHAR8                                     *Rfc4646AsciiLanguage;\r
 \r
   LastStringId      = (EFI_STRING_ID) 0;\r
   StringId          = (EFI_STRING_ID) 0;\r
-  Rfc3066AsciiLanguage = NULL;\r
+  Rfc4646AsciiLanguage = NULL;\r
 \r
   if (Language != NULL) {\r
     ZeroMem (AsciiLanguage, sizeof (AsciiLanguage));;\r
     ZeroMem (LanguageCopy, sizeof (LanguageCopy));\r
     CopyMem (LanguageCopy, Language, ISO_639_2_ENTRY_SIZE * sizeof (CHAR16));\r
     UnicodeStrToAsciiStr (LanguageCopy, AsciiLanguage);\r
-    Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (AsciiLanguage);\r
-    ASSERT (Rfc3066AsciiLanguage != NULL);\r
+    Rfc4646AsciiLanguage = ConvertLanguagesIso639ToRfc4646 (AsciiLanguage);\r
+    ASSERT (Rfc4646AsciiLanguage != NULL);\r
   }\r
 \r
   Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
@@ -289,7 +197,7 @@ HiiNewString (
       if (CompareGuid (&TagGuid, &ThunkContext->TagGuid)) {\r
         if (ThunkContext->SharingStringPack) {\r
           StringId = *Reference;\r
-          Status = UpdateString (ThunkContext, Rfc3066AsciiLanguage, NewString, &StringId);\r
+          Status = UpdateString (ThunkContext, Rfc4646AsciiLanguage, NewString, &StringId);\r
           if (EFI_ERROR (Status)) {\r
             break;\r
           }\r
@@ -317,7 +225,7 @@ HiiNewString (
     }\r
   } else {\r
     StringId = *Reference;\r
-    Status = UpdateString (StringPackThunkContext, Rfc3066AsciiLanguage, NewString, &StringId);\r
+    Status = UpdateString (StringPackThunkContext, Rfc4646AsciiLanguage, NewString, &StringId);\r
   }\r
 \r
   if (!EFI_ERROR (Status)) {\r
@@ -378,7 +286,7 @@ HiiResetStrings (
 **/\r
 EFI_STATUS\r
 EFIAPI\r
-HiiGetString (\r
+HiiThunkGetString (\r
   IN     EFI_HII_PROTOCOL           *This,\r
   IN     FRAMEWORK_EFI_HII_HANDLE   Handle,\r
   IN     STRING_REF                 Token,\r
@@ -388,16 +296,18 @@ HiiGetString (
   OUT    EFI_STRING                 StringBuffer\r
   )\r
 {\r
-  CHAR8                                 *Iso639AsciiLanguage;\r
   HII_THUNK_PRIVATE_DATA                *Private;\r
-  CHAR8                                 *Rfc3066AsciiLanguage;\r
+  CHAR8                                 *Iso639AsciiLanguage;\r
+  CHAR8                                 *Rfc4646AsciiLanguage;\r
+  CHAR8                                 *SupportedLanguages;\r
+  CHAR8                                 *PlatformLanguage;\r
+  CHAR8                                 *BestLanguage;\r
   EFI_HII_HANDLE                        UefiHiiHandle;\r
   EFI_STATUS                            Status;\r
 \r
   Private = HII_THUNK_PRIVATE_DATA_FROM_THIS(This);\r
 \r
-  Iso639AsciiLanguage = NULL;\r
-  Rfc3066AsciiLanguage = NULL;\r
+  Rfc4646AsciiLanguage = NULL;\r
 \r
   if (LanguageString != NULL) {\r
     Iso639AsciiLanguage = AllocateZeroPool (StrLen (LanguageString) + 1);\r
@@ -408,15 +318,16 @@ HiiGetString (
 \r
     //\r
     // Caller of Framework HII Interface uses the Language Identification String defined \r
-    // in Iso639. So map it to the Language Identifier defined in RFC3066.\r
+    // in Iso639. So map it to the Language Identifier defined in RFC4646.\r
     //\r
-    Rfc3066AsciiLanguage = ConvertIso639ToRfc3066 (Iso639AsciiLanguage);\r
+    Rfc4646AsciiLanguage = ConvertLanguagesIso639ToRfc4646 (Iso639AsciiLanguage);\r
+    FreePool (Iso639AsciiLanguage);\r
 \r
     //\r
-    // If Rfc3066AsciiLanguage is NULL, more language mapping must be added to \r
-    // Iso639ToRfc3066Map.\r
+    // If Rfc4646AsciiLanguage is NULL, more language mapping must be added to \r
+    // Iso639ToRfc4646Map.\r
     //\r
-    ASSERT (Rfc3066AsciiLanguage != NULL);\r
+    ASSERT (Rfc4646AsciiLanguage != NULL);\r
     \r
   }\r
 \r
@@ -426,23 +337,56 @@ HiiGetString (
     goto Done;\r
   }\r
 \r
-  if (Rfc3066AsciiLanguage == NULL) {\r
-    Status =  HiiLibGetString (UefiHiiHandle, Token, StringBuffer, BufferLengthTemp);\r
-  } else {\r
-    Status = mHiiStringProtocol->GetString (\r
-                                 mHiiStringProtocol,\r
-                                 Rfc3066AsciiLanguage,\r
-                                 UefiHiiHandle,\r
-                                 Token,\r
-                                 StringBuffer,\r
-                                 BufferLengthTemp,\r
-                                 NULL\r
-                                 );\r
+  //\r
+  // Get the languages that the package specified by HiiHandle supports\r
+  //\r
+  SupportedLanguages = HiiGetSupportedLanguages (UefiHiiHandle);\r
+  if (SupportedLanguages == NULL) {\r
+    goto Error2;\r
+  }\r
+\r
+  //\r
+  // Get the current platform language setting\r
+  //\r
+  PlatformLanguage = GetEfiGlobalVariable (L"PlatformLang");\r
+  if (PlatformLanguage == NULL) {\r
+    goto Error1;\r
+  }\r
+\r
+  //\r
+  // Get the best matching language from SupportedLanguages\r
+  //\r
+  BestLanguage = GetBestLanguage (\r
+                   SupportedLanguages, \r
+                   FALSE,                // RFC 4646 mode\r
+                   (Rfc4646AsciiLanguage != NULL) ? Rfc4646AsciiLanguage : "",\r
+                   PlatformLanguage,     // Next highest priority\r
+                   SupportedLanguages,   // Lowest priority \r
+                   NULL\r
+                   );\r
+  if (BestLanguage == NULL) {\r
+    FreePool (PlatformLanguage);\r
+Error1:\r
+    FreePool (SupportedLanguages);\r
+Error2:\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto Done;\r
   }\r
 \r
+  Status = mHiiStringProtocol->GetString (\r
+                               mHiiStringProtocol,\r
+                               BestLanguage,\r
+                               UefiHiiHandle,\r
+                               Token,\r
+                               StringBuffer,\r
+                               BufferLengthTemp,\r
+                               NULL\r
+                               );\r
+  FreePool (BestLanguage);\r
+\r
 Done:\r
-       if (Iso639AsciiLanguage != NULL) {\r
-    FreePool (Iso639AsciiLanguage);\r
+       if (Rfc4646AsciiLanguage != NULL) {\r
+    FreePool (Rfc4646AsciiLanguage);\r
   }\r
   \r
   return Status;\r