Apply GetBestLanguage() API in UEFI

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@7963 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qhuang8 2009-03-27 03:21:37 +00:00
parent bda1bdbbf0
commit a3a795afdb
1 changed files with 85 additions and 31 deletions

View File

@ -129,10 +129,12 @@ FrontPageCallback (
{
CHAR8 *LanguageString;
CHAR8 *LangCode;
CHAR8 Lang[RFC_3066_ENTRY_SIZE];
CHAR8 *Lang;
CHAR8 OldLang[ISO_639_2_ENTRY_SIZE];
UINTN Index;
EFI_STATUS Status;
CHAR8 *PlatformSupportedLanguages;
CHAR8 *BestLanguage;
if ((Value == NULL) || (ActionRequest == NULL)) {
return EFI_INVALID_PARAMETER;
@ -158,6 +160,11 @@ FrontPageCallback (
//
LanguageString = HiiLibGetSupportedLanguages (gFrontPagePrivate.HiiHandle);
ASSERT (LanguageString != NULL);
//
// Allocate working buffer for RFC 4646 language in supported LanguageString.
//
Lang = AllocatePool (AsciiStrSize (LanguageString));
ASSERT (Lang != NULL);
Index = 0;
LangCode = LanguageString;
@ -171,30 +178,53 @@ FrontPageCallback (
Index++;
}
Status = gRT->SetVariable (
L"PlatformLang",
&gEfiGlobalVariableGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
AsciiStrSize (Lang),
Lang
);
if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
//
// Set UEFI deprecated variable "Lang" for backwards compatibility
//
Status = ConvertRfc3066LanguageToIso639Language (Lang, OldLang);
if (!EFI_ERROR (Status)) {
Status = gRT->SetVariable (
L"Lang",
&gEfiGlobalVariableGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
ISO_639_2_ENTRY_SIZE,
OldLang
);
}
PlatformSupportedLanguages = GetEfiGlobalVariable (L"PlatformLangCodes");
if (PlatformSupportedLanguages == NULL) {
PlatformSupportedLanguages = AllocateCopyPool (
AsciiStrSize ((CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes)),
(CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes)
);
ASSERT (PlatformSupportedLanguages != NULL);
}
//
// Select the best language in platform supported Language.
//
BestLanguage = GetBestLanguage (
PlatformSupportedLanguages,
FALSE,
Lang,
NULL
);
if (BestLanguage != NULL) {
Status = gRT->SetVariable (
L"PlatformLang",
&gEfiGlobalVariableGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
AsciiStrSize (BestLanguage),
Lang
);
if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate)) {
//
// Set UEFI deprecated variable "Lang" for backwards compatibility
//
Status = ConvertRfc3066LanguageToIso639Language (BestLanguage, OldLang);
if (!EFI_ERROR (Status)) {
Status = gRT->SetVariable (
L"Lang",
&gEfiGlobalVariableGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
ISO_639_2_ENTRY_SIZE,
OldLang
);
}
}
FreePool (BestLanguage);
}
FreePool (PlatformSupportedLanguages);
FreePool (Lang);
FreePool (LanguageString);
break;
@ -247,8 +277,9 @@ InitializeFrontPage (
IFR_OPTION *OptionList;
CHAR8 *LanguageString;
CHAR8 *LangCode;
CHAR8 Lang[RFC_3066_ENTRY_SIZE];
CHAR8 CurrentLang[RFC_3066_ENTRY_SIZE];
CHAR8 *Lang;
CHAR8 *CurrentLang;
CHAR8 *BestLanguage;
UINTN OptionCount;
EFI_STRING_ID Token;
CHAR16 *StringBuffer;
@ -329,10 +360,6 @@ InitializeFrontPage (
}
}
//
// Get current language setting
//
GetCurrentLanguage (CurrentLang);
//
// Allocate space for creation of UpdateData Buffer
@ -350,6 +377,28 @@ InitializeFrontPage (
HiiHandle = gFrontPagePrivate.HiiHandle;
LanguageString = HiiLibGetSupportedLanguages (HiiHandle);
ASSERT (LanguageString != NULL);
//
// Allocate working buffer for RFC 4646 language in supported LanguageString.
//
Lang = AllocatePool (AsciiStrSize (LanguageString));
ASSERT (Lang != NULL);
CurrentLang = GetEfiGlobalVariable (L"PlatformLang");
//
// Select the best language in LanguageString as the default one.
//
BestLanguage = GetBestLanguage (
LanguageString,
FALSE,
(CurrentLang != NULL) ? CurrentLang : "",
(CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang),
LanguageString,
NULL
);
//
// BestLanguage must be selected as it is the first language in LanguageString by default
//
ASSERT (BestLanguage != NULL);
OptionCount = 0;
LangCode = LanguageString;
@ -394,7 +443,7 @@ InitializeFrontPage (
Token = gFrontPagePrivate.LanguageToken[OptionCount];
}
if (AsciiStrCmp (Lang, CurrentLang) == 0) {
if (AsciiStrCmp (Lang, BestLanguage) == 0) {
OptionList[OptionCount].Flags = EFI_IFR_OPTION_DEFAULT;
} else {
OptionList[OptionCount].Flags = 0;
@ -405,6 +454,11 @@ InitializeFrontPage (
OptionCount++;
}
if (CurrentLang != NULL) {
FreePool (CurrentLang);
}
FreePool (BestLanguage);
FreePool (Lang);
FreePool (LanguageString);
UpdateData.Offset = 0;