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 <deque>
24#include <memory>
25#include <set>
26#include <string>
27#include <unordered_map>
28
29#include "dictionary.hpp"
30#include "language.hpp"
31
32namespace tinygettext {
33
34class 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{
41private:
42 typedef std::unordered_map<Language, Dictionary*, Language_hash> Dictionaries;
44
45 typedef std::deque<std::string> SearchPath;
47
48 std::string charset;
50
53
55
56 std::unique_ptr<FileSystem> filesystem;
57
58 void clear_cache();
59
60public:
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 Set @p precedence to true to invert this for a single addition. */
86 void add_directory(const std::string& pathname, bool precedence = false);
87
88 /** Remove a directory from the search path */
89 void remove_directory(const std::string& pathname);
90
91 /** Return a set of the available languages in their country code */
92 std::set<Language> get_languages();
93
94 void set_filesystem(std::unique_ptr<FileSystem> filesystem);
95 std::string convertFilename2Language(const std::string &s_in) const;
96
97private:
100};
101
102} // namespace tinygettext
103
104#endif
105
106/* EOF */
Manager class for dictionaries, you give it a bunch of directories with .po files and it will then au...
Definition: dictionary_manager.hpp:40
void set_use_fuzzy(bool t)
Definition: dictionary_manager.cpp:225
Dictionaries dictionaries
Definition: dictionary_manager.hpp:43
std::string charset
Definition: dictionary_manager.hpp:48
DictionaryManager(const DictionaryManager &)
void set_filesystem(std::unique_ptr< FileSystem > filesystem)
Definition: dictionary_manager.cpp:259
void add_directory(const std::string &pathname, bool precedence=false)
Add a directory to the search path for dictionaries, earlier added directories have higher priority t...
Definition: dictionary_manager.cpp:238
~DictionaryManager()
Definition: dictionary_manager.cpp:57
Dictionary * current_dict
Definition: dictionary_manager.hpp:52
Dictionary empty_dict
Definition: dictionary_manager.hpp:54
bool use_fuzzy
Definition: dictionary_manager.hpp:49
std::string convertFilename2Language(const std::string &s_in) const
This function converts a .po filename (e.g.
Definition: dictionary_manager.cpp:271
void clear_cache()
Definition: dictionary_manager.cpp:66
void set_charset(const std::string &charset)
Set a charset that will be set on the returned dictionaries.
Definition: dictionary_manager.cpp:218
bool get_use_fuzzy() const
Definition: dictionary_manager.cpp:232
Language current_language
Definition: dictionary_manager.hpp:51
Language get_language() const
returns the (normalized) country code of the currently used language
Definition: dictionary_manager.cpp:212
std::unique_ptr< FileSystem > filesystem
Definition: dictionary_manager.hpp:56
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
void remove_directory(const std::string &pathname)
Remove a directory from the search path.
Definition: dictionary_manager.cpp:248
SearchPath search_path
Definition: dictionary_manager.hpp:46
DictionaryManager(const std::string &charset_="UTF-8")
Definition: dictionary_manager.cpp:45
DictionaryManager & operator=(const DictionaryManager &)
Dictionary & get_dictionary()
Return the currently active dictionary, if none is set, an empty dictionary is returned.
Definition: dictionary_manager.cpp:78
std::unordered_map< Language, Dictionary *, Language_hash > Dictionaries
Definition: dictionary_manager.hpp:42
std::deque< std::string > SearchPath
Definition: dictionary_manager.hpp:45
A simple dictionary class that mimics gettext() behaviour.
Definition: dictionary.hpp:35
Lightweight wrapper around LanguageSpec.
Definition: language.hpp:32
Definition: L10n.h:36