TinyGetText Namespace Reference


Classes

class  POFileReader
struct  LanguageDef
class  Dictionary
 A simple dictionary class that mimics gettext() behaviour. More...
class  DictionaryManager
 Manager class for dictionaries, you give it a bunch of directories with .po files and it will then automatically load the right file on demand depending on which language was set. More...

Typedefs

typedef int(*) PluralFunc (int n)

Functions

std::string convert (const std::string &text, const std::string &from_charset, const std::string &to_charset)
 Convert which is in from_charset to to_charset and return it.
bool has_suffix (const std::string &lhs, const std::string rhs)
bool has_prefix (const std::string &lhs, const std::string rhs)
int plural1 (int)
int plural2_1 (int n)
int plural2_2 (int n)
int plural3_lv (int n)
int plural3_ga (int n)
int plural3_lt (int n)
int plural3_1 (int n)
int plural3_sk (int n)
int plural3_pl (int n)
int plural3_sl (int n)
LanguageDefget_language_def (const std::string &name)
void read_po_file (Dictionary &dict, std::istream &in)
 Read the content of the .po file given as in into the dictionary given as dict.

Variables

LanguageDef lang_hu ("hu","Hungarian", 1, plural1)
 Language Definitions.
LanguageDef lang_ja ("ja","Japanese", 1, plural1)
LanguageDef lang_ko ("ko","Korean", 1, plural1)
LanguageDef lang_tr ("tr","Turkish", 1, plural1)
LanguageDef lang_da ("da","Danish", 2, plural2_1)
LanguageDef lang_nl ("nl","Dutch", 2, plural2_1)
LanguageDef lang_en ("en","English", 2, plural2_1)
LanguageDef lang_fo ("fo","Faroese", 2, plural2_1)
LanguageDef lang_de ("de","German", 2, plural2_1)
LanguageDef lang_nb ("nb","Norwegian Bokmal", 2, plural2_1)
LanguageDef lang_no ("no","Norwegian", 2, plural2_1)
LanguageDef lang_nn ("nn","Norwegian Nynorsk", 2, plural2_1)
LanguageDef lang_sv ("sv","Swedish", 2, plural2_1)
LanguageDef lang_et ("et","Estonian", 2, plural2_1)
LanguageDef lang_fi ("fi","Finnish", 2, plural2_1)
LanguageDef lang_el ("el","Greek", 2, plural2_1)
LanguageDef lang_he ("he","Hebrew", 2, plural2_1)
LanguageDef lang_it ("it","Italian", 2, plural2_1)
LanguageDef lang_pt ("pt","Portuguese", 2, plural2_1)
LanguageDef lang_es ("es","Spanish", 2, plural2_1)
LanguageDef lang_eo ("eo","Esperanto", 2, plural2_1)
LanguageDef lang_fr ("fr","French", 2, plural2_2)
LanguageDef lang_pt_BR ("pt_BR","Brazilian", 2, plural2_2)
LanguageDef lang_lv ("lv","Latvian", 3, plural3_lv)
LanguageDef lang_ga ("ga","Irish", 3, plural3_ga)
LanguageDef lang_lt ("lt","Lithuanian", 3, plural3_lt)
LanguageDef lang_hr ("hr","Croatian", 3, plural3_1)
LanguageDef lang_cs ("cs","Czech", 3, plural3_1)
LanguageDef lang_ru ("ru","Russian", 3, plural3_1)
LanguageDef lang_uk ("uk","Ukrainian", 3, plural3_1)
LanguageDef lang_sk ("sk","Slovak", 3, plural3_sk)
LanguageDef lang_pl ("pl","Polish", 3, plural3_pl)
LanguageDef lang_sl ("sl","Slovenian", 3, plural3_sl)


Typedef Documentation

typedef int(*) TinyGetText::PluralFunc(int n)

Definition at line 30 of file tinygettext.hpp.


Function Documentation

std::string TinyGetText::convert ( const std::string &  text,
const std::string &  from_charset,
const std::string &  to_charset 
)

Convert which is in from_charset to to_charset and return it.

Definition at line 46 of file tinygettext.cpp.

References log_warning.

Referenced by GLTexture::GLTexture(), optimize(), and TinyGetText::POFileReader::tokenize_po().

