mirror of https://github.com/acidanthera/audk.git
Apply GetBestLanguage() for the implementation of HiiStringIdToImage() API.
E.g. L"PlatformLang" variable is "en" and registered string supports "en-US" git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7954 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
2fef9e5f7a
commit
bf9af1b959
|
@ -2089,12 +2089,17 @@ HiiStringIdToImage (
|
|||
{
|
||||
EFI_STATUS Status;
|
||||
HII_DATABASE_PRIVATE_DATA *Private;
|
||||
EFI_HII_STRING_PROTOCOL *HiiString;
|
||||
EFI_STRING String;
|
||||
UINTN StringSize;
|
||||
UINTN FontLen;
|
||||
EFI_FONT_INFO *StringFontInfo;
|
||||
EFI_FONT_DISPLAY_INFO *NewStringInfo;
|
||||
CHAR8 CurrentLang[RFC_3066_ENTRY_SIZE];
|
||||
CHAR8 TempSupportedLanguages;
|
||||
CHAR8 *SupportedLanguages;
|
||||
UINTN SupportedLanguagesSize;
|
||||
CHAR8 *CurrentLanguage;
|
||||
CHAR8 *BestLanguage;
|
||||
|
||||
if (This == NULL || PackageList == NULL || Blt == NULL || PackageList == NULL) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
|
@ -2105,57 +2110,104 @@ HiiStringIdToImage (
|
|||
}
|
||||
|
||||
//
|
||||
// When Language points to NULL, current system language is used.
|
||||
// Initialize string pointers to be NULL
|
||||
//
|
||||
if (Language != NULL) {
|
||||
AsciiStrCpy (CurrentLang, (CHAR8 *) Language);
|
||||
} else {
|
||||
GetCurrentLanguage (CurrentLang);
|
||||
}
|
||||
SupportedLanguages = NULL;
|
||||
CurrentLanguage = NULL;
|
||||
BestLanguage = NULL;
|
||||
String = NULL;
|
||||
StringInfo = NULL;
|
||||
StringFontInfo = NULL;
|
||||
NewStringInfo = NULL;
|
||||
|
||||
//
|
||||
// Get the string to be displayed.
|
||||
//
|
||||
Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
|
||||
HiiString = &Private->HiiString;
|
||||
|
||||
StringSize = MAX_STRING_LENGTH;
|
||||
String = (EFI_STRING) AllocateZeroPool (StringSize);
|
||||
if (String == NULL) {
|
||||
//
|
||||
// Get the size of supported language.
|
||||
//
|
||||
SupportedLanguagesSize = 0;
|
||||
Status = HiiString->GetLanguages (
|
||||
HiiString,
|
||||
PackageList,
|
||||
&TempSupportedLanguages,
|
||||
&SupportedLanguagesSize
|
||||
);
|
||||
if (Status != EFI_BUFFER_TOO_SMALL) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
SupportedLanguages = AllocatePool (SupportedLanguagesSize);
|
||||
if (SupportedLanguages == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
|
||||
StringFontInfo = NULL;
|
||||
NewStringInfo = NULL;
|
||||
|
||||
Status = Private->HiiString.GetString (
|
||||
&Private->HiiString,
|
||||
CurrentLang,
|
||||
PackageList,
|
||||
StringId,
|
||||
String,
|
||||
&StringSize,
|
||||
&StringFontInfo
|
||||
);
|
||||
Status = HiiString->GetLanguages (
|
||||
HiiString,
|
||||
PackageList,
|
||||
SupportedLanguages,
|
||||
&SupportedLanguagesSize
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
if (Language == NULL) {
|
||||
Language = "";
|
||||
}
|
||||
CurrentLanguage = GetEfiGlobalVariable (L"PlatformLang");
|
||||
BestLanguage = GetBestLanguage (
|
||||
SupportedLanguages,
|
||||
FALSE,
|
||||
Language,
|
||||
(CurrentLanguage == NULL) ? CurrentLanguage : "",
|
||||
(CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang),
|
||||
NULL
|
||||
);
|
||||
if (BestLanguage == NULL) {
|
||||
Status = EFI_NOT_FOUND;
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
StringSize = MAX_STRING_LENGTH;
|
||||
String = (EFI_STRING) AllocateZeroPool (StringSize);
|
||||
if (String == NULL) {
|
||||
Status = EFI_OUT_OF_RESOURCES;
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
Status = HiiString->GetString (
|
||||
HiiString,
|
||||
BestLanguage,
|
||||
PackageList,
|
||||
StringId,
|
||||
String,
|
||||
&StringSize,
|
||||
&StringFontInfo
|
||||
);
|
||||
if (Status == EFI_BUFFER_TOO_SMALL) {
|
||||
FreePool (String);
|
||||
String = (EFI_STRING) AllocateZeroPool (StringSize);
|
||||
if (String == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
Status = EFI_OUT_OF_RESOURCES;
|
||||
goto Exit;
|
||||
}
|
||||
Status = Private->HiiString.GetString (
|
||||
&Private->HiiString,
|
||||
Language,
|
||||
PackageList,
|
||||
StringId,
|
||||
String,
|
||||
&StringSize,
|
||||
NULL
|
||||
);
|
||||
|
||||
Status = HiiString->GetString (
|
||||
HiiString,
|
||||
BestLanguage,
|
||||
PackageList,
|
||||
StringId,
|
||||
String,
|
||||
&StringSize,
|
||||
NULL
|
||||
);
|
||||
}
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto Exit;
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -2204,6 +2256,15 @@ HiiStringIdToImage (
|
|||
);
|
||||
|
||||
Exit:
|
||||
if (SupportedLanguages != NULL) {
|
||||
FreePool (SupportedLanguages);
|
||||
}
|
||||
if (CurrentLanguage != NULL) {
|
||||
FreePool (CurrentLanguage);
|
||||
}
|
||||
if (BestLanguage != NULL) {
|
||||
FreePool (BestLanguage);
|
||||
}
|
||||
if (String != NULL) {
|
||||
FreePool (String);
|
||||
}
|
||||
|
|
|
@ -57,49 +57,4 @@ R8_EfiLibCompareLanguage (
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
Determine what is the current language setting. The space reserved for Lang
|
||||
must be at least RFC_3066_ENTRY_SIZE bytes;
|
||||
|
||||
If Lang is NULL, then ASSERT.
|
||||
|
||||
@param Lang Pointer of system language. Lang will always be filled with
|
||||
a valid RFC 3066 language string. If "PlatformLang" is not
|
||||
set in the system, the default language specifed by PcdUefiVariableDefaultPlatformLang
|
||||
is returned.
|
||||
|
||||
@return EFI_SUCCESS If the EFI Variable with "PlatformLang" is set and return in Lang.
|
||||
@return EFI_NOT_FOUND If the EFI Variable with "PlatformLang" is not set, but a valid default language is return in Lang.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GetCurrentLanguage (
|
||||
OUT CHAR8 *Lang
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Size;
|
||||
|
||||
ASSERT (Lang != NULL);
|
||||
|
||||
//
|
||||
// Get current language setting
|
||||
//
|
||||
Size = RFC_3066_ENTRY_SIZE;
|
||||
Status = gRT->GetVariable (
|
||||
L"PlatformLang",
|
||||
&gEfiGlobalVariableGuid,
|
||||
NULL,
|
||||
&Size,
|
||||
Lang
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
AsciiStrCpy (Lang, (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang));
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,27 +34,6 @@ R8_EfiLibCompareLanguage (
|
|||
)
|
||||
;
|
||||
|
||||
/**
|
||||
Determine what is the current language setting. The space reserved for Lang
|
||||
must be at least RFC_3066_ENTRY_SIZE bytes;
|
||||
|
||||
If Lang is NULL, then ASSERT.
|
||||
|
||||
@param Lang Pointer of system language. Lang will always be filled with
|
||||
a valid RFC 3066 language string. If "PlatformLang" is not
|
||||
set in the system, the default language specifed by PcdUefiVariableDefaultPlatformLang
|
||||
is returned.
|
||||
|
||||
@return EFI_SUCCESS If the EFI Variable with "PlatformLang" is set and return in Lang.
|
||||
@return EFI_NOT_FOUND If the EFI Variable with "PlatformLang" is not set, but a valid default language is return in Lang.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GetCurrentLanguage (
|
||||
OUT CHAR8 *Lang
|
||||
);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue