Pyrogenesis trunk
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
tinygettext::Dictionary Class Reference

A simple dictionary class that mimics gettext() behaviour. More...

#include <dictionary.hpp>

Collaboration diagram for tinygettext::Dictionary:
Collaboration graph
[legend]

Public Member Functions

 Dictionary (const std::string &charset="UTF-8")
 Constructs a dictionary converting to the specified charset (default UTF-8) More...
 
 ~Dictionary ()
 
std::string get_charset () const
 Return the charset used for this dictionary. More...
 
void set_plural_forms (const PluralForms &)
 
PluralForms get_plural_forms () const
 
std::string translate (const std::string &msgid) const
 Translate the string msgid. More...
 
std::string translate_plural (const std::string &msgid, const std::string &msgidplural, int num) const
 Translate the string msgid to its correct plural form, based on the number of items given by num. More...
 
std::string translate_ctxt (const std::string &msgctxt, const std::string &msgid) const
 Translate the string msgid that is in context msgctx. More...
 
std::string translate_ctxt_plural (const std::string &msgctxt, const std::string &msgid, const std::string &msgidplural, int num) const
 
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 message, msgid_plural the plural form and msgstrs a table of translations. More...
 
void add_translation (const std::string &msgctxt, const std::string &msgid, const std::string &msgid_plural, const std::vector< std::string > &msgstrs)
 
void add_translation (const std::string &msgid, const std::string &msgstr)
 Add a translation from msgid to msgstr to the dictionary. More...
 
void add_translation (const std::string &msgctxt, const std::string &msgid, const std::string &msgstr)
 
template<class Func >
Func foreach (Func func)
 Iterate over all messages, Func is of type: void func(const std::string& msgid, const std::vector<std::string>& msgstrs) More...
 
void addFallback (Dictionary *fallback)
 
template<class Func >
Func foreach_ctxt (Func func)
 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) More...
 

Private Types

typedef std::unordered_map< std::string, std::vector< std::string > > Entries
 
typedef std::unordered_map< std::string, EntriesCtxtEntries
 

Private Member Functions

std::string translate (const Entries &dict, const std::string &msgid) const
 
std::string translate_plural (const Entries &dict, const std::string &msgid, const std::string &msgidplural, int num) const
 
 Dictionary (const Dictionary &)=delete
 
Dictionaryoperator= (const Dictionary &)=delete
 

Private Attributes

Entries entries
 
CtxtEntries ctxt_entries
 
std::string charset
 
PluralForms plural_forms
 
bool m_has_fallback
 
Dictionarym_fallback
 

Detailed Description

A simple dictionary class that mimics gettext() behaviour.

Each Dictionary only works for a single language, for managing multiple languages and .po files at once use the DictionaryManager.

Member Typedef Documentation

◆ CtxtEntries

typedef std::unordered_map<std::string, Entries> tinygettext::Dictionary::CtxtEntries
private

◆ Entries

typedef std::unordered_map<std::string, std::vector<std::string> > tinygettext::Dictionary::Entries
private

Constructor & Destructor Documentation

◆ Dictionary() [1/2]

tinygettext::Dictionary::Dictionary ( const std::string &  charset = "UTF-8")

Constructs a dictionary converting to the specified charset (default UTF-8)

◆ ~Dictionary()

tinygettext::Dictionary::~Dictionary ( )

◆ Dictionary() [2/2]

tinygettext::Dictionary::Dictionary ( const Dictionary )
privatedelete

Member Function Documentation

◆ add_translation() [1/4]

void tinygettext::Dictionary::add_translation ( const std::string &  msgctxt,
const std::string &  msgid,
const std::string &  msgid_plural,
const std::vector< std::string > &  msgstrs 
)

◆ add_translation() [2/4]

void tinygettext::Dictionary::add_translation ( const std::string &  msgctxt,
const std::string &  msgid,
const std::string &  msgstr 
)

◆ add_translation() [3/4]

void tinygettext::Dictionary::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 message, msgid_plural the plural form and msgstrs a table of translations.

The right translation will be calculated based on the num argument to translate().

◆ add_translation() [4/4]

void tinygettext::Dictionary::add_translation ( const std::string &  msgid,
const std::string &  msgstr 
)

Add a translation from msgid to msgstr to the dictionary.

◆ addFallback()

void tinygettext::Dictionary::addFallback ( Dictionary fallback)
inline

◆ foreach()

template<class Func >
Func tinygettext::Dictionary::foreach ( Func  func)
inline

Iterate over all messages, Func is of type: void func(const std::string& msgid, const std::vector<std::string>& msgstrs)

◆ foreach_ctxt()

template<class Func >
Func tinygettext::Dictionary::foreach_ctxt ( Func  func)
inline

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)

◆ get_charset()

std::string tinygettext::Dictionary::get_charset ( ) const

Return the charset used for this dictionary.

◆ get_plural_forms()

PluralForms tinygettext::Dictionary::get_plural_forms ( ) const

◆ operator=()

Dictionary & tinygettext::Dictionary::operator= ( const Dictionary )
privatedelete

◆ set_plural_forms()

void tinygettext::Dictionary::set_plural_forms ( const PluralForms plural_forms_)

◆ translate() [1/2]

std::string tinygettext::Dictionary::translate ( const Entries dict,
const std::string &  msgid 
) const
private

◆ translate() [2/2]

std::string tinygettext::Dictionary::translate ( const std::string &  msgid) const

Translate the string msgid.

◆ translate_ctxt()

std::string tinygettext::Dictionary::translate_ctxt ( const std::string &  msgctxt,
const std::string &  msgid 
) const

Translate the string msgid that is in context msgctx.

A context is a way to disambiguate msgids that contain the same letters, but different meaning. For example "exit" might mean to quit doing something or it might refer to a door that leads outside (i.e. 'Ausgang' vs 'Beenden' in german)

◆ translate_ctxt_plural()

std::string tinygettext::Dictionary::translate_ctxt_plural ( const std::string &  msgctxt,
const std::string &  msgid,
const std::string &  msgidplural,
int  num 
) const

◆ translate_plural() [1/2]

std::string tinygettext::Dictionary::translate_plural ( const Entries dict,
const std::string &  msgid,
const std::string &  msgidplural,
int  num 
) const
private

◆ translate_plural() [2/2]

std::string tinygettext::Dictionary::translate_plural ( const std::string &  msgid,
const std::string &  msgidplural,
int  num 
) const

Translate the string msgid to its correct plural form, based on the number of items given by num.

msgid_plural is msgid in plural form.

Member Data Documentation

◆ charset

std::string tinygettext::Dictionary::charset
private

◆ ctxt_entries

CtxtEntries tinygettext::Dictionary::ctxt_entries
private

◆ entries

Entries tinygettext::Dictionary::entries
private

◆ m_fallback

Dictionary* tinygettext::Dictionary::m_fallback
private

◆ m_has_fallback

bool tinygettext::Dictionary::m_has_fallback
private

◆ plural_forms

PluralForms tinygettext::Dictionary::plural_forms
private

The documentation for this class was generated from the following files: