Add fallback support in tinygettext, fixing languages like fr_CA, which relies on fr

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7981 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2011-03-17 22:34:25 +00:00
parent 830c224e2d
commit ea060b7581
3 changed files with 18 additions and 1 deletions

View File

@ -27,6 +27,7 @@ Dictionary::Dictionary(const std::string& charset_) :
charset(charset_),
plural_forms()
{
m_has_fallback = false;
}
Dictionary::~Dictionary()
@ -108,7 +109,9 @@ Dictionary::translate(const Entries& dict, const std::string& msgid)
else
{
//log_info << "Couldn't translate: " << msgid << std::endl;
return msgid;
if (m_has_fallback) return m_fallback->translate(msgid);
else return msgid;
}
}

View File

@ -43,6 +43,9 @@ private:
std::string translate(const Entries& dict, const std::string& msgid);
std::string translate_plural(const Entries& dict, const std::string& msgid, const std::string& msgidplural, int num);
bool m_has_fallback;
Dictionary* m_fallback;
public:
/** Constructs a dictionary converting to the specified \a charset (default UTF-8) */
Dictionary(const std::string& charset = "UTF-8");
@ -100,6 +103,12 @@ public:
return func;
}
void addFallback(Dictionary* fallback)
{
m_has_fallback = true;
m_fallback = fallback;
}
/** Iterate over all messages with a context, Func is of type:
void func(const std::string& ctxt, const std::string& msgid, const std::vector<std::string>& msgstrs) */
template<class Func>

View File

@ -164,6 +164,11 @@ DictionaryManager::get_dictionary(const Language& language)
}
}
if (language.get_country().size() > 0)
{
printf("Adding language fallback %s\n", language.get_language().c_str());
dict->addFallback( &get_dictionary(Language::from_spec(language.get_language())) );
}
return *dict;
}
}