2 Language related HII Library implementation.
4 Copyright (c) 2006, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "InternalHiiLib.h"
19 Determine what is the current language setting. The space reserved for Lang
20 must be at least RFC_3066_ENTRY_SIZE bytes;
22 If Lang is NULL, then ASSERT.
24 @param Lang Pointer of system language. Lang will always be filled with
25 a valid RFC 3066 language string. If "PlatformLang" is not
26 set in the system, the default language specifed by PcdUefiVariableDefaultPlatformLang
29 @return EFI_SUCCESS If the EFI Variable with "PlatformLang" is set and return in Lang.
30 @return EFI_NOT_FOUND If the EFI Variable with "PlatformLang" is not set, but a valid default language is return in Lang.
35 HiiLibGetCurrentLanguage (
42 ASSERT (Lang
!= NULL
);
45 // Get current language setting
47 Size
= RFC_3066_ENTRY_SIZE
;
48 Status
= gRT
->GetVariable (
50 &gEfiGlobalVariableGuid
,
56 if (EFI_ERROR (Status
)) {
57 AsciiStrCpy (Lang
, (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
));
65 Get next language from language code list (with separator ';').
67 If LangCode is NULL, then ASSERT.
68 If Lang is NULL, then ASSERT.
70 @param LangCode On input: point to first language in the list. On
71 output: point to next language in the list, or
72 NULL if no more language in the list.
73 @param Lang The first language in the list.
78 HiiLibGetNextLanguage (
79 IN OUT CHAR8
**LangCode
,
86 ASSERT (LangCode
!= NULL
);
87 ASSERT (Lang
!= NULL
);
90 StringPtr
= *LangCode
;
91 while (StringPtr
[Index
] != 0 && StringPtr
[Index
] != ';') {
95 CopyMem (Lang
, StringPtr
, Index
);
98 if (StringPtr
[Index
] == ';') {
101 *LangCode
= StringPtr
+ Index
;
106 This function returns the list of supported languages, in the format specified
107 in UEFI specification Appendix M.
109 If HiiHandle is not a valid Handle in the default HII database, then ASSERT.
111 @param HiiHandle The HII package list handle.
113 @retval !NULL The supported languages.
114 @retval NULL If Supported Languages can not be retrived.
119 HiiLibGetSupportedLanguages (
120 IN EFI_HII_HANDLE HiiHandle
125 CHAR8
*LanguageString
;
127 ASSERT (HiiHandle
!= NULL
);
128 ASSERT (IsHiiHandleRegistered (HiiHandle
));
130 // Collect current supported Languages for given HII handle
133 LanguageString
= AllocateZeroPool (BufferSize
);
134 if (LanguageString
== NULL
) {
138 LocateHiiProtocols ();
140 Status
= mHiiStringProt
->GetLanguages (mHiiStringProt
, HiiHandle
, LanguageString
, &BufferSize
);
142 if (Status
== EFI_BUFFER_TOO_SMALL
) {
143 gBS
->FreePool (LanguageString
);
144 LanguageString
= AllocateZeroPool (BufferSize
);
145 if (LanguageString
== NULL
) {
149 Status
= mHiiStringProt
->GetLanguages (mHiiStringProt
, HiiHandle
, LanguageString
, &BufferSize
);
152 if (EFI_ERROR (Status
)) {
153 LanguageString
= NULL
;
156 return LanguageString
;
161 This function returns the number of supported languages on HiiHandle.
163 If HiiHandle is not a valid Handle in the default HII database, then ASSERT.
164 If not enough resource to complete the operation, then ASSERT.
166 @param HiiHandle The HII package list handle.
168 @return The number of supported languages.
173 HiiLibGetSupportedLanguageNumber (
174 IN EFI_HII_HANDLE HiiHandle
178 CHAR8
*LanguageString
;
180 CHAR8 Lang
[RFC_3066_ENTRY_SIZE
];
182 Languages
= HiiLibGetSupportedLanguages (HiiHandle
);
183 if (Languages
== NULL
) {
188 LanguageString
= Languages
;
189 while (*LanguageString
!= 0) {
190 HiiLibGetNextLanguage (&LanguageString
, Lang
);
193 gBS
->FreePool (Languages
);
199 This function returns the list of supported 2nd languages, in the format specified
200 in UEFI specification Appendix M.
202 If HiiHandle is not a valid Handle in the default HII database, then ASSERT.
203 If not enough resource to complete the operation, then ASSERT.
205 @param HiiHandle The HII package list handle.
206 @param FirstLanguage Pointer to language name buffer.
208 @return The supported languages.
213 HiiLibGetSupportedSecondaryLanguages (
214 IN EFI_HII_HANDLE HiiHandle
,
215 IN CONST CHAR8
*FirstLanguage
220 CHAR8
*LanguageString
;
222 ASSERT (HiiHandle
!= NULL
);
223 ASSERT (IsHiiHandleRegistered (HiiHandle
));
225 // Collect current supported 2nd Languages for given HII handle
228 LanguageString
= AllocateZeroPool (BufferSize
);
229 if (LanguageString
== NULL
) {
233 LocateHiiProtocols ();
235 Status
= mHiiStringProt
->GetSecondaryLanguages (mHiiStringProt
, HiiHandle
, FirstLanguage
, LanguageString
, &BufferSize
);
237 if (Status
== EFI_BUFFER_TOO_SMALL
) {
238 gBS
->FreePool (LanguageString
);
239 LanguageString
= AllocateZeroPool (BufferSize
);
240 if (LanguageString
== NULL
) {
244 Status
= mHiiStringProt
->GetSecondaryLanguages (mHiiStringProt
, HiiHandle
, FirstLanguage
, LanguageString
, &BufferSize
);
247 if (EFI_ERROR (Status
)) {
248 LanguageString
= NULL
;
251 return LanguageString
;