2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-07-03 23:55:52 +00:00
This commit is contained in:
Jack Andersen 2016-01-06 14:39:49 -10:00
commit 329be27c7d
2 changed files with 7 additions and 10 deletions

View File

@ -18,7 +18,7 @@ public:
const unsigned char* yamlSource, size_t yamlLength); const unsigned char* yamlSource, size_t yamlLength);
const std::string& name() const {return m_name;} const std::string& name() const {return m_name;}
const std::string& fullName() const {return m_fullName;} const std::string& fullName() const {return m_fullName;}
const Athena::io::YAMLNode& rootNode() const {return *m_langNode;} const Athena::io::YAMLNode* rootNode() const {return m_langNode;}
}; };
class Translator class Translator

View File

@ -30,7 +30,7 @@ void Translator::setLocale(const Locale* targetLocale)
m_targetLocale = targetLocale; m_targetLocale = targetLocale;
} }
static const std::string* RecursiveLookup(const Athena::io::YAMLNode& node, static const std::string* RecursiveLookup(const Athena::io::YAMLNode* node,
std::string::const_iterator start, std::string::const_iterator start,
std::string::const_iterator end) std::string::const_iterator end)
{ {
@ -38,13 +38,13 @@ static const std::string* RecursiveLookup(const Athena::io::YAMLNode& node,
{ {
if (*it == '/') if (*it == '/')
{ {
const Athena::io::YAMLNode* ch = node.findMapChild(std::string(start, it).c_str()); const Athena::io::YAMLNode* ch = node->findMapChild(std::string(start, it).c_str());
if (!ch) if (!ch)
return nullptr; return nullptr;
return RecursiveLookup(*ch, it+1, end); return RecursiveLookup(ch, it+1, end);
} }
} }
const Athena::io::YAMLNode* ch = node.findMapChild(std::string(start, end).c_str()); const Athena::io::YAMLNode* ch = node->findMapChild(std::string(start, end).c_str());
if (!ch) if (!ch)
return nullptr; return nullptr;
return &ch->m_scalarString; return &ch->m_scalarString;
@ -52,7 +52,7 @@ static const std::string* RecursiveLookup(const Athena::io::YAMLNode& node,
const std::string* Translator::translate(const std::string& key) const const std::string* Translator::translate(const std::string& key) const
{ {
if ((&m_targetLocale->rootNode()) == nullptr) if (!m_targetLocale->rootNode())
return nullptr; return nullptr;
return RecursiveLookup(m_targetLocale->rootNode(), key.cbegin(), key.cend()); return RecursiveLookup(m_targetLocale->rootNode(), key.cbegin(), key.cend());
@ -60,10 +60,7 @@ const std::string* Translator::translate(const std::string& key) const
std::string Translator::translateOr(const std::string& key, const char* vor) const std::string Translator::translateOr(const std::string& key, const char* vor) const
{ {
if ((&m_targetLocale->rootNode()) == nullptr) const std::string* find = translate(key);
return vor;
const std::string* find = RecursiveLookup(m_targetLocale->rootNode(), key.cbegin(), key.cend());
if (find) if (find)
return *find; return *find;
return vor; return vor;