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) { }
|
||||
};
|
||||
|
||||
// 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
|
||||
class BotConfig final : public Singleton <BotConfig> {
|
||||
public:
|
||||
|
|
@ -73,7 +57,7 @@ private:
|
|||
StringArray m_logos;
|
||||
StringArray m_avatars;
|
||||
|
||||
HashMap <String, String, HashLangString> m_language;
|
||||
HashMap <uint32, String, Hash <int32>> m_language;
|
||||
HashMap <int32, DifficultyData> m_difficulty;
|
||||
|
||||
// default tables for personality weapon preferences, overridden by weapon.cfg
|
||||
|
|
@ -148,9 +132,12 @@ private:
|
|||
if (line.empty ()) {
|
||||
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:
|
||||
|
||||
// checks whether chat banks contains messages
|
||||
|
|
|
|||
|
|
@ -495,7 +495,7 @@ void BotConfig::loadLanguageConfig () {
|
|||
}
|
||||
|
||||
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 ()) {
|
||||
|
|
@ -756,9 +756,23 @@ const char *BotConfig::translate (StringRef input) {
|
|||
if (game.isDedicated ()) {
|
||||
return input.chars ();
|
||||
}
|
||||
auto hash = hashLangString (input.chars ());
|
||||
|
||||
if (m_language.has (input)) {
|
||||
return m_language[input.chars ()].chars ();
|
||||
if (m_language.has (hash)) {
|
||||
return m_language[hash].chars ();
|
||||
}
|
||||
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