00049 {
00050 #ifndef GP2X
00051   if (from_charset == to_charset)
00052     return text;
00053 
00054   char *in = new char[text.length() + 1];
00055   strcpy(in, text.c_str());
00056   char *out = SDL_iconv_string(to_charset.c_str(), from_charset.c_str(), in, text.length() + 1);
00057   delete[] in; 
00058   if(out == 0)
00059   {
00060     log_warning << "Error: conversion from " << from_charset << " to " << to_charset << " failed" << std::endl;
00061     return "";
00062   }
00063   std::string ret(out);
00064   SDL_free(out);
00065   return ret;
00066 #else
00067   log_warning << "FIXME: Char conversion not supported on GP2X!" << std::endl;
00068   return "";
00069 #endif
00070 #if 0
00071   iconv_t cd = SDL_iconv_open(to_charset.c_str(), from_charset.c_str());
00072 
00073   size_t in_len = text.length();
00074   size_t out_len = text.length()*3; // FIXME: cross fingers that this is enough
00075 
00076   char*  out_orig = new char[out_len];
00077   char*  in_orig  = new char[in_len+1];
00078   strcpy(in_orig, text.c_str());
00079 
00080   char* out = out_orig;
00081   ICONV_CONST char* in  = in_orig;
00082   size_t out_len_temp = out_len; // iconv is counting down the bytes it has
00083                                  // written from this...
00084 
00085   size_t retval = SDL_iconv(cd, &in, &in_len, &out, &out_len_temp);
00086   out_len -= out_len_temp; // see above
00087   if (retval == (size_t) -1)
00088     {
00089       log_warning << strerror(errno) << std::endl;
00090       log_warning << "Error: conversion from " << from_charset << " to " << to_charset << " went wrong: " << retval << std::endl;
00091       return "";
00092     }
00093   SDL_iconv_close(cd);
00094 
00095   std::string ret(out_orig, out_len);
00096   delete[] out_orig;
00097   delete[] in_orig;
00098   return ret;
00099 #endif
00100 }

LanguageDef & TinyGetText::get_language_def ( const std::string &  name  ) 

Definition at line 167 of file tinygettext.cpp.

References lang_cs, lang_da, lang_de, lang_el, lang_en, lang_eo, lang_es, lang_et, lang_fi, lang_fo, lang_fr, lang_ga, lang_he, lang_hr, lang_hu, lang_it, lang_ja, lang_ko, lang_lt, lang_lv, lang_nb, lang_nl, lang_nn, lang_no, lang_pl, lang_pt, lang_pt_BR, lang_ru, lang_sk, lang_sl, lang_sv, lang_tr, and lang_uk.

Referenced by TinyGetText::DictionaryManager::get_dictionary().

00168 {
00169   if (name == "hu") return lang_hu;
00170   else if (name == "ja") return lang_ja;
00171   else if (name == "ko") return lang_ko;
00172   else if (name == "tr") return lang_tr;
00173   else if (name == "da") return lang_da;
00174   else if (name == "nl") return lang_nl;
00175   else if (name == "en") return lang_en;
00176   else if (name == "fo") return lang_fo;
00177   else if (name == "de") return lang_de;
00178   else if (name == "nb") return lang_nb;
00179   else if (name == "no") return lang_no;
00180   else if (name == "nn") return lang_nn;
00181   else if (name == "sv") return lang_sv;
00182   else if (name == "et") return lang_et;
00183   else if (name == "fi") return lang_fi;
00184   else if (name == "el") return lang_el;
00185   else if (name == "he") return lang_he;
00186   else if (name == "it") return lang_it;
00187   else if (name == "pt") return lang_pt;
00188   else if (name == "es") return lang_es;
00189   else if (name == "eo") return lang_eo;
00190   else if (name == "fr") return lang_fr;
00191   else if (name == "pt_BR") return lang_pt_BR;
00192   else if (name == "lv") return lang_lv;
00193   else if (name == "ga") return lang_ga;
00194   else if (name == "lt") return lang_lt;
00195   else if (name == "hr") return lang_hr;
00196   else if (name == "cs") return lang_cs;
00197   else if (name == "ru") return lang_ru;
00198   else if (name == "uk") return lang_uk;
00199   else if (name == "sk") return lang_sk;
00200   else if (name == "pl") return lang_pl;
00201   else if (name == "sl") return lang_sl;
00202   else return lang_en;
00203 }

bool TinyGetText::has_prefix ( const std::string &  lhs,
const std::string  rhs 
)

Definition at line 110 of file tinygettext.cpp.

Referenced by TinyGetText::POFileReader::parse_header(), and TinyGetText::POFileReader::tokenize_po().

