1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-02-13 16:16:08 +00:00

Add custom upper<->lowercase translation tables for better localization support.

Translation tables by Henrik Holst.
This commit is contained in:
fgenesis 2013-11-14 17:58:33 +01:00
parent 7a9df46830
commit 7de589e275
7 changed files with 215 additions and 18 deletions

View file

@ -559,6 +559,8 @@ void UserSettings::load(bool doApply, const std::string &overrideFile)
setUsedLocale(system.locale);
}
core->initLocalization();
if (doApply)
apply();
}

View file

@ -152,6 +152,60 @@ unsigned hash(const std::string &string)
/* hash * 33 + c */
static unsigned char lowerToUpperTable[256];
static unsigned char upperToLowerTable[256];
void initCharTranslationTables(const std::map<unsigned char, unsigned char>& tab)
{
for (unsigned int i = 0; i < 256; ++i)
{
lowerToUpperTable[i] = i;
upperToLowerTable[i] = i;
}
for (unsigned char i = 'a'; i <= 'z'; ++i)
{
lowerToUpperTable[i] = i - 'a' + 'A';
upperToLowerTable[i - 'a' + 'A'] = i;
}
for (std::map<unsigned char, unsigned char>::const_iterator it = tab.begin(); it != tab.end(); ++it)
{
lowerToUpperTable[it->first] = it->second;
upperToLowerTable[it->second] = it->first;
}
}
struct TransatableStaticInit
{
TransatableStaticInit()
{
std::map<unsigned char, unsigned char> dummy;
initCharTranslationTables(dummy);
}
};
static TransatableStaticInit _transtable_static_init;
static unsigned char charIsUpper(unsigned char c)
{
return c == upperToLowerTable[c];
}
static unsigned char charIsLower(unsigned char c)
{
return c == lowerToUpperTable[c];
}
static unsigned char charToLower(unsigned char c)
{
return upperToLowerTable[c];
}
static unsigned char charToUpper(unsigned char c)
{
return lowerToUpperTable[c];
}
std::string splitCamelCase(const std::string &input)
{
std::string result;
@ -160,7 +214,7 @@ std::string splitCamelCase(const std::string &input)
{
if (last == 1)
{
if (input[i] >= 'A' && input[i] <= 'Z')
if (charIsUpper(input[i]))
{
result += ' ';
}
@ -168,7 +222,7 @@ std::string splitCamelCase(const std::string &input)
result += input[i];
if (input[i] >= 'A' && input[i] <= 'Z')
if (charIsUpper(input[i]))
{
last = 2;
}
@ -201,22 +255,6 @@ bool isVectorInRect(const Vector &vec, const Vector &coord1, const Vector &coord
return (vec.x > coord1.x && vec.x < coord2.x && vec.y > coord1.y && vec.y < coord2.y);
}
static char charToUpper(char c)
{
if (c >= 'a' && c <= 'z') c = c - 'a' + 'A';
if ((unsigned char)c >= 0xE0 && (unsigned char)c <= 0xFF)
c = c - 0xE0 + 0xC0;
return c;
}
static char charToLower(char c)
{
if (c >= 'A' && c <= 'Z') c = c-'A' + 'a';
if ((unsigned char)c >= 0xC0 && (unsigned char)c <= 0xDF)
c = c-0xC0+0xE0;
return c;
}
void stringToUpper(std::string &s)
{
for (int i = 0; i < s.size(); i++)

View file

@ -204,6 +204,7 @@ struct IntPair
std::string numToZeroString(int num, int zeroes);
bool chance(int perc);
bool chancef(float p);
void initCharTranslationTables(const std::map<unsigned char, unsigned char>& tab);
void stringToUpper(std::string &s);
void stringToLower(std::string &s);
void stringToLowerUserData(std::string &s);

View file

@ -1293,6 +1293,8 @@ void Core::init()
initInputCodeMap();
initLocalization();
//glfwSetWindowSizeCallback(lockWindowSize);
}
@ -5164,3 +5166,23 @@ void Core::setupFileAccess()
debugLog("Done");
#endif
}
void Core::initLocalization()
{
InStream in(localisePath("data/localecase.txt"));
if(!in)
{
debugLog("data/localecase.txt does not exist, using internal locale data");
return;
}
std::string low, up;
std::map<unsigned char, unsigned char> trans;
while(in)
{
in >> low >> up;
trans[low[0]] = up[0];
}
initCharTranslationTables(trans);
}

View file

@ -1310,6 +1310,8 @@ public:
virtual void onBackgroundUpdate();
void initLocalization();
protected:
std::string fpsDebugString;

60
files/data/localecase.txt Normal file
View file

@ -0,0 +1,60 @@
a A
b B
c C
d D
e E
f F
g G
h H
i I
j J
k K
l L
m M
n N
o O
p P
q Q
r R
s S
t T
u U
v V
w W
x X
y Y
z Z
š Š
œ Œ
ž Ž
ÿ Ÿ
à À
á Á
â Â
ã Ã
ä Ä
å Å
æ Æ
ç Ç
è È
é É
ê Ê
ë Ë
ì Ì
í Í
î Î
ï Ï
ð Ð
ñ Ñ
ò Ò
ó Ó
ô Ô
õ Õ
ö Ö
ø Ø
ù Ù
ú Ú
û Û
ü Ü
ý Ý
þ Þ

View file

@ -0,0 +1,72 @@
a A
b B
c C
d D
e E
f F
g G
h H
i I
j J
k K
l L
m M
n N
o O
p P
q Q
r R
s S
t T
u U
v V
w W
x X
y Y
z Z
<EFBFBD>
ƒ <20>
š Š
œ Œ
<EFBFBD> <20>
ž Ž
Ÿ <20>
¢ ¡
¼ £
´ ¥
¸ ¨
º ª
¾ ½
¿ ¯
à À
ð Ð
á Á
ñ Ñ
â Â
ò Ò
ã Ã
ó Ó
ä Ä
ô Ô
å Å
õ Õ
æ Æ
ö Ö
ç Ç
÷ ×
è È
ø Ø
é É
ù Ù
ê Ê
ú Ú
ë Ë
û Û
ì Ì
ü Ü
í Í
ý Ý
î Î
þ Þ
ï Ï
ÿ ß