src/tinygettext/tinygettext.hpp

Go to the documentation of this file.
00001 //  $Id: tinygettext.hpp 168 2009-11-18 17:55:48Z grumbel $
00002 //
00003 //  SuperTux
00004 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020 #ifndef HEADER_TINYGETTEXT_H
00021 #define HEADER_TINYGETTEXT_H
00022 
00023 #include <map>
00024 #include <vector>
00025 #include <set>
00026 #include <string>
00027 
00028 namespace TinyGetText {
00029 
00030 typedef int (*PluralFunc)(int n);
00031 
00032 struct LanguageDef {
00033   const char* code;
00034   const char* name;
00035   int         nplural;
00036   PluralFunc  plural;
00037 
00038   LanguageDef(const char* code_, const char* name_,  int nplural_, PluralFunc plural_)
00039     : code(code_), name(name_), nplural(nplural_), plural(plural_)
00040   {}
00041 };
00042 
00046 class Dictionary
00047 {
00048 private:
00049   typedef std::map<std::string, std::string> Entries;
00050   Entries entries;
00051 
00052   typedef std::map<std::string, std::map<int, std::string> > PluralEntries;
00053   PluralEntries plural_entries;
00054 
00055   LanguageDef language;
00056   std::string charset;
00057 public:
00059   Dictionary(const LanguageDef& language_, const std::string& charset = "");
00060 
00061   Dictionary();
00062 
00064   std::string get_charset() const;
00065 
00069   void set_charset(const std::string& charset);
00070 
00073   void set_language(const LanguageDef& lang);
00074 
00078   std::string translate(const std::string& msgid, const std::string& msgid2, int num);
00079 
00081   std::string translate(const std::string& msgid);
00083   const char* translate(const char* msgid);
00084 
00090   void add_translation(const std::string& msgid, const std::string& msgid2,
00091                        const std::map<int, std::string>& msgstrs);
00092 
00095   void add_translation(const std::string& msgid, const std::string& msgstr);
00096 };
00097 
00101 class DictionaryManager
00102 {
00103 private:
00104   typedef std::map<std::string, Dictionary> Dictionaries;
00105   Dictionaries dictionaries;
00106   typedef std::vector<std::string> SearchPath;
00107   SearchPath search_path;
00108   typedef std::map<std::string, std::string> Aliases;
00109   Aliases language_aliases;
00110   std::string charset;
00111   std::string language;
00112   Dictionary* current_dict;
00113   Dictionary empty_dict;
00114 
00115 public:
00116   DictionaryManager();
00117 
00120   Dictionary& get_dictionary()
00121   { return *current_dict; }
00122 
00124   Dictionary& get_dictionary(const std::string& langspec);
00125 
00127   void set_language(const std::string& langspec);
00128 
00130   const std::string& get_language() const;
00131 
00133   void set_charset(const std::string& charset);
00134 
00136   void set_language_alias(const std::string& alias, const std::string& lang);
00137 
00139   void add_directory(const std::string& pathname);
00140 
00142   std::set<std::string> get_languages();
00143 
00144 private:
00145   void parseLocaleAliases();
00147   std::string get_language_from_spec(const std::string& spec);
00148 };
00149 
00152 void read_po_file(Dictionary& dict, std::istream& in);
00153 LanguageDef& get_language_def(const std::string& name);
00154 
00155 } // namespace TinyGetText
00156 
00157 #endif
00158 
00159 /* EOF */

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