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

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

Constructor & Destructor Documentation

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

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

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

Member Function Documentation

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().

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

Add a translation from msgid to msgstr to the dictionary.

void tinygettext::Dictionary::add_translation ( const std::string &  msgctxt,
const std::string &  msgid,
const std::string &  msgstr 
)
void tinygettext::Dictionary::addFallback ( Dictionary fallback)
inline
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)

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)

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

Return the charset used for this dictionary.

PluralForms tinygettext::Dictionary::get_plural_forms ( ) const
Dictionary& tinygettext::Dictionary::operator= ( const Dictionary )
privatedelete
void tinygettext::Dictionary::set_plural_forms ( const PluralForms plural_forms_)
std::string tinygettext::Dictionary::translate ( const Entries dict,
const std::string &  msgid 
) const
private
std::string tinygettext::Dictionary::translate ( const std::string &  msgid) const

Translate the string msgid.

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)

std::string tinygettext::Dictionary::translate_ctxt_plural ( const std::string &  msgctxt,
const std::string &  msgid,
const std::string &  msgidplural,
int  num 
) const
std::string tinygettext::Dictionary::translate_plural ( const Entries dict,
const std::string &  msgid,
const std::string &  msgidplural,
int  num 
) const
private
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

std::string tinygettext::Dictionary::charset
private
CtxtEntries tinygettext::Dictionary::ctxt_entries
private
Entries tinygettext::Dictionary::entries
private
Dictionary* tinygettext::Dictionary::m_fallback
private
bool tinygettext::Dictionary::m_has_fallback
private
PluralForms tinygettext::Dictionary::plural_forms
private

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