| 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
22 namespace 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;
81 domains_type domains;
83 std::vector<std::string> paths;
85
94 typedef std::function<std::vector<char>(const std::string& file_name, const std::string& encoding)>
95 callback_type;
96
99 callback_type callback;
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>>
112 BOOST_LOCALE_DECL message_format<CharType>* create_messages_facet(const messages_info& info);
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
boost::locale::info
a facet that holds general information about locale
Definition: info.hpp:26
boost::locale::message_format
This facet provides message formatting abilities.
Definition: message.hpp:49
boost::locale::gnu_gettext::create_messages_facet
message_format< CharType > * create_messages_facet(const messages_info &info)
boost::locale::gnu_gettext::messages_info::domain
This type represents GNU Gettext domain name for the messages.
Definition: gnu_gettext.hpp:52
boost::locale::gnu_gettext::messages_info::domain::domain
domain(const std::string &n)
Definition: gnu_gettext.hpp:61
boost::locale::gnu_gettext::messages_info::domain::operator!=
bool operator!=(const domain &other) const
Check whether two objects are distinct, only names are compared, encoding is ignored.
Definition: gnu_gettext.hpp:76
boost::locale::gnu_gettext::messages_info::domain::encoding
std::string encoding
The character encoding for the domain.
Definition: gnu_gettext.hpp:54
boost::locale::gnu_gettext::messages_info::domain::operator==
bool operator==(const domain &other) const
Check whether two objects are equivalent, only names are compared, encoding is ignored.
Definition: gnu_gettext.hpp:74
boost::locale::gnu_gettext::messages_info::domain::name
std::string name
The name of the domain.
Definition: gnu_gettext.hpp:53
boost::locale::gnu_gettext::messages_info
This structure holds all information required for creating gnu-gettext message catalogs,...
Definition: gnu_gettext.hpp:35
boost::locale::gnu_gettext::messages_info::language
std::string language
The language we load the catalog for, like "ru", "en", "de".
Definition: gnu_gettext.hpp:38
boost::locale::gnu_gettext::messages_info::domains
domains_type domains
Definition: gnu_gettext.hpp:81
boost::locale::gnu_gettext::messages_info::get_catalog_paths
std::vector< std::string > get_catalog_paths() const
Get paths to folders which may contain catalog files.
boost::locale::gnu_gettext::messages_info::paths
std::vector< std::string > paths
Definition: gnu_gettext.hpp:83
boost::locale::gnu_gettext::messages_info::locale_category
std::string locale_category
Definition: gnu_gettext.hpp:43
boost::locale::gnu_gettext::messages_info::callback_type
std::function< std::vector< char >(const std::string &file_name, const std::string &encoding)> callback_type
Definition: gnu_gettext.hpp:95
boost::locale::gnu_gettext::messages_info::encoding
std::string encoding
Definition: gnu_gettext.hpp:41
boost::locale::gnu_gettext::messages_info::callback
callback_type callback
Definition: gnu_gettext.hpp:99
boost::locale::gnu_gettext::messages_info::domains_type
std::vector< domain > domains_type
Definition: gnu_gettext.hpp:79
boost::locale::gnu_gettext::messages_info::country
std::string country
The country we load the catalog for, like "US", "IL".
Definition: gnu_gettext.hpp:39
boost::locale::gnu_gettext::messages_info::variant
std::string variant
Language variant, like "euro" so it would look for catalog like de_DE@euro.
Definition: gnu_gettext.hpp:40
- © Copyright 2009-2012 Artyom Beilis, Distributed under the Boost Software License, Version 1.0.