]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c
Apply GetBestLanguage() API in UEFI
[mirror_edk2.git] / MdeModulePkg / Library / UefiHiiLib / HiiLanguage.c
CommitLineData
08e4b3cf 1/** @file\r
2 Language related HII Library implementation.\r
3\r
4 Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15\r
16#include "InternalHiiLib.h"\r
17\r
18/**\r
19 Get next language from language code list (with separator ';').\r
20\r
21 If LangCode is NULL, then ASSERT.\r
22 If Lang is NULL, then ASSERT.\r
23\r
24 @param LangCode On input: point to first language in the list. On\r
25 output: point to next language in the list, or\r
26 NULL if no more language in the list.\r
27 @param Lang The first language in the list.\r
28\r
29**/\r
30VOID\r
31EFIAPI\r
32HiiLibGetNextLanguage (\r
33 IN OUT CHAR8 **LangCode,\r
34 OUT CHAR8 *Lang\r
35 )\r
36{\r
37 UINTN Index;\r
38 CHAR8 *StringPtr;\r
39\r
40 ASSERT (LangCode != NULL);\r
41 ASSERT (*LangCode != NULL);\r
42 ASSERT (Lang != NULL);\r
43\r
44 Index = 0;\r
45 StringPtr = *LangCode;\r
46 while (StringPtr[Index] != 0 && StringPtr[Index] != ';') {\r
47 Index++;\r
48 }\r
49\r
50 CopyMem (Lang, StringPtr, Index);\r
51 Lang[Index] = 0;\r
52\r
53 if (StringPtr[Index] == ';') {\r
54 Index++;\r
55 }\r
56 *LangCode = StringPtr + Index;\r
57}\r
58\r
59\r
60/**\r
61 This function returns the list of supported languages, in the format specified\r
62 in UEFI specification Appendix M.\r
63\r
64 If HiiHandle is not a valid Handle in the default HII database, then ASSERT.\r
65\r
66 @param HiiHandle The HII package list handle.\r
67\r
68 @retval !NULL The supported languages.\r
69 @retval NULL If Supported Languages can not be retrived.\r
70\r
71**/\r
72CHAR8 *\r
73EFIAPI\r
74HiiLibGetSupportedLanguages (\r
75 IN EFI_HII_HANDLE HiiHandle\r
76 )\r
77{\r
78 EFI_STATUS Status;\r
79 UINTN BufferSize;\r
80 CHAR8 *LanguageString;\r
81\r
82 ASSERT (IsHiiHandleRegistered (HiiHandle));\r
83 //\r
84 // Collect current supported Languages for given HII handle\r
85 // First try allocate 4K buffer to store the current supported languages.\r
86 //\r
87 BufferSize = 0x1000;\r
88 LanguageString = AllocateZeroPool (BufferSize);\r
89 if (LanguageString == NULL) {\r
90 return NULL;\r
91 }\r
92\r
93 Status = mHiiStringProt->GetLanguages (mHiiStringProt, HiiHandle, LanguageString, &BufferSize);\r
94 \r
95 if (Status == EFI_BUFFER_TOO_SMALL) {\r
96 FreePool (LanguageString);\r
97 LanguageString = AllocateZeroPool (BufferSize);\r
98 if (LanguageString == NULL) {\r
99 return NULL;\r
100 }\r
101\r
102 Status = mHiiStringProt->GetLanguages (mHiiStringProt, HiiHandle, LanguageString, &BufferSize);\r
103 }\r
104\r
105 if (EFI_ERROR (Status)) {\r
106 LanguageString = NULL;\r
107 }\r
108\r
109 return LanguageString;\r
110}\r
111\r
112\r
113/**\r
114 This function returns the number of supported languages on HiiHandle.\r
115\r
116 If HiiHandle is not a valid Handle in the default HII database, then ASSERT.\r
117 If not enough resource to complete the operation, then ASSERT.\r
118\r
119 @param HiiHandle The HII package list handle.\r
120\r
121 @return The number of supported languages.\r
122\r
123**/\r
124UINT16\r
125EFIAPI\r
126HiiLibGetSupportedLanguageNumber (\r
127 IN EFI_HII_HANDLE HiiHandle\r
128 )\r
129{\r
130 CHAR8 *Languages;\r
131 CHAR8 *LanguageString;\r
132 UINT16 LangNumber;\r
133 CHAR8 Lang[RFC_3066_ENTRY_SIZE];\r
134\r
135 Languages = HiiLibGetSupportedLanguages (HiiHandle);\r
136 if (Languages == NULL) {\r
137 return 0;\r
138 }\r
139\r
140 LangNumber = 0;\r
141 LanguageString = Languages;\r
142 while (*LanguageString != 0) {\r
143 HiiLibGetNextLanguage (&LanguageString, Lang);\r
144 LangNumber++;\r
145 }\r
146 FreePool (Languages);\r
147\r
148 return LangNumber;\r
149}\r
150\r
151/**\r
152 This function returns the list of supported 2nd languages, in the format specified\r
153 in UEFI specification Appendix M.\r
154\r
155 If HiiHandle is not a valid Handle in the default HII database, then ASSERT.\r
156 If not enough resource to complete the operation, then ASSERT.\r
157\r
158 @param HiiHandle The HII package list handle.\r
159 @param FirstLanguage Pointer to language name buffer.\r
160 \r
161 @return The supported languages.\r
162\r
163**/\r
164CHAR8 *\r
165EFIAPI\r
166HiiLibGetSupportedSecondaryLanguages (\r
167 IN EFI_HII_HANDLE HiiHandle,\r
168 IN CONST CHAR8 *FirstLanguage\r
169 )\r
170{\r
171 EFI_STATUS Status;\r
172 UINTN BufferSize;\r
173 CHAR8 *LanguageString;\r
174\r
175 ASSERT (HiiHandle != NULL);\r
176 ASSERT (IsHiiHandleRegistered (HiiHandle));\r
177 //\r
178 // Collect current supported 2nd Languages for given HII handle\r
179 // First try allocate 4K buffer to store the current supported 2nd languages.\r
180 //\r
181 BufferSize = 0x1000;\r
182 LanguageString = AllocateZeroPool (BufferSize);\r
183 if (LanguageString == NULL) {\r
184 return NULL;\r
185 }\r
186\r
187 Status = mHiiStringProt->GetSecondaryLanguages (mHiiStringProt, HiiHandle, FirstLanguage, LanguageString, &BufferSize);\r
188 \r
189 if (Status == EFI_BUFFER_TOO_SMALL) {\r
190 FreePool (LanguageString);\r
191 LanguageString = AllocateZeroPool (BufferSize);\r
192 if (LanguageString == NULL) {\r
193 return NULL;\r
194 }\r
195\r
196 Status = mHiiStringProt->GetSecondaryLanguages (mHiiStringProt, HiiHandle, FirstLanguage, LanguageString, &BufferSize);\r
197 }\r
198\r
199 if (EFI_ERROR (Status)) {\r
200 LanguageString = NULL;\r
201 }\r
202\r
203 return LanguageString;\r
204}\r
205\r
206\r
11e92503 207/**\r
208 Determine what is the current language setting. The space reserved for Lang\r
209 must be at least RFC_3066_ENTRY_SIZE bytes;\r
210\r
211 If Lang is NULL, then ASSERT.\r
212\r
213 @param Lang Pointer of system language. Lang will always be filled with \r
214 a valid RFC 3066 language string. If "PlatformLang" is not\r
215 set in the system, the default language specifed by PcdUefiVariableDefaultPlatformLang\r
216 is returned.\r
217\r
218 @return EFI_SUCCESS If the EFI Variable with "PlatformLang" is set and return in Lang.\r
219 @return EFI_NOT_FOUND If the EFI Variable with "PlatformLang" is not set, but a valid default language is return in Lang.\r
220\r
221**/\r
222EFI_STATUS\r
223EFIAPI\r
224GetCurrentLanguage (\r
225 OUT CHAR8 *Lang\r
226 )\r
227{\r
228 EFI_STATUS Status;\r
229 UINTN Size;\r
230\r
231 ASSERT (Lang != NULL);\r
232\r
233 //\r
234 // Get current language setting\r
235 //\r
236 Size = RFC_3066_ENTRY_SIZE;\r
237 Status = gRT->GetVariable (\r
238 L"PlatformLang",\r
239 &gEfiGlobalVariableGuid,\r
240 NULL,\r
241 &Size,\r
242 Lang\r
243 );\r
244\r
245 if (EFI_ERROR (Status)) {\r
246 AsciiStrCpy (Lang, (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang));\r
247 }\r
248\r
249 return Status;\r
250}\r
251\r
252\r
253\r