00111 {
00112   if (lhs.length() < rhs.length())
00113     return false;
00114   else
00115     return lhs.compare(0, rhs.length(), rhs) == 0;
00116 }

bool TinyGetText::has_suffix ( const std::string &  lhs,
const std::string  rhs 
)

Definition at line 102 of file tinygettext.cpp.

Referenced by TinyGetText::DictionaryManager::get_languages().

00103 {
00104   if (lhs.length() < rhs.length())
00105     return false;
00106   else
00107     return lhs.compare(lhs.length() - rhs.length(), rhs.length(), rhs) == 0;
00108 }

int TinyGetText::plural1 ( int   ) 

Definition at line 118 of file tinygettext.cpp.

00118 { return 0; }

int TinyGetText::plural2_1 ( int  n  ) 

Definition at line 119 of file tinygettext.cpp.

Referenced by TinyGetText::Dictionary::translate().

00119 { return (n != 1); }

int TinyGetText::plural2_2 ( int  n  ) 

Definition at line 120 of file tinygettext.cpp.

00120 { return (n > 1); }

int TinyGetText::plural3_1 ( int  n  ) 

Definition at line 124 of file tinygettext.cpp.

00124 { return (n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); }

int TinyGetText::plural3_ga ( int  n  ) 

Definition at line 122 of file tinygettext.cpp.

00122 { return n==1 ? 0 : n==2 ? 1 : 2; }

int TinyGetText::plural3_lt ( int  n  ) 

Definition at line 123 of file tinygettext.cpp.

00123 { return (n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2); }

int TinyGetText::plural3_lv ( int  n  ) 

Definition at line 121 of file tinygettext.cpp.

00121 { return (n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2); }

int TinyGetText::plural3_pl ( int  n  ) 

Definition at line 126 of file tinygettext.cpp.

00126 { return (n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); }

int TinyGetText::plural3_sk ( int  n  ) 

Definition at line 125 of file tinygettext.cpp.

00125 { return (n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2; }

int TinyGetText::plural3_sl ( int  n  ) 

Definition at line 127 of file tinygettext.cpp.

00127 { return (n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3); }

void TinyGetText::read_po_file ( Dictionary &  dict_,
std::istream &  in 
)

Read the content of the .po file given as in into the dictionary given as dict.

Definition at line 774 of file tinygettext.cpp.

Referenced by TinyGetText::DictionaryManager::get_dictionary().

00775 {
00776   POFileReader reader(in, dict_);
00777 }


Variable Documentation

LanguageDef TinyGetText::lang_cs("cs","Czech", 3, plural3_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_da("da","Danish", 2, plural2_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_de("de","German", 2, plural2_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_el("el","Greek", 2, plural2_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_en("en","English", 2, plural2_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_eo("eo","Esperanto", 2, plural2_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_es("es","Spanish", 2, plural2_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_et("et","Estonian", 2, plural2_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_fi("fi","Finnish", 2, plural2_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_fo("fo","Faroese", 2, plural2_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_fr("fr","French", 2, plural2_2)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_ga("ga","Irish", 3, plural3_ga)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_he("he","Hebrew", 2, plural2_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_hr("hr","Croatian", 3, plural3_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_hu("hu","Hungarian", 1, plural1)

Language Definitions.

Referenced by get_language_def().

LanguageDef TinyGetText::lang_it("it","Italian", 2, plural2_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_ja("ja","Japanese", 1, plural1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_ko("ko","Korean", 1, plural1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_lt("lt","Lithuanian", 3, plural3_lt)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_lv("lv","Latvian", 3, plural3_lv)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_nb("nb","Norwegian Bokmal", 2, plural2_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_nl("nl","Dutch", 2, plural2_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_nn("nn","Norwegian Nynorsk", 2, plural2_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_no("no","Norwegian", 2, plural2_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_pl("pl","Polish", 3, plural3_pl)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_pt("pt","Portuguese", 2, plural2_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_pt_BR("pt_BR","Brazilian", 2, plural2_2)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_ru("ru","Russian", 3, plural3_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_sk("sk","Slovak", 3, plural3_sk)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_sl("sl","Slovenian", 3, plural3_sl)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_sv("sv","Swedish", 2, plural2_1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_tr("tr","Turkish", 1, plural1)

Referenced by get_language_def().

LanguageDef TinyGetText::lang_uk("uk","Ukrainian", 3, plural3_1)

Referenced by get_language_def().


Generated on Mon Jun 9 03:38:41 2014 for SuperTux by  doxygen 1.5.1