Boost.Locale
gnu_gettext.hpp
1//
2// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3//
4// Distributed under the Boost Software License, Version 1.0.
5// https://www.boost.org/LICENSE_1_0.txt
6
7#ifndef BOOST_LOCLAE_GNU_GETTEXT_HPP
8#define BOOST_LOCLAE_GNU_GETTEXT_HPP
9
10#include <boost/locale/detail/is_supported_char.hpp>
11#include <boost/locale/message.hpp>
12#include <functional>
13#include <stdexcept>
14#include <type_traits>
15#include <vector>
16
17#ifdef BOOST_MSVC
18# pragma warning(push)
19# pragma warning(disable : 4251) // "identifier" : class "type" needs to have dll-interface...
20#endif
21
22namespace boost { namespace locale {
25
27 namespace gnu_gettext {
28
35 struct BOOST_LOCALE_DECL messages_info {
36 messages_info() : language("C"), locale_category("LC_MESSAGES") {}
37
38 std::string language;
39 std::string country;
40 std::string variant;
41 std::string encoding;
43 std::string locale_category;
52 struct domain {
53 std::string name;
54 std::string encoding;
55 domain() = default;
56
61 domain(const std::string& n)
62 {
63 const size_t pos = n.find('/');
64 if(pos == std::string::npos) {
65 name = n;
66 encoding = "UTF-8";
67 } else {
68 name = n.substr(0, pos);
69 encoding = n.substr(pos + 1);
70 }
71 }
72
74 bool operator==(const domain& other) const { return name == other.name; }
76 bool operator!=(const domain& other) const { return !(*this == other); }
77 };
78
79 typedef std::vector<domain> domains_type;
83 std::vector<std::string> paths;
85
94 typedef std::function<std::vector<char>(const std::string& file_name, const std::string& encoding)>
96
100
102 std::vector<std::string> get_catalog_paths() const;
103
104 private:
106 std::vector<std::string> get_lang_folders() const;
107 };
108
111 template<typename CharType, class = boost::locale::detail::enable_if_is_supported_char<CharType>>
113
114 } // namespace gnu_gettext
115
117
118}} // namespace boost::locale
119
120#ifdef BOOST_MSVC
121# pragma warning(pop)
122#endif
123
124#endif
a facet that holds general information about locale
Definition: info.hpp:26
This facet provides message formatting abilities.
Definition: message.hpp:49
message_format< CharType > * create_messages_facet(const messages_info &info)
This type represents GNU Gettext domain name for the messages.
Definition: gnu_gettext.hpp:52
domain(const std::string &n)
Definition: gnu_gettext.hpp:61
bool operator!=(const domain &other) const
Check whether two objects are distinct, only names are compared, encoding is ignored.
Definition: gnu_gettext.hpp:76
std::string encoding
The character encoding for the domain.
Definition: gnu_gettext.hpp:54
bool operator==(const domain &other) const
Check whether two objects are equivalent, only names are compared, encoding is ignored.
Definition: gnu_gettext.hpp:74
std::string name
The name of the domain.
Definition: gnu_gettext.hpp:53
This structure holds all information required for creating gnu-gettext message catalogs,...
Definition: gnu_gettext.hpp:35
std::string language
The language we load the catalog for, like "ru", "en", "de".
Definition: gnu_gettext.hpp:38
domains_type domains
Definition: gnu_gettext.hpp:81
std::vector< std::string > get_catalog_paths() const
Get paths to folders which may contain catalog files.
std::vector< std::string > paths
Definition: gnu_gettext.hpp:83
std::string locale_category
Definition: gnu_gettext.hpp:43
std::function< std::vector< char >(const std::string &file_name, const std::string &encoding)> callback_type
Definition: gnu_gettext.hpp:95
std::string encoding
Definition: gnu_gettext.hpp:41
callback_type callback
Definition: gnu_gettext.hpp:99
std::vector< domain > domains_type
Definition: gnu_gettext.hpp:79
std::string country
The country we load the catalog for, like "US", "IL".
Definition: gnu_gettext.hpp:39
std::string variant
Language variant, like "euro" so it would look for catalog like de_DE@euro.
Definition: gnu_gettext.hpp:40