Pyrogenesis  trunk
dictionary_manager.hpp
Go to the documentation of this file.
1 // tinygettext - A gettext replacement that works directly on .po files
2 // Copyright (c) 2006 Ingo Ruhnke <grumbel@gmail.com>
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 //
8 // Permission is granted to anyone to use this software for any purpose,
9 // including commercial applications, and to alter it and redistribute it
10 // freely, subject to the following restrictions:
11 //
12 // 1. The origin of this software must not be misrepresented; you must not
13 // claim that you wrote the original software. If you use this software
14 // in a product, an acknowledgement in the product documentation would be
15 // appreciated but is not required.
16 // 2. Altered source versions must be plainly marked as such, and must not be
17 // misrepresented as being the original software.
18 // 3. This notice may not be removed or altered from any source distribution.
19 
20 #ifndef HEADER_TINYGETTEXT_DICTIONARY_MANAGER_HPP
21 #define HEADER_TINYGETTEXT_DICTIONARY_MANAGER_HPP
22 
23 #include <memory>
24 #include <set>
25 #include <string>
26 #include <unordered_map>
27 #include <vector>
28 
29 #include "dictionary.hpp"
30 #include "language.hpp"
31 
32 namespace tinygettext {
33 
34 class FileSystem;
35 
36 /** Manager class for dictionaries, you give it a bunch of directories
37  with .po files and it will then automatically load the right file
38  on demand depending on which language was set. */
40 {
41 private:
42  typedef std::unordered_map<Language, Dictionary*, Language_hash> Dictionaries;
43  Dictionaries dictionaries;
44 
45  typedef std::vector<std::string> SearchPath;
46  SearchPath search_path;
47 
48  std::string charset;
49  bool use_fuzzy;
50 
53 
55 
56  std::unique_ptr<FileSystem> filesystem;
57 
58  void clear_cache();
59 
60 public:
61  DictionaryManager(const std::string& charset_ = "UTF-8");
63 
64  /** Return the currently active dictionary, if none is set, an empty
65  dictionary is returned. */
67 
68  /** Get dictionary for language */
69  Dictionary& get_dictionary(const Language& language);
70 
71  /** Set a language based on a four? letter country code */
72  void set_language(const Language& language);
73 
74  /** returns the (normalized) country code of the currently used language */
75  Language get_language() const;
76 
77  void set_use_fuzzy(bool t);
78  bool get_use_fuzzy() const;
79 
80  /** Set a charset that will be set on the returned dictionaries */
81  void set_charset(const std::string& charset);
82 
83  /** Add a directory to the search path for dictionaries, earlier
84  added directories have higher priority then later added ones */
85  void add_directory(const std::string& pathname);
86 
87  /** Return a set of the available languages in their country code */
88  std::set<Language> get_languages();
89 
90  void set_filesystem(std::unique_ptr<FileSystem> filesystem);
91  std::string convertFilename2Language(const std::string &s_in) const;
92 
93 private:
96 };
97 
98 } // namespace tinygettext
99 
100 #endif
101 
102 /* EOF */
std::string convertFilename2Language(const std::string &s_in) const
This function converts a .po filename (e.g.
Definition: dictionary_manager.cpp:257
Dictionary & get_dictionary()
Return the currently active dictionary, if none is set, an empty dictionary is returned.
Definition: dictionary_manager.cpp:78
DictionaryManager & operator=(const DictionaryManager &)
void set_language(const Language &language)
Set a language based on a four? letter country code.
Definition: dictionary_manager.cpp:202
std::set< Language > get_languages()
Return a set of the available languages in their country code.
Definition: dictionary_manager.cpp:182
Language current_language
Definition: dictionary_manager.hpp:51
std::unordered_map< Language, Dictionary *, Language_hash > Dictionaries
Definition: dictionary_manager.hpp:42
Lightweight wrapper around LanguageSpec.
Definition: language.hpp:31
bool get_use_fuzzy() const
Definition: dictionary_manager.cpp:232
Manager class for dictionaries, you give it a bunch of directories with .po files and it will then au...
Definition: dictionary_manager.hpp:39
void set_use_fuzzy(bool t)
Definition: dictionary_manager.cpp:225
SearchPath search_path
Definition: dictionary_manager.hpp:46
void set_charset(const std::string &charset)
Set a charset that will be set on the returned dictionaries.
Definition: dictionary_manager.cpp:218
Language get_language() const
returns the (normalized) country code of the currently used language
Definition: dictionary_manager.cpp:212
void add_directory(const std::string &pathname)
Add a directory to the search path for dictionaries, earlier added directories have higher priority t...
Definition: dictionary_manager.cpp:238
Dictionaries dictionaries
Definition: dictionary_manager.hpp:43
Definition: dictionary.hpp:29
DictionaryManager(const std::string &charset_="UTF-8")
Definition: dictionary_manager.cpp:45
std::vector< std::string > SearchPath
Definition: dictionary_manager.hpp:45
A simple dictionary class that mimics gettext() behaviour.
Definition: dictionary.hpp:34
void set_filesystem(std::unique_ptr< FileSystem > filesystem)
Definition: dictionary_manager.cpp:245
~DictionaryManager()
Definition: dictionary_manager.cpp:57
bool use_fuzzy
Definition: dictionary_manager.hpp:49
Dictionary empty_dict
Definition: dictionary_manager.hpp:54
std::string charset
Definition: dictionary_manager.hpp:48
Dictionary * current_dict
Definition: dictionary_manager.hpp:52
std::unique_ptr< FileSystem > filesystem
Definition: dictionary_manager.hpp:56
void clear_cache()
Definition: dictionary_manager.cpp:66