mirror of https://github.com/acidanthera/audk.git
Apply GetBestLanguage() API in UEFI to display HII string.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7964 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
a3a795afdb
commit
ea7cd3ec1a
|
@ -473,29 +473,24 @@ ConvertRfc3066LanguageToIso639Language (
|
|||
;
|
||||
|
||||
/**
|
||||
Convert language code from ISO639-2 to RFC3066.
|
||||
Convert language code from ISO639-2 to RFC3066 and return the converted language.
|
||||
Caller is responsible for freeing the allocated buffer.
|
||||
|
||||
LanguageIso639 contain a single ISO639-2 code such as
|
||||
"eng" or "fra".
|
||||
|
||||
The LanguageRfc3066 must be a buffer large enough
|
||||
for RFC_3066_ENTRY_SIZE characters.
|
||||
|
||||
If LanguageIso639 is NULL, then ASSERT.
|
||||
If LanguageRfc3066 is NULL, then ASSERT.
|
||||
|
||||
@param LanguageIso639 ISO639-2 language code.
|
||||
@param LanguageRfc3066 RFC3066 language code.
|
||||
|
||||
@retval EFI_SUCCESS Language code converted.
|
||||
@retval EFI_NOT_FOUND Language code not found.
|
||||
@return the allocated buffer or NULL, if the language is not found.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
CHAR8*
|
||||
EFIAPI
|
||||
ConvertIso639LanguageToRfc3066Language (
|
||||
IN CONST CHAR8 *LanguageIso639,
|
||||
OUT CHAR8 *LanguageRfc3066
|
||||
IN CONST CHAR8 *LanguageIso639
|
||||
)
|
||||
;
|
||||
|
||||
|
@ -517,27 +512,4 @@ Rfc3066ToIso639 (
|
|||
)
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
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
|
||||
|
|
|
@ -130,7 +130,7 @@ HiiLibGetSupportedLanguageNumber (
|
|||
CHAR8 *Languages;
|
||||
CHAR8 *LanguageString;
|
||||
UINT16 LangNumber;
|
||||
CHAR8 Lang[RFC_3066_ENTRY_SIZE];
|
||||
CHAR8 *Lang;
|
||||
|
||||
Languages = HiiLibGetSupportedLanguages (HiiHandle);
|
||||
if (Languages == NULL) {
|
||||
|
@ -138,10 +138,15 @@ HiiLibGetSupportedLanguageNumber (
|
|||
}
|
||||
|
||||
LangNumber = 0;
|
||||
LanguageString = Languages;
|
||||
while (*LanguageString != 0) {
|
||||
HiiLibGetNextLanguage (&LanguageString, Lang);
|
||||
LangNumber++;
|
||||
Lang = AllocatePool (AsciiStrSize (Languages));
|
||||
if (Lang != NULL) {
|
||||
LanguageString = Languages;
|
||||
while (*LanguageString != 0) {
|
||||
HiiLibGetNextLanguage (&LanguageString, Lang);
|
||||
LangNumber++;
|
||||
}
|
||||
|
||||
FreePool (Lang);
|
||||
}
|
||||
FreePool (Languages);
|
||||
|
||||
|
@ -204,50 +209,4 @@ HiiLibGetSupportedSecondaryLanguages (
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -191,7 +191,7 @@ HiiLibNewString (
|
|||
EFI_STATUS Status;
|
||||
CHAR8 *Languages;
|
||||
CHAR8 *LangStrings;
|
||||
CHAR8 Lang[RFC_3066_ENTRY_SIZE];
|
||||
CHAR8 *Lang;
|
||||
|
||||
ASSERT (String != NULL);
|
||||
ASSERT (StringId != NULL);
|
||||
|
@ -200,6 +200,11 @@ HiiLibNewString (
|
|||
|
||||
Languages = HiiLibGetSupportedLanguages (PackageList);
|
||||
ASSERT (Languages != NULL);
|
||||
//
|
||||
// Allocate working buffer to contain substring of Languages.
|
||||
//
|
||||
Lang = AllocatePool (AsciiStrSize (Languages));
|
||||
ASSERT (Lang != NULL);
|
||||
|
||||
LangStrings = Languages;
|
||||
while (*LangStrings != 0) {
|
||||
|
@ -223,6 +228,7 @@ HiiLibNewString (
|
|||
}
|
||||
}
|
||||
|
||||
FreePool (Lang);
|
||||
FreePool (Languages);
|
||||
|
||||
return Status;
|
||||
|
@ -258,7 +264,7 @@ HiiLibSetString (
|
|||
EFI_STATUS Status;
|
||||
CHAR8 *Languages;
|
||||
CHAR8 *LangStrings;
|
||||
CHAR8 Lang[RFC_3066_ENTRY_SIZE];
|
||||
CHAR8 *Lang;
|
||||
|
||||
ASSERT (IsHiiHandleRegistered (PackageList));
|
||||
|
||||
|
@ -267,6 +273,12 @@ HiiLibSetString (
|
|||
Languages = HiiLibGetSupportedLanguages (PackageList);
|
||||
ASSERT (Languages != NULL);
|
||||
|
||||
//
|
||||
// Allocate working buffer to contain substring of Languages.
|
||||
//
|
||||
Lang = AllocatePool (AsciiStrSize (Languages));
|
||||
ASSERT (Lang != NULL);
|
||||
|
||||
LangStrings = Languages;
|
||||
while (*LangStrings != 0) {
|
||||
HiiLibGetNextLanguage (&LangStrings, Lang);
|
||||
|
@ -288,6 +300,7 @@ HiiLibSetString (
|
|||
}
|
||||
}
|
||||
|
||||
FreePool (Lang);
|
||||
FreePool (Languages);
|
||||
|
||||
return Status;
|
||||
|
@ -390,44 +403,43 @@ HiiLibGetString (
|
|||
{
|
||||
EFI_STATUS Status;
|
||||
CHAR8 *Languages;
|
||||
CHAR8 *LangStrings;
|
||||
CHAR8 Lang[RFC_3066_ENTRY_SIZE];
|
||||
CHAR8 CurrentLang[RFC_3066_ENTRY_SIZE];
|
||||
CHAR8 *CurrentLang;
|
||||
CHAR8 *BestLanguage;
|
||||
|
||||
ASSERT (StringSize != NULL);
|
||||
ASSERT (!(*StringSize != 0 && String == NULL));
|
||||
ASSERT (IsHiiHandleRegistered (PackageList));
|
||||
|
||||
GetCurrentLanguage (CurrentLang);
|
||||
Languages = HiiLibGetSupportedLanguages (PackageList);
|
||||
ASSERT (Languages != NULL);
|
||||
|
||||
Status = mHiiStringProt->GetString (
|
||||
CurrentLang = GetEfiGlobalVariable (L"PlatformLang");
|
||||
|
||||
Status = EFI_NOT_FOUND;
|
||||
BestLanguage = GetBestLanguage (
|
||||
Languages,
|
||||
FALSE,
|
||||
(CurrentLang != NULL) ? CurrentLang : "",
|
||||
(CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang),
|
||||
Languages,
|
||||
NULL
|
||||
);
|
||||
if (BestLanguage != NULL ) {
|
||||
Status = mHiiStringProt->GetString (
|
||||
mHiiStringProt,
|
||||
CurrentLang,
|
||||
BestLanguage,
|
||||
PackageList,
|
||||
StringId,
|
||||
String,
|
||||
StringSize,
|
||||
NULL
|
||||
);
|
||||
|
||||
if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
|
||||
Languages = HiiLibGetSupportedLanguages (PackageList);
|
||||
ASSERT (Languages != NULL);
|
||||
|
||||
LangStrings = Languages;
|
||||
HiiLibGetNextLanguage (&LangStrings, Lang);
|
||||
FreePool (Languages);
|
||||
|
||||
Status = mHiiStringProt->GetString (
|
||||
mHiiStringProt,
|
||||
Lang,
|
||||
PackageList,
|
||||
StringId,
|
||||
String,
|
||||
StringSize,
|
||||
NULL
|
||||
);
|
||||
FreePool (BestLanguage);
|
||||
}
|
||||
if (CurrentLang != NULL) {
|
||||
FreePool (CurrentLang);
|
||||
}
|
||||
FreePool (Languages);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
@ -520,41 +532,35 @@ ConvertRfc3066LanguageToIso639Language (
|
|||
|
||||
|
||||
/**
|
||||
Convert language code from ISO639-2 to RFC3066.
|
||||
Convert language code from ISO639-2 to RFC3066 and return the converted language.
|
||||
Caller is responsible for freeing the allocated buffer.
|
||||
|
||||
LanguageIso639 contain a single ISO639-2 code such as
|
||||
"eng" or "fra".
|
||||
|
||||
The LanguageRfc3066 must be a buffer large enough
|
||||
for RFC_3066_ENTRY_SIZE characters.
|
||||
|
||||
If LanguageIso639 is NULL, then ASSERT.
|
||||
If LanguageRfc3066 is NULL, then ASSERT.
|
||||
|
||||
@param LanguageIso639 ISO639-2 language code.
|
||||
@param LanguageRfc3066 RFC3066 language code.
|
||||
|
||||
@retval EFI_SUCCESS Language code converted.
|
||||
@retval EFI_NOT_FOUND Language code not found.
|
||||
@return the allocated buffer or NULL, if the language is not found.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
CHAR8*
|
||||
EFIAPI
|
||||
ConvertIso639LanguageToRfc3066Language (
|
||||
IN CONST CHAR8 *LanguageIso639,
|
||||
OUT CHAR8 *LanguageRfc3066
|
||||
IN CONST CHAR8 *LanguageIso639
|
||||
)
|
||||
{
|
||||
UINTN Index;
|
||||
|
||||
for (Index = 0; Iso639ToRfc3066ConversionTable[Index] != 0; Index += 5) {
|
||||
if (CompareMem (LanguageIso639, &Iso639ToRfc3066ConversionTable[Index], 3) == 0) {
|
||||
CopyMem (LanguageRfc3066, &Iso639ToRfc3066ConversionTable[Index + 3], 2);
|
||||
return EFI_SUCCESS;
|
||||
return AllocateCopyPool (2, &Iso639ToRfc3066ConversionTable[Index + 3]);
|
||||
}
|
||||
}
|
||||
|
||||
return EFI_NOT_FOUND;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -575,15 +581,25 @@ Rfc3066ToIso639 (
|
|||
CHAR8 *Languages;
|
||||
CHAR8 *ReturnValue;
|
||||
CHAR8 *LangCodes;
|
||||
CHAR8 LangRfc3066[RFC_3066_ENTRY_SIZE];
|
||||
CHAR8 *LangRfc3066;
|
||||
CHAR8 LangIso639[ISO_639_2_ENTRY_SIZE];
|
||||
UINTN LanguageSize;
|
||||
EFI_STATUS Status;
|
||||
|
||||
ReturnValue = AllocateZeroPool (AsciiStrSize (SupportedLanguages));
|
||||
LanguageSize = AsciiStrSize (SupportedLanguages);
|
||||
ReturnValue = AllocateZeroPool (LanguageSize);
|
||||
if (ReturnValue == NULL) {
|
||||
return ReturnValue;
|
||||
}
|
||||
|
||||
//
|
||||
// Allocate working buffer to contain substring in SupportedLanguages;
|
||||
//
|
||||
LangRfc3066 = AllocatePool (LanguageSize);
|
||||
if (LangRfc3066 == NULL) {
|
||||
FreePool (ReturnValue);
|
||||
return NULL;
|
||||
}
|
||||
Languages = ReturnValue;
|
||||
LangCodes = SupportedLanguages;
|
||||
while (*LangCodes != 0) {
|
||||
|
@ -596,6 +612,7 @@ Rfc3066ToIso639 (
|
|||
}
|
||||
}
|
||||
|
||||
FreePool (LangRfc3066);
|
||||
return ReturnValue;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue