add static import of tinygettext
[supertux.git] / external / tinygettext / tinygettext / dictionary_manager.hpp
1 //  tinygettext - A gettext replacement that works directly on .po files
2 //  Copyright (C) 2006 Ingo Ruhnke <grumbel@gmx.de>
3 //
4 //  This program is free software; you can redistribute it and/or
5 //  modify it under the terms of the GNU General Public License
6 //  as published by the Free Software Foundation; either version 2
7 //  of the License, or (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program; if not, write to the Free Software
16 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
18 #ifndef HEADER_TINYGETTEXT_DICTIONARY_MANAGER_HPP
19 #define HEADER_TINYGETTEXT_DICTIONARY_MANAGER_HPP
20
21 #include <map>
22 #include <set>
23 #include <string>
24 #include <vector>
25 #include <memory>
26
27 #include "dictionary.hpp"
28 #include "language.hpp"
29
30 namespace tinygettext {
31
32 class FileSystem;
33
34 /** Manager class for dictionaries, you give it a bunch of directories
35     with .po files and it will then automatically load the right file
36     on demand depending on which language was set. */
37 class DictionaryManager
38 {
39 private:
40   typedef std::map<Language, Dictionary*> Dictionaries;
41   Dictionaries dictionaries;
42
43   typedef std::vector<std::string> SearchPath;
44   SearchPath search_path;
45
46   std::string charset;
47   bool        use_fuzzy;
48   
49   Language    current_language;
50   Dictionary* current_dict;
51
52   Dictionary  empty_dict;
53
54   std::auto_ptr<FileSystem> filesystem;
55
56   void clear_cache();
57
58 public:
59   DictionaryManager(const std::string& charset_ = "UTF-8");
60   ~DictionaryManager();
61
62   /** Return the currently active dictionary, if none is set, an empty
63       dictionary is returned. */
64   Dictionary& get_dictionary();
65
66   /** Get dictionary for language */
67   Dictionary& get_dictionary(const Language& language);
68
69   /** Set a language based on a four? letter country code */
70   void set_language(const Language& language);
71
72   /** returns the (normalized) country code of the currently used language */
73   Language get_language() const;
74
75   void set_use_fuzzy(bool t);
76   bool get_use_fuzzy() const;
77
78   /** Set a charset that will be set on the returned dictionaries */
79   void set_charset(const std::string& charset);
80
81   /** Add a directory to the search path for dictionaries, earlier
82       added directories have higher priority then later added ones */
83   void add_directory(const std::string& pathname);
84
85   /** Return a set of the available languages in their country code */
86   std::set<Language> get_languages();
87
88   void set_filesystem(std::auto_ptr<FileSystem> filesystem);
89
90 private:
91   DictionaryManager (const DictionaryManager&);
92   DictionaryManager& operator= (const DictionaryManager&);
93 };
94
95 } // namespace tinygettext
96
97 #endif
98
99 /* EOF */