Date
1 - 1 of 1
Ways to add a string package of different language at runtime
Konstantin Aladyshev
Hello!
I was investigating the possibility of adding localization strings at runtime. I've noticed that https://github.com/tianocore/edk2/blob/master/OvmfPkg/PlatformDxe/Platform.uni has strings only for the `en-US` language. So I've decided to use it as an example, and create an application that would add translations for some other supported system language (in this case `fr-FR`): ``` EFI_STATUS EFIAPI UefiMain ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; EFI_GUID PackageGuid = {0xD9DCC5DF, 0x4007, 0x435E, {0x90, 0x98, 0x89, 0x70, 0x93, 0x55, 0x04, 0xb2 }}; EFI_HII_HANDLE* Handle = HiiGetHiiHandles(&PackageGuid); CHAR16* FrenchStrings[] = { L"Configuration de la OVMF plateforme", L"Modifier divers paramètres de la plateforme OVMF", L"Paramètres OVMF", L"Résolution préférée au prochain démarrage", ... L"2560x1600", }; for (UINTN i=0; i<(sizeof(FrenchStrings)/sizeof(FrenchStrings[0])); i++) { EFI_STRING_ID StringId; if (i==0) { Status = gHiiString->NewString(gHiiString, *Handle, &StringId, "fr-FR", L"French", L"", NULL); Print(L"Added ID=%d, Status = %r\n", StringId, Status); } StringId = i+2; Status = gHiiString->SetString(gHiiString, *Handle, StringId, "fr-FR", FrenchStrings[i], NULL); Print(L"Added ID=%d, Status = %r\n", StringId, Status); } return EFI_SUCCESS; } ``` This works well, but I'm a little concerned about the approach that I've used to initially create the 'fr-FR' string package. Here I've used: ``` gHiiString->NewString(gHiiString, *Handle, &StringId, "fr-FR", L"French", L"", NULL); ``` Initially the `en-US` string package has 40 strings, so this code would create a 'fr-FR' string package with one string of ID=41, which has a "" value. Because of this hack in the end the 'en-US' package would have 40 strings and the 'fr-FR' package would have 41 strings. This is really not a problem of any kind, but maybe there is a library function to create a string package of a different language? Best regards, Konstantin Aladyshev |
|