3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
25 // Include common header file for this module.
27 #include "CommonHeader.h"
29 #include "BdsString.h"
33 // Default language code, currently is English
35 CHAR8
*mDefaultLangCode
= "eng";
40 BOOLEAN LangCodesSettingRequired
45 Determine the current language that will be used
46 based on language related EFI Variables
49 LangCodesSettingRequired - If required to set LangCode variable
58 CHAR8 LangCode
[ISO_639_2_ENTRY_SIZE
];
60 CHAR16
*LanguageString
;
62 LanguageString
= NULL
;
66 // Collect the languages from what our current Language support is based on our VFR
68 gHii
->GetPrimaryLanguages (gHii
, gStringPackHandle
, &LanguageString
);
70 LangCodes
= AllocatePool (StrLen (LanguageString
));
74 // Convert LanguageString from Unicode to EFI defined ASCII LangCodes
76 for (Index
= 0; LanguageString
[Index
] != 0x0000; Index
++) {
77 LangCodes
[Index
] = (CHAR8
) LanguageString
[Index
];
82 if (LangCodesSettingRequired
) {
83 Status
= gRT
->SetVariable (
85 &gEfiGlobalVariableGuid
,
86 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
87 AsciiStrLen (LangCodes
),
92 // Find current LangCode from Lang NV Variable
94 Size
= ISO_639_2_ENTRY_SIZE
;
95 Status
= gRT
->GetVariable (
97 &gEfiGlobalVariableGuid
,
103 if (!EFI_ERROR (Status
)) {
104 Status
= EFI_NOT_FOUND
;
105 for (Index
= 0; LangCodes
[Index
] != 0; Index
+= ISO_639_2_ENTRY_SIZE
) {
106 if (CompareMem (&LangCodes
[Index
], LangCode
, ISO_639_2_ENTRY_SIZE
) == 0) {
107 Status
= EFI_SUCCESS
;
113 // If we cannot get language code from Lang variable,
114 // or LangCode cannot be found from language table,
115 // set the mDefaultLangCode to Lang variable.
117 if (EFI_ERROR (Status
)) {
118 Status
= gRT
->SetVariable (
120 &gEfiGlobalVariableGuid
,
121 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
122 ISO_639_2_ENTRY_SIZE
,
128 FreePool (LangCodes
);
131 if (LanguageString
!= NULL
) {
132 FreePool (LanguageString
);