fix: menus are not translated into selected language.
This commit is contained in:
parent
419626df0e
commit
5d1bc34563
2 changed files with 23 additions and 22 deletions
23
inc/config.h
23
inc/config.h
|
|
@ -35,22 +35,6 @@ public:
|
||||||
ChatterItem (StringRef name, float repeat, float duration) : name (name), repeat (repeat), duration (duration) { }
|
ChatterItem (StringRef name, float repeat, float duration) : name (name), repeat (repeat), duration (duration) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
// language hasher
|
|
||||||
struct HashLangString {
|
|
||||||
uint32 operator () (const String &key) const {
|
|
||||||
auto str = reinterpret_cast <uint8 *> (const_cast <char *> (key.chars ()));
|
|
||||||
uint32 hash = 0;
|
|
||||||
|
|
||||||
while (*str++) {
|
|
||||||
if (!isalnum (*str)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
hash = ((*str << 5) + hash) + *str;
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// mostly config stuff, and some stuff dealing with menus
|
// mostly config stuff, and some stuff dealing with menus
|
||||||
class BotConfig final : public Singleton <BotConfig> {
|
class BotConfig final : public Singleton <BotConfig> {
|
||||||
public:
|
public:
|
||||||
|
|
@ -73,7 +57,7 @@ private:
|
||||||
StringArray m_logos;
|
StringArray m_logos;
|
||||||
StringArray m_avatars;
|
StringArray m_avatars;
|
||||||
|
|
||||||
HashMap <String, String, HashLangString> m_language;
|
HashMap <uint32, String, Hash <int32>> m_language;
|
||||||
HashMap <int32, DifficultyData> m_difficulty;
|
HashMap <int32, DifficultyData> m_difficulty;
|
||||||
|
|
||||||
// default tables for personality weapon preferences, overridden by weapon.cfg
|
// default tables for personality weapon preferences, overridden by weapon.cfg
|
||||||
|
|
@ -148,9 +132,12 @@ private:
|
||||||
if (line.empty ()) {
|
if (line.empty ()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return line.substr (0, 1).findFirstOf ("#/; \n\r") != String::InvalidIndex;
|
return line.substr (0, 1).findFirstOf ("#/;") != String::InvalidIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// hash the lang string, only the letters
|
||||||
|
uint32 hashLangString (const char *input);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// checks whether chat banks contains messages
|
// checks whether chat banks contains messages
|
||||||
|
|
|
||||||
|
|
@ -495,7 +495,7 @@ void BotConfig::loadLanguageConfig () {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lang.second.empty () && !lang.first.empty ()) {
|
if (!lang.second.empty () && !lang.first.empty ()) {
|
||||||
m_language[lang.first.trim ()] = lang.second.trim ();
|
m_language[hashLangString (lang.first.trim ().chars ())] = lang.second;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (line.startsWith ("[TRANSLATED]") && !temp.empty ()) {
|
else if (line.startsWith ("[TRANSLATED]") && !temp.empty ()) {
|
||||||
|
|
@ -756,9 +756,23 @@ const char *BotConfig::translate (StringRef input) {
|
||||||
if (game.isDedicated ()) {
|
if (game.isDedicated ()) {
|
||||||
return input.chars ();
|
return input.chars ();
|
||||||
}
|
}
|
||||||
|
auto hash = hashLangString (input.chars ());
|
||||||
|
|
||||||
if (m_language.has (input)) {
|
if (m_language.has (hash)) {
|
||||||
return m_language[input.chars ()].chars ();
|
return m_language[hash].chars ();
|
||||||
}
|
}
|
||||||
return input.chars (); // nothing found
|
return input.chars (); // nothing found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32 BotConfig::hashLangString (const char *input) {
|
||||||
|
auto str = reinterpret_cast <uint8 *> (const_cast <char *> (input));
|
||||||
|
uint32 hash = 0;
|
||||||
|
|
||||||
|
while (*str++) {
|
||||||
|
if (!isalnum (*str)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
hash = ((*str << 5) + hash) + *str;
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue