20#ifndef HEADER_TINYGETTEXT_DICTIONARY_HPP
21#define HEADER_TINYGETTEXT_DICTIONARY_HPP
24#include <unordered_map>
37 typedef std::unordered_map<std::string, std::vector<std::string> >
Entries;
47 std::string
translate_plural(
const Entries& dict,
const std::string& msgid,
const std::string& msgidplural,
int num)
const;
65 std::string
translate(
const std::string& msgid)
const;
70 std::string
translate_plural(
const std::string& msgid,
const std::string& msgidplural,
int num)
const;
77 std::string
translate_ctxt(
const std::string& msgctxt,
const std::string& msgid)
const;
79 std::string
translate_ctxt_plural(
const std::string& msgctxt,
const std::string& msgid,
const std::string& msgidplural,
int num)
const;
86 void add_translation(
const std::string& msgid,
const std::string& msgid_plural,
87 const std::vector<std::string>& msgstrs);
89 const std::string& msgid,
const std::string& msgid_plural,
90 const std::vector<std::string>& msgstrs);
94 void add_translation(
const std::string& msgid,
const std::string& msgstr);
95 void add_translation(
const std::string& msgctxt,
const std::string& msgid,
const std::string& msgstr);
100 Func
foreach(Func func)
102 for(Entries::iterator i =
entries.begin(); i !=
entries.end(); ++i)
104 func(i->first, i->second);
122 for(Entries::iterator j = i->second.begin(); j != i->second.end(); ++j)
124 func(i->first, j->first, j->second);
A simple dictionary class that mimics gettext() behaviour.
Definition: dictionary.hpp:35
std::unordered_map< std::string, std::vector< std::string > > Entries
Definition: dictionary.hpp:37
Dictionary & operator=(const Dictionary &)=delete
CtxtEntries ctxt_entries
Definition: dictionary.hpp:41
std::string translate_ctxt_plural(const std::string &msgctxt, const std::string &msgid, const std::string &msgidplural, int num) const
Definition: dictionary.cpp:158
std::string get_charset() const
Return the charset used for this dictionary.
Definition: dictionary.cpp:59
Entries entries
Definition: dictionary.hpp:38
std::string translate_plural(const Entries &dict, const std::string &msgid, const std::string &msgidplural, int num) const
Definition: dictionary.cpp:83
void add_translation(const std::string &msgid, const std::string &msgid_plural, const std::vector< std::string > &msgstrs)
Add a translation from msgid to msgstr to the dictionary, where msgid is the singular form of the mes...
Definition: dictionary.cpp:177
std::unordered_map< std::string, Entries > CtxtEntries
Definition: dictionary.hpp:40
std::string translate_ctxt(const std::string &msgctxt, const std::string &msgid) const
Translate the string msgid that is in context msgctx.
Definition: dictionary.cpp:143
std::string translate(const Entries &dict, const std::string &msgid) const
Definition: dictionary.cpp:126
Func foreach_ctxt(Func func)
Iterate over all messages with a context, Func is of type: void func(const std::string& ctxt,...
Definition: dictionary.hpp:118
~Dictionary()
Definition: dictionary.cpp:54
PluralForms get_plural_forms() const
Definition: dictionary.cpp:71
Dictionary * m_fallback
Definition: dictionary.hpp:50
Dictionary(const std::string &charset="UTF-8")
Constructs a dictionary converting to the specified charset (default UTF-8)
Definition: dictionary.cpp:44
PluralForms plural_forms
Definition: dictionary.hpp:44
void set_plural_forms(const PluralForms &)
Definition: dictionary.cpp:65
bool m_has_fallback
Definition: dictionary.hpp:49
Dictionary(const Dictionary &)=delete
std::string charset
Definition: dictionary.hpp:43
void addFallback(Dictionary *fallback)
Definition: dictionary.hpp:109
Definition: plural_forms.hpp:30