60b92f0c7eaf3445bf920f9a0e797cba65ef221b
[mirror_edk2.git] / Nt32Pkg / PlatformBdsDxe / Generic / Language.c
1 /*++
2
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
8
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.
11
12 Module Name:
13
14 language.c
15
16 Abstract:
17
18 Language settings
19
20 Revision History
21
22 --*/
23
24 //
25 // Include common header file for this module.
26 //
27 #include "CommonHeader.h"
28
29 #include "BdsString.h"
30 #include "Language.h"
31
32 //
33 // Default language code, currently is English
34 //
35 CHAR8 *mDefaultLangCode = "eng";
36
37
38 VOID
39 InitializeLanguage (
40 BOOLEAN LangCodesSettingRequired
41 )
42 /*++
43
44 Routine Description:
45 Determine the current language that will be used
46 based on language related EFI Variables
47
48 Arguments:
49 LangCodesSettingRequired - If required to set LangCode variable
50
51 Returns:
52
53 --*/
54 {
55 EFI_STATUS Status;
56 UINTN Index;
57 UINTN Size;
58 CHAR8 LangCode[ISO_639_2_ENTRY_SIZE];
59 CHAR8 *LangCodes;
60 CHAR16 *LanguageString;
61
62 LanguageString = NULL;
63 LangCodes = NULL;
64
65 //
66 // Collect the languages from what our current Language support is based on our VFR
67 //
68 gHii->GetPrimaryLanguages (gHii, gStringPackHandle, &LanguageString);
69
70 LangCodes = AllocatePool (StrLen (LanguageString));
71 ASSERT (LangCodes);
72
73 //
74 // Convert LanguageString from Unicode to EFI defined ASCII LangCodes
75 //
76 for (Index = 0; LanguageString[Index] != 0x0000; Index++) {
77 LangCodes[Index] = (CHAR8) LanguageString[Index];
78 }
79
80 LangCodes[Index] = 0;
81
82 if (LangCodesSettingRequired) {
83 Status = gRT->SetVariable (
84 L"LangCodes",
85 &gEfiGlobalVariableGuid,
86 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
87 AsciiStrLen (LangCodes),
88 LangCodes
89 );
90 }
91 //
92 // Find current LangCode from Lang NV Variable
93 //
94 Size = ISO_639_2_ENTRY_SIZE;
95 Status = gRT->GetVariable (
96 L"Lang",
97 &gEfiGlobalVariableGuid,
98 NULL,
99 &Size,
100 &LangCode
101 );
102
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;
108 break;
109 }
110 }
111 }
112 //
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.
116 //
117 if (EFI_ERROR (Status)) {
118 Status = gRT->SetVariable (
119 L"Lang",
120 &gEfiGlobalVariableGuid,
121 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
122 ISO_639_2_ENTRY_SIZE,
123 mDefaultLangCode
124 );
125 }
126
127 if (LangCodes) {
128 FreePool (LangCodes);
129 }
130
131 if (LanguageString != NULL) {
132 FreePool (LanguageString);
133 }
134
135 }