Refine language conversion in ECP. Create a new library LanguageLib providing functions for language conversion between ISO 639-2 and RFC 4646 styles. Update FrameworkHiiOnUefiHiiThunk, UcOnUc2Thunk and Uc2OnUcThunk modules to use this library.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8258 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
rsun3
2009-05-08 01:51:35 +00:00
parent e779654316
commit 7c9d25ae76
13 changed files with 686 additions and 736 deletions

View File

@ -15,299 +15,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#include "HiiDatabase.h"
typedef struct {
CHAR8 *Iso639;
CHAR8 *Rfc4646;
} ISO639TORFC4646MAP;
ISO639TORFC4646MAP Iso639ToRfc4646Map [] = {
{"eng", "en-US"},
{"fra", "fr-FR"},
};
//
// Lookup table of ISO639-2 3 character language codes to ISO 639-1 2 character language codes
// Each entry is 5 CHAR8 values long. The first 3 CHAR8 values are the ISO 639-2 code.
// The last 2 CHAR8 values are the ISO 639-1 code.
//
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 Iso639ToRfc4646ConversionTable[] =
"\
aaraa\
abkab\
afraf\
amham\
araar\
asmas\
aymay\
azeaz\
bakba\
belbe\
benbn\
bihbh\
bisbi\
bodbo\
brebr\
bulbg\
catca\
cescs\
corkw\
cosco\
cymcy\
danda\
deude\
dzodz\
ellel\
engen\
epoeo\
estet\
euseu\
faofo\
fasfa\
fijfj\
finfi\
frafr\
fryfy\
gaiga\
gdhgd\
glggl\
grngn\
gujgu\
hauha\
hebhe\
hinhi\
hrvhr\
hunhu\
hyehy\
ikuiu\
ileie\
inaia\
indid\
ipkik\
islis\
itait\
jawjw\
jpnja\
kalkl\
kankn\
kasks\
katka\
kazkk\
khmkm\
kinrw\
kirky\
korko\
kurku\
laolo\
latla\
lavlv\
linln\
litlt\
ltzlb\
malml\
marmr\
mkdmk\
mlgmg\
mltmt\
molmo\
monmn\
mrimi\
msams\
myamy\
nauna\
nepne\
nldnl\
norno\
ocioc\
ormom\
panpa\
polpl\
porpt\
pusps\
quequ\
rohrm\
ronro\
runrn\
rusru\
sagsg\
sansa\
sinsi\
slksk\
slvsl\
smise\
smosm\
snasn\
sndsd\
somso\
sotst\
spaes\
sqisq\
srpsr\
sswss\
sunsu\
swasw\
swesv\
tamta\
tattt\
telte\
tgktg\
tgltl\
thath\
tsnts\
tuktk\
twitw\
uigug\
ukruk\
urdur\
uzbuz\
vievi\
volvo\
wolwo\
xhoxh\
yidyi\
zhaza\
zhozh\
zulzu\
";
CHAR8 *
ConvertIso639ToRfc4646 (
CHAR8 *Iso638Lang
)
{
UINTN Index;
CHAR8 AsciiLanguage[ISO_639_2_ENTRY_SIZE + 1];
AsciiStrnCpy (AsciiLanguage, Iso638Lang, sizeof (AsciiLanguage));
for (Index = 0; Index < ISO_639_2_ENTRY_SIZE + 1; Index ++) {
if (AsciiLanguage [Index] == 0) {
break;
} else if (AsciiLanguage [Index] >= 'A' && AsciiLanguage [Index] <= 'Z') {
AsciiLanguage [Index] = (CHAR8) (AsciiLanguage [Index] - 'A' + 'a');
}
}
for (Index = 0; Index < sizeof (Iso639ToRfc4646Map) / sizeof (Iso639ToRfc4646Map[0]); Index++) {
if (AsciiStrnCmp (AsciiLanguage, Iso639ToRfc4646Map[Index].Iso639, AsciiStrSize (AsciiLanguage)) == 0) {
return Iso639ToRfc4646Map[Index].Rfc4646;
}
}
return (CHAR8 *) NULL;
}
/**
Convert language code from RFC4646 to ISO639-2.
@param LanguageRfc4646 RFC4646 language code.
@param LanguageIso639 ISO639-2 language code.
@retval EFI_SUCCESS Language code converted.
@retval EFI_NOT_FOUND Language code not found.
**/
EFI_STATUS
EFIAPI
ConvertRfc4646LanguageToIso639Language (
IN CHAR8 *LanguageRfc4646,
OUT CHAR8 *LanguageIso639
)
{
UINTN Index;
if ((LanguageRfc4646[2] != '-') && (LanguageRfc4646[2] != 0)) {
CopyMem (LanguageIso639, LanguageRfc4646, 3);
return EFI_SUCCESS;
}
for (Index = 0; Iso639ToRfc4646ConversionTable[Index] != 0; Index += 5) {
if (CompareMem (LanguageRfc4646, &Iso639ToRfc4646ConversionTable[Index + 3], 2) == 0) {
CopyMem (LanguageIso639, &Iso639ToRfc4646ConversionTable[Index], 3);
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
/**
Convert language code from ISO639-2 to RFC4646 and return the converted language.
Caller is responsible for freeing the allocated buffer.
LanguageIso639 contain a single ISO639-2 code such as
"eng" or "fra".
If LanguageIso639 is NULL, then ASSERT.
If LanguageRfc4646 is NULL, then ASSERT.
@param LanguageIso639 ISO639-2 language code.
@return the allocated buffer or NULL, if the language is not found.
**/
CHAR8*
EFIAPI
ConvertIso639LanguageToRfc4646Language (
IN CONST CHAR8 *LanguageIso639
)
{
UINTN Index;
CHAR8 *Rfc4646Language;
for (Index = 0; Iso639ToRfc4646ConversionTable[Index] != 0; Index += 5) {
if (CompareMem (LanguageIso639, &Iso639ToRfc4646ConversionTable[Index], 3) == 0) {
Rfc4646Language = AllocateZeroPool (3);
if (Rfc4646Language != NULL) {
Rfc4646Language = CopyMem (Rfc4646Language, &Iso639ToRfc4646ConversionTable[Index + 3], 2);
}
return Rfc4646Language;
}
}
return NULL;
}
/**
Get next language from language code list (with separator ';').
If LangCode is NULL, then ASSERT.
If Lang is NULL, then ASSERT.
@param LangCode On input: point to first language in the list. On
output: point to next language in the list, or
NULL if no more language in the list.
@param Lang The first language in the list.
**/
VOID
EFIAPI
GetNextLanguage (
IN OUT CHAR8 **LangCode,
OUT CHAR8 *Lang
)
{
UINTN Index;
CHAR8 *StringPtr;
ASSERT (LangCode != NULL);
ASSERT (*LangCode != NULL);
ASSERT (Lang != NULL);
Index = 0;
StringPtr = *LangCode;
while (StringPtr[Index] != 0 && StringPtr[Index] != ';') {
Index++;
}
CopyMem (Lang, StringPtr, Index);
Lang[Index] = 0;
if (StringPtr[Index] == ';') {
Index++;
}
*LangCode = StringPtr + Index;
}
/**
Test if all of the characters in a string have corresponding font characters.
@ -468,7 +175,7 @@ HiiNewString (
ZeroMem (LanguageCopy, sizeof (LanguageCopy));
CopyMem (LanguageCopy, Language, ISO_639_2_ENTRY_SIZE * sizeof (CHAR16));
UnicodeStrToAsciiStr (LanguageCopy, AsciiLanguage);
Rfc4646AsciiLanguage = ConvertIso639ToRfc4646 (AsciiLanguage);
Rfc4646AsciiLanguage = ConvertLanguagesIso639ToRfc4646 (AsciiLanguage);
ASSERT (Rfc4646AsciiLanguage != NULL);
}
@ -614,7 +321,7 @@ HiiThunkGetString (
// Caller of Framework HII Interface uses the Language Identification String defined
// in Iso639. So map it to the Language Identifier defined in RFC4646.
//
Rfc4646AsciiLanguage = ConvertIso639ToRfc4646 (Iso639AsciiLanguage);
Rfc4646AsciiLanguage = ConvertLanguagesIso639ToRfc4646 (Iso639AsciiLanguage);
//
// If Rfc4646AsciiLanguage is NULL, more language mapping must be added to