]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/UefiHiiLib/HiiString.c
Support get string from configuration string packages.
[mirror_edk2.git] / MdeModulePkg / Library / UefiHiiLib / HiiString.c
index 7d8ca5e11720664a8c1f670d9db2d7ce16ba9514..bfae3f8fc0948460704886730f3d4a58a7ae8cd3 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   HII Library implementation that uses DXE protocols and services.\r
 \r
-  Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
-  All rights reserved. This program and the accompanying materials\r
+  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
   http://opensource.org/licenses/bsd-license.php\r
 \r
 #include "InternalHiiLib.h"\r
 \r
-\r
-//\r
-// Lookup table of ISO639-2 3 character language codes to ISO 639-1 2 character language codes\r
-// Each entry is 5 CHAR8 values long.  The first 3 CHAR8 values are the ISO 639-2 code.\r
-// The last 2 CHAR8 values are the ISO 639-1 code.\r
-//\r
-GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Iso639ToRfc3066ConversionTable[] =\r
-"\\r
-aaraa\\r
-abkab\\r
-afraf\\r
-amham\\r
-araar\\r
-asmas\\r
-aymay\\r
-azeaz\\r
-bakba\\r
-belbe\\r
-benbn\\r
-bihbh\\r
-bisbi\\r
-bodbo\\r
-brebr\\r
-bulbg\\r
-catca\\r
-cescs\\r
-corkw\\r
-cosco\\r
-cymcy\\r
-danda\\r
-deude\\r
-dzodz\\r
-ellel\\r
-engen\\r
-epoeo\\r
-estet\\r
-euseu\\r
-faofo\\r
-fasfa\\r
-fijfj\\r
-finfi\\r
-frafr\\r
-fryfy\\r
-gaiga\\r
-gdhgd\\r
-glggl\\r
-grngn\\r
-gujgu\\r
-hauha\\r
-hebhe\\r
-hinhi\\r
-hrvhr\\r
-hunhu\\r
-hyehy\\r
-ikuiu\\r
-ileie\\r
-inaia\\r
-indid\\r
-ipkik\\r
-islis\\r
-itait\\r
-jawjw\\r
-jpnja\\r
-kalkl\\r
-kankn\\r
-kasks\\r
-katka\\r
-kazkk\\r
-khmkm\\r
-kinrw\\r
-kirky\\r
-korko\\r
-kurku\\r
-laolo\\r
-latla\\r
-lavlv\\r
-linln\\r
-litlt\\r
-ltzlb\\r
-malml\\r
-marmr\\r
-mkdmk\\r
-mlgmg\\r
-mltmt\\r
-molmo\\r
-monmn\\r
-mrimi\\r
-msams\\r
-myamy\\r
-nauna\\r
-nepne\\r
-nldnl\\r
-norno\\r
-ocioc\\r
-ormom\\r
-panpa\\r
-polpl\\r
-porpt\\r
-pusps\\r
-quequ\\r
-rohrm\\r
-ronro\\r
-runrn\\r
-rusru\\r
-sagsg\\r
-sansa\\r
-sinsi\\r
-slksk\\r
-slvsl\\r
-smise\\r
-smosm\\r
-snasn\\r
-sndsd\\r
-somso\\r
-sotst\\r
-spaes\\r
-sqisq\\r
-srpsr\\r
-sswss\\r
-sunsu\\r
-swasw\\r
-swesv\\r
-tamta\\r
-tattt\\r
-telte\\r
-tgktg\\r
-tgltl\\r
-thath\\r
-tsnts\\r
-tuktk\\r
-twitw\\r
-uigug\\r
-ukruk\\r
-urdur\\r
-uzbuz\\r
-vievi\\r
-volvo\\r
-wolwo\\r
-xhoxh\\r
-yidyi\\r
-zhaza\\r
-zhozh\\r
-zulzu\\r
-";\r
-\r
-\r
-\r
 /**\r
-  This function adds the string into String Package of each language\r
-  supported by the package list.\r
-\r
-  If String is NULL, then ASSERT.\r
-  If StringId is NULL, the ASSERT.\r
-  If PackageList could not be found in the default HII database, then ASSERT.\r
-\r
-  @param  PackageList            Handle of the package list where this string will\r
-                                            be added.\r
-  @param  StringId               On return, contains the new strings id, which is\r
-                                          unique within PackageList.\r
-  @param  String                 Points to the new null-terminated string.\r
-\r
-  @retval EFI_SUCCESS             The new string was added successfully.\r
-  @retval EFI_OUT_OF_RESOURCES   Could not add the string due to lack of resources.\r
+  This function create a new string in String Package or updates an existing \r
+  string in a String Package.  If StringId is 0, then a new string is added to\r
+  a String Package.  If StringId is not zero, then a string in String Package is\r
+  updated.  If SupportedLanguages is NULL, then the string is added or updated\r
+  for all the languages that the String Package supports.  If SupportedLanguages\r
+  is not NULL, then the string is added or updated for the set of languages \r
+  specified by SupportedLanguages.\r
+    \r
+  If HiiHandle is NULL, then ASSERT().\r
+  If String is NULL, then ASSERT().\r
+\r
+  @param[in]  HiiHandle           A handle that was previously registered in the \r
+                                  HII Database.\r
+  @param[in]  StringId            If zero, then a new string is created in the \r
+                                  String Package associated with HiiHandle.  If \r
+                                  non-zero, then the string specified by StringId \r
+                                  is updated in the String Package  associated \r
+                                  with HiiHandle. \r
+  @param[in]  String              A pointer to the Null-terminated Unicode string \r
+                                  to add or update in the String Package associated \r
+                                  with HiiHandle.\r
+  @param[in]  SupportedLanguages  A pointer to a Null-terminated ASCII string of \r
+                                  language codes.  If this parameter is NULL, then \r
+                                  String is added or updated in the String Package \r
+                                  associated with HiiHandle for all the languages \r
+                                  that the String Package supports.  If this \r
+                                  parameter is not NULL, then then String is added \r
+                                  or updated in the String Package associated with \r
+                                  HiiHandle for the set oflanguages specified by \r
+                                  SupportedLanguages.  The format of \r
+                                  SupportedLanguages must follow the language \r
+                                  format assumed the HII Database.\r
+\r
+  @retval 0      The string could not be added or updated in the String Package.\r
+  @retval Other  The EFI_STRING_ID of the newly added or updated string.\r
 \r
 **/\r
-EFI_STATUS\r
+EFI_STRING_ID\r
 EFIAPI\r
-HiiLibNewString (\r
-  IN  EFI_HII_HANDLE                  PackageList,\r
-  OUT EFI_STRING_ID                   *StringId,\r
-  IN  CONST EFI_STRING                String\r
+HiiSetString (\r
+  IN EFI_HII_HANDLE    HiiHandle,\r
+  IN EFI_STRING_ID     StringId,            OPTIONAL\r
+  IN CONST EFI_STRING  String,\r
+  IN CONST CHAR8       *SupportedLanguages  OPTIONAL\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-  CHAR8       *Languages;\r
-  CHAR8       *LangStrings;\r
-  CHAR8       *Lang;\r
+  EFI_STATUS     Status;\r
+  CHAR8          *AllocatedLanguages;\r
+  CHAR8          *Supported;\r
+  CHAR8          *Language;\r
 \r
+  ASSERT (HiiHandle != NULL);\r
   ASSERT (String != NULL);\r
-  ASSERT (StringId != NULL);\r
 \r
-  Status = EFI_SUCCESS;\r
+  if (SupportedLanguages == NULL) {\r
+    //\r
+    // Retrieve the languages that the package specified by HiiHandle supports\r
+    //\r
+    AllocatedLanguages = HiiGetSupportedLanguages (HiiHandle);\r
+  } else {\r
+    //\r
+    // Allocate a copy of the SupportLanguages string that passed in\r
+    //\r
+    AllocatedLanguages = AllocateCopyPool (AsciiStrSize (SupportedLanguages), SupportedLanguages);\r
+  }\r
 \r
-  Languages = HiiLibGetSupportedLanguages (PackageList);\r
-  ASSERT (Languages != NULL);\r
   //\r
-  // Allocate working buffer to contain substring of Languages.\r
+  // If there are not enough resources for the supported languages string, then return a StringId of 0\r
   //\r
-  Lang = AllocatePool (AsciiStrSize (Languages));\r
-  ASSERT (Lang != NULL);\r
+  if (AllocatedLanguages == NULL) {\r
+    return (EFI_STRING_ID)(0);\r
+  }\r
 \r
-  LangStrings = Languages;\r
-  while (*LangStrings != 0) {\r
-    HiiLibGetNextLanguage (&LangStrings, Lang);\r
+  Status = EFI_INVALID_PARAMETER;\r
+  //\r
+  // Loop through each language that the string supports\r
+  //\r
+  for (Supported = AllocatedLanguages; *Supported != '\0'; ) {\r
+    //\r
+    // Cache a pointer to the beginning of the current language in the list of languages\r
+    //\r
+    Language = Supported;\r
 \r
     //\r
-    // For each language supported by the package,\r
-    // a string token is created.\r
+    // Search for the next language seperator and replace it with a Null-terminator\r
     //\r
-    Status = gHiiString->NewString (\r
-                                 gHiiString,\r
-                                 PackageList,\r
-                                 StringId,\r
-                                 Lang,\r
-                                 NULL,\r
-                                 String,\r
-                                 NULL\r
-                                 );\r
-    if (EFI_ERROR (Status)) {\r
-      break;\r
+    for (; *Supported != 0 && *Supported != ';'; Supported++);\r
+    if (*Supported != 0) {\r
+      *(Supported++) = '\0';\r
+    }\r
+    \r
+    if ((SupportedLanguages == NULL) && AsciiStrnCmp (Language, UEFI_CONFIG_LANG, AsciiStrLen (UEFI_CONFIG_LANG)) == 0) {\r
+      //\r
+      // Skip string package used for keyword protocol.\r
+      //\r
+      continue;\r
     }\r
-  }\r
-\r
-  FreePool (Lang);\r
-  FreePool (Languages);\r
-\r
-  return Status;\r
-  \r
-}\r
-\r
-\r
-/**\r
-  This function update the specified string in String Package of each language\r
-  supported by the package list.\r
-\r
-  If String is NULL, then ASSERT.\r
-  If PackageList could not be found in the default HII database, then ASSERT.\r
-  If StringId is not found in PackageList, then ASSERT.\r
-\r
-  @param  PackageList            Handle of the package list where this string will\r
-                                            be added.\r
-  @param  StringId               Ths String Id to be updated.\r
-  @param  String                 Points to the new null-terminated string.\r
-\r
-  @retval EFI_SUCCESS            The new string was added successfully.\r
-  @retval EFI_OUT_OF_RESOURCES   Could not add the string due to lack of resources.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-HiiLibSetString (\r
-  IN  EFI_HII_HANDLE                  PackageList,\r
-  IN  EFI_STRING_ID                   StringId,\r
-  IN  CONST EFI_STRING                String\r
-  )\r
-{\r
-  EFI_STATUS  Status;\r
-  CHAR8       *Languages;\r
-  CHAR8       *LangStrings;\r
-  CHAR8       *Lang;\r
-\r
-  ASSERT (IsHiiHandleRegistered (PackageList));\r
-\r
-  Status = EFI_SUCCESS;\r
-\r
-  Languages = HiiLibGetSupportedLanguages (PackageList);\r
-  ASSERT (Languages != NULL);\r
-\r
-  //\r
-  // Allocate working buffer to contain substring of Languages.\r
-  //\r
-  Lang = AllocatePool (AsciiStrSize (Languages));\r
-  ASSERT (Lang != NULL);\r
 \r
-  LangStrings = Languages;\r
-  while (*LangStrings != 0) {\r
-    HiiLibGetNextLanguage (&LangStrings, Lang);\r
+    //\r
+    // If StringId is 0, then call NewString().  Otherwise, call SetString()\r
+    //\r
+    if (StringId == (EFI_STRING_ID)(0)) {\r
+      Status = gHiiString->NewString (gHiiString, HiiHandle, &StringId, Language, NULL, String, NULL);\r
+    } else {\r
+      Status = gHiiString->SetString (gHiiString, HiiHandle, StringId, Language, String, NULL);\r
+    }\r
 \r
     //\r
-    // For each language supported by the package,\r
-    // the string is updated.\r
+    // If there was an error, then break out of the loop and return a StringId of 0\r
     //\r
-    Status = gHiiString->SetString (\r
-                                 gHiiString,\r
-                                 PackageList,\r
-                                 StringId,\r
-                                 Lang,\r
-                                 String,\r
-                                 NULL\r
-                                 );\r
     if (EFI_ERROR (Status)) {\r
       break;\r
     }\r
   }\r
 \r
-  FreePool (Lang);\r
-  FreePool (Languages);\r
+  //\r
+  // Free the buffer of supported languages\r
+  //\r
+  FreePool (AllocatedLanguages);\r
 \r
-  return Status;\r
+  if (EFI_ERROR (Status)) {\r
+    return (EFI_STRING_ID)(0);\r
+  } else {\r
+    return StringId;\r
+  }\r
 }\r
 \r
 \r
 /**\r
-  Get the string given the StringId and String package Producer's Guid. The caller\r
-  is responsible to free the *String.\r
-\r
-  If PackageList with the matching ProducerGuid is not found, then ASSERT.\r
-  If PackageList with the matching ProducerGuid is found but no String is\r
-  specified by StringId is found, then ASSERT.\r
-\r
-  @param  ProducerGuid           The Guid of String package list.\r
-  @param  StringId               The String ID.\r
-  @param  String                 The output string.\r
-\r
-  @retval EFI_SUCCESS            Operation is successful.\r
-  @retval EFI_OUT_OF_RESOURCES   There is not enought memory in the system.\r
+  Retrieves a string from a string package names by GUID in a specific language.  \r
+  If the language is not specified, then a string from a string package in the \r
+  current platform  language is retrieved.  If the string can not be retrieved \r
+  using the specified language or the current platform language, then the string \r
+  is retrieved from the string package in the first language the string package \r
+  supports.  The returned string is allocated using AllocatePool().  The caller \r
+  is responsible for freeing the allocated buffer using FreePool().\r
+  \r
+  If PackageListGuid is NULL, then ASSERT().\r
+  If StringId is 0, then ASSERT.\r
+\r
+  @param[in]  PackageListGuid  The GUID of a package list that was previously \r
+                               registered in the HII Database.\r
+  @param[in]  StringId         The identifier of the string to retrieved from the \r
+                               string package associated with PackageListGuid.\r
+  @param[in]  Language         The language of the string to retrieve.  If this \r
+                               parameter is NULL, then the current platform \r
+                               language is used.  The format of Language must \r
+                               follow the language format assumed the HII Database.\r
+\r
+  @retval NULL   The package list specified by PackageListGuid is not present in the\r
+                 HII Database.\r
+  @retval NULL   The string specified by StringId is not present in the string package.\r
+  @retval Other  The string was returned.\r
 \r
 **/\r
-EFI_STATUS\r
+EFI_STRING\r
 EFIAPI\r
-HiiLibGetStringFromToken (\r
-  IN  EFI_GUID                        *ProducerGuid,\r
-  IN  EFI_STRING_ID                   StringId,\r
-  OUT EFI_STRING                      *String\r
+HiiGetPackageString (\r
+  IN CONST EFI_GUID  *PackageListGuid,\r
+  IN EFI_STRING_ID   StringId,\r
+  IN CONST CHAR8     *Language  OPTIONAL\r
   )\r
 {\r
-  EFI_STATUS      Status;\r
-  UINTN           Index;\r
-  UINTN           HandleBufferLen;\r
-  EFI_HII_HANDLE  *HiiHandleBuffer;\r
-  EFI_GUID        Guid;\r
+  EFI_HANDLE  *HiiHandleBuffer;\r
+  EFI_HANDLE  HiiHandle;\r
 \r
-  Status = HiiLibGetHiiHandles (&HandleBufferLen, &HiiHandleBuffer);\r
-  if (HiiHandleBuffer == NULL) {\r
-    return EFI_NOT_FOUND;\r
-  }\r
-  for (Index = 0; Index < (HandleBufferLen / sizeof (EFI_HII_HANDLE)); Index++) {\r
-    Status = HiiLibExtractGuidFromHiiHandle (HiiHandleBuffer[Index], &Guid);\r
-    if (EFI_ERROR(Status)) {\r
-      return Status;\r
-    }\r
-    if (CompareGuid (&Guid, ProducerGuid)) {\r
-      break;\r
-    }\r
-  }\r
+  ASSERT (PackageListGuid != NULL);\r
 \r
-  if (Index >= (HandleBufferLen / sizeof (EFI_HII_HANDLE))) {\r
-    //\r
-    // If PackageList with the matching ProducerGuid is not found, then ASSERT.\r
-    //\r
-    ASSERT (FALSE);\r
-    Status = EFI_NOT_FOUND;\r
-    goto Out;\r
+  HiiHandleBuffer = HiiGetHiiHandles (PackageListGuid);\r
+  if (HiiHandleBuffer == NULL) {\r
+    return NULL;\r
   }\r
 \r
-  Status = HiiLibGetStringFromHandle (HiiHandleBuffer[Index], StringId, String);\r
-\r
-Out:\r
+  HiiHandle = HiiHandleBuffer[0];\r
   FreePool (HiiHandleBuffer);\r
 \r
-  return Status;\r
+  return HiiGetString (HiiHandle, StringId, Language);\r
 }\r
 \r
 /**\r
-  This function try to retrieve string from String package of current language.\r
-  If fails, it try to retrieve string from String package of first language it support.\r
-\r
-  If StringSize is NULL, then ASSERT.\r
-  If String is NULL and *StringSize is not 0, then ASSERT.\r
-  If PackageList could not be found in the default HII database, then ASSERT.\r
-  If StringId is not found in PackageList, then ASSERT.\r
-\r
-  @param  PackageList     The package list in the HII database to search for\r
-                                     the specified string.\r
-  @param  StringId          The string's id, which is unique within\r
-                                      PackageList.\r
-  @param  String             Points to the new null-terminated string.\r
-  @param  StringSize       On entry, points to the size of the buffer pointed\r
-                                 to by String, in bytes. On return, points to the\r
-                                 length of the string, in bytes.\r
-\r
-  @retval EFI_SUCCESS            The string was returned successfully.\r
-  @retval EFI_NOT_FOUND          The string specified by StringId is not available.\r
-  @retval EFI_BUFFER_TOO_SMALL   The buffer specified by StringLength is too small\r
-                                 to hold the string.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-HiiLibGetString (\r
-  IN  EFI_HII_HANDLE                  PackageList,\r
-  IN  EFI_STRING_ID                   StringId,\r
-  OUT EFI_STRING                      String,\r
-  IN  OUT UINTN                       *StringSize\r
-  )\r
-{\r
-  EFI_STATUS  Status;\r
-  CHAR8       *Languages;\r
-  CHAR8       *CurrentLang;\r
-  CHAR8       *BestLanguage;\r
-\r
-  ASSERT (StringSize != NULL);\r
-  ASSERT (!(*StringSize != 0 && String == NULL));\r
-  ASSERT (IsHiiHandleRegistered (PackageList));\r
-\r
-  Languages = HiiLibGetSupportedLanguages (PackageList);\r
-  ASSERT (Languages != NULL);\r
-\r
-  CurrentLang = GetEfiGlobalVariable (L"PlatformLang");\r
+  Retrieves a string from a string package in a specific language.  If the language\r
+  is not specified, then a string from a string package in the current platform \r
+  language is retrieved.  If the string can not be retrieved using the specified \r
+  language or the current platform language, then the string is retrieved from \r
+  the string package in the first language the string package supports.  The \r
+  returned string is allocated using AllocatePool().  The caller is responsible \r
+  for freeing the allocated buffer using FreePool().\r
   \r
-  Status = EFI_NOT_FOUND;\r
-  BestLanguage = GetBestLanguage (\r
-                   Languages,\r
-                   FALSE,\r
-                   (CurrentLang != NULL) ? CurrentLang : "",\r
-                   (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang),\r
-                   Languages,\r
-                   NULL\r
-                   );\r
-  if (BestLanguage != NULL ) {\r
-     Status = gHiiString->GetString (\r
-                               gHiiString,\r
-                               BestLanguage,\r
-                               PackageList,\r
-                               StringId,\r
-                               String,\r
-                               StringSize,\r
-                               NULL\r
-                               );\r
-     FreePool (BestLanguage);\r
-  }\r
-  if (CurrentLang != NULL) {\r
-    FreePool (CurrentLang);\r
-  }\r
-  FreePool (Languages);\r
+  If HiiHandle is NULL, then ASSERT().\r
+  If StringId is 0, then ASSET.\r
 \r
-  return Status;\r
-}\r
-\r
-\r
-/**\r
-  Get string specified by StringId form the HiiHandle. The caller\r
-  is responsible to free the *String.\r
-\r
-  If String is NULL, then ASSERT.\r
-  If HiiHandle could not be found in the default HII database, then ASSERT.\r
-  If StringId is not found in PackageList, then ASSERT.\r
+  @param[in]  HiiHandle  A handle that was previously registered in the HII Database.\r
+  @param[in]  StringId   The identifier of the string to retrieved from the string \r
+                         package associated with HiiHandle.\r
+  @param[in]  Language   The language of the string to retrieve.  If this parameter \r
+                         is NULL, then the current platform language is used.  The \r
+                         format of Language must follow the language format assumed \r
+                         the HII Database.\r
 \r
-  @param  HiiHandle              The HII handle of package list.\r
-  @param  StringId               The String ID.\r
-  @param  String                 The output string.\r
-\r
-  @retval EFI_NOT_FOUND          String is not found.\r
-  @retval EFI_SUCCESS            Operation is successful.\r
-  @retval EFI_OUT_OF_RESOURCES   There is not enought memory in the system.\r
+  @retval NULL   The string specified by StringId is not present in the string package.\r
+  @retval Other  The string was returned.\r
 \r
 **/\r
-EFI_STATUS\r
+EFI_STRING\r
 EFIAPI\r
-HiiLibGetStringFromHandle (\r
-  IN  EFI_HII_HANDLE                  HiiHandle,\r
-  IN  EFI_STRING_ID                   StringId,\r
-  OUT EFI_STRING                      *String\r
+HiiGetString (\r
+  IN EFI_HII_HANDLE  HiiHandle,\r
+  IN EFI_STRING_ID   StringId,\r
+  IN CONST CHAR8     *Language  OPTIONAL\r
   )\r
 {\r
-  EFI_STATUS                          Status;\r
-  UINTN                               StringSize;\r
+  EFI_STATUS  Status;\r
+  UINTN       StringSize;\r
+  CHAR16      TempString;\r
+  EFI_STRING  String;\r
+  CHAR8       *SupportedLanguages;\r
+  CHAR8       *PlatformLanguage;\r
+  CHAR8       *BestLanguage;\r
 \r
-  ASSERT (String != NULL);\r
+  ASSERT (HiiHandle != NULL);\r
+  ASSERT (StringId != 0);\r
 \r
-  StringSize = HII_LIB_DEFAULT_STRING_SIZE;\r
-  *String    = AllocateZeroPool (StringSize);\r
-  if (*String == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
+  //\r
+  // Initialize all allocated buffers to NULL\r
+  // \r
+  SupportedLanguages = NULL;\r
+  PlatformLanguage   = NULL;\r
+  BestLanguage       = NULL;\r
+  String             = NULL;\r
 \r
-  Status = HiiLibGetString (HiiHandle, StringId, *String, &StringSize);\r
-  if (Status == EFI_BUFFER_TOO_SMALL) {\r
-    FreePool (*String);\r
-    *String = AllocateZeroPool (StringSize);\r
-    if (*String == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-    Status = HiiLibGetString (HiiHandle, StringId, *String, &StringSize);\r
+  //\r
+  // Get the languages that the package specified by HiiHandle supports\r
+  //\r
+  SupportedLanguages = HiiGetSupportedLanguages (HiiHandle);\r
+  if (SupportedLanguages == NULL) {\r
+    goto Error;\r
   }\r
 \r
-  return Status;\r
-}\r
-\r
-\r
-\r
-/**\r
-  Convert language code from RFC3066 to ISO639-2.\r
-\r
-  @param  LanguageRfc3066        RFC3066 language code.\r
-  @param  LanguageIso639         ISO639-2 language code.\r
-\r
-  @retval EFI_SUCCESS            Language code converted.\r
-  @retval EFI_NOT_FOUND          Language code not found.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-ConvertRfc3066LanguageToIso639Language (\r
-  IN  CHAR8   *LanguageRfc3066,\r
-  OUT CHAR8   *LanguageIso639\r
-  )\r
-{\r
-  UINTN  Index;\r
+  //\r
+  // Get the current platform language setting\r
+  //\r
+  GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatformLanguage, NULL);\r
 \r
-  if ((LanguageRfc3066[2] != '-') && (LanguageRfc3066[2] != 0)) {\r
-    CopyMem (LanguageIso639, LanguageRfc3066, 3);\r
-    return EFI_SUCCESS;\r
+  //\r
+  // If Languag is NULL, then set it to an empty string, so it will be \r
+  // skipped by GetBestLanguage()\r
+  //\r
+  if (Language == NULL) {\r
+    Language = "";\r
   }\r
 \r
-  for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) {\r
-    if (CompareMem (LanguageRfc3066, &Iso639ToRfc3066ConversionTable[Index + 3], 2) == 0) {\r
-      CopyMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3);\r
-      return EFI_SUCCESS;\r
-    }\r
+  //\r
+  // Get the best matching language from SupportedLanguages\r
+  //\r
+  BestLanguage = GetBestLanguage (\r
+                   SupportedLanguages, \r
+                   FALSE,                                             // RFC 4646 mode\r
+                   Language,                                          // Highest priority \r
+                   PlatformLanguage != NULL ? PlatformLanguage : "",  // Next highest priority\r
+                   SupportedLanguages,                                // Lowest priority \r
+                   NULL\r
+                   );\r
+  if (BestLanguage == NULL) {\r
+    goto Error;\r
   }\r
 \r
-  return EFI_NOT_FOUND;\r
-}\r
-\r
-\r
-/**\r
-  Convert language code from ISO639-2 to RFC3066 and return the converted language.\r
-  Caller is responsible for freeing the allocated buffer.\r
-\r
-  LanguageIso639 contain a single ISO639-2 code such as\r
-  "eng" or "fra".\r
-\r
-  If LanguageIso639 is NULL, then ASSERT.\r
-  If LanguageRfc3066 is NULL, then ASSERT.\r
-\r
-  @param  LanguageIso639         ISO639-2 language code.\r
-\r
-  @return the allocated buffer or NULL, if the language is not found.\r
-\r
-**/\r
-CHAR8*\r
-EFIAPI\r
-ConvertIso639LanguageToRfc3066Language (\r
-  IN  CONST CHAR8   *LanguageIso639\r
-  )\r
-{\r
-  UINTN Index;\r
-  CHAR8 *Rfc3066Language;\r
-  \r
-  for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) {\r
-    if (CompareMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3) == 0) {\r
-      Rfc3066Language = AllocateZeroPool (3);\r
-      if (Rfc3066Language != NULL) {\r
-        Rfc3066Language = CopyMem (Rfc3066Language, &Iso639ToRfc3066ConversionTable[Index + 3], 2);\r
-      }\r
-      return Rfc3066Language;\r
-    }\r
+  //\r
+  // Retrieve the size of the string in the string package for the BestLanguage\r
+  //\r
+  StringSize = 0;\r
+  Status = gHiiString->GetString (\r
+                         gHiiString,\r
+                         BestLanguage,\r
+                         HiiHandle,\r
+                         StringId,\r
+                         &TempString,\r
+                         &StringSize,\r
+                         NULL\r
+                         );\r
+  //\r
+  // If GetString() returns EFI_SUCCESS for a zero size, \r
+  // then there are no supported languages registered for HiiHandle.  If GetString() \r
+  // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present\r
+  // in the HII Database\r
+  //\r
+  if (Status != EFI_BUFFER_TOO_SMALL) {\r
+    goto Error;\r
   }\r
 \r
-  return NULL;\r
-}\r
-\r
-/**\r
-  Convert language code list from RFC3066 to ISO639-2, e.g. "en-US;fr-FR" will\r
-  be converted to "engfra".\r
-\r
-  @param  SupportedLanguages     The RFC3066 language list.\r
-\r
-  @return The ISO639-2 language list.\r
-\r
-**/\r
-CHAR8 *\r
-EFIAPI\r
-Rfc3066ToIso639 (\r
-  CHAR8  *SupportedLanguages\r
-  )\r
-{\r
-  CHAR8       *Languages;\r
-  CHAR8       *ReturnValue;\r
-  CHAR8       *LangCodes;\r
-  CHAR8       *LangRfc3066;\r
-  CHAR8       LangIso639[ISO_639_2_ENTRY_SIZE];\r
-  UINTN       LanguageSize;\r
-  EFI_STATUS  Status;\r
+  //\r
+  // Allocate a buffer for the return string\r
+  //\r
+  String = AllocateZeroPool (StringSize);\r
+  if (String == NULL) {\r
+    goto Error;\r
+  }\r
 \r
-  LanguageSize = AsciiStrSize (SupportedLanguages);\r
-  ReturnValue = AllocateZeroPool (LanguageSize);\r
-  if (ReturnValue == NULL) {\r
-    return ReturnValue;\r
+  //\r
+  // Retrieve the string from the string package\r
+  //\r
+  Status = gHiiString->GetString (\r
+                         gHiiString,\r
+                         BestLanguage,\r
+                         HiiHandle,\r
+                         StringId,\r
+                         String,\r
+                         &StringSize,\r
+                         NULL\r
+                         );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Free the buffer and return NULL if the supported languages can not be retrieved.\r
+    //\r
+    FreePool (String);\r
+    String = NULL;\r
   }\r
 \r
+Error:\r
   //\r
-  // Allocate working buffer to contain substring in SupportedLanguages;\r
+  // Free allocated buffers\r
   //\r
-  LangRfc3066 = AllocatePool (LanguageSize);\r
-  if (LangRfc3066 == NULL) {\r
-    FreePool (ReturnValue);\r
-    return NULL;\r
+  if (SupportedLanguages != NULL) {\r
+    FreePool (SupportedLanguages);\r
   }\r
-  Languages = ReturnValue;\r
-  LangCodes = SupportedLanguages;\r
-  while (*LangCodes != 0) {\r
-    HiiLibGetNextLanguage (&LangCodes, LangRfc3066);\r
-\r
-    Status = ConvertRfc3066LanguageToIso639Language (LangRfc3066, LangIso639);\r
-    if (!EFI_ERROR (Status)) {\r
-      CopyMem (Languages, LangIso639, 3);\r
-      Languages = Languages + 3;\r
-    }\r
+  if (PlatformLanguage != NULL) {\r
+    FreePool (PlatformLanguage);\r
+  }\r
+  if (BestLanguage != NULL) {\r
+    FreePool (BestLanguage);\r
   }\r
 \r
-  FreePool (LangRfc3066);\r
-  return ReturnValue;\r
+  //\r
+  // Return the Null-terminated Unicode string\r
+  //\r
+  return String;\r
 }\r
 \r
-\r