Boost.Locale
gnu_gettext.hpp
1//
2// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3// Copyright (c) 2022-2024 Alexander Grund
4//
5// Distributed under the Boost Software License, Version 1.0.
6// https://www.boost.org/LICENSE_1_0.txt
7
8#ifndef BOOST_LOCALE_GNU_GETTEXT_HPP
9#define BOOST_LOCALE_GNU_GETTEXT_HPP
10
11#include <boost/locale/detail/is_supported_char.hpp>
12#include <boost/locale/message.hpp>
13#include <functional>
14#include <stdexcept>
15#include <type_traits>
16#include <vector>
17
18#ifdef BOOST_MSVC
19# pragma warning(push)
20# pragma warning(disable : 4251) // "identifier" : class "type" needs to have dll-interface...
21#endif
22
23namespace boost { namespace locale {
26
28 namespace gnu_gettext {
29
36 struct BOOST_LOCALE_DECL messages_info {
37 messages_info() : language("C"), locale_category("LC_MESSAGES") {}
38
39 std::string language;
40 std::string country;
41 std::string variant;
42 std::string encoding;
44 std::string locale_category;
53 struct domain {
54 std::string name;
55 std::string encoding;
56 domain() = default;
57
62 domain(const std::string& n)
63 {
64 const size_t pos = n.find('/');
65 if(pos == std::string::npos) {
66 name = n;
67 encoding = "UTF-8";
68 } else {
69 name = n.substr(0, pos);
70 encoding = n.substr(pos + 1);
71 }
72 }
73
75 bool operator==(const domain& other) const { return name == other.name; }
77 bool operator!=(const domain& other) const { return !(*this == other); }
78 };
79
80 typedef std::vector<domain> domains_type;
84 std::vector<std::string> paths;
86
95 typedef std::function<std::vector<char>(const std::string& file_name, const std::string& encoding)>
97
101
103 std::vector<std::string> get_catalog_paths() const;
104
105 private:
107 std::vector<std::string> get_lang_folders() const;
108 };
109
112 template<typename CharType, class = boost::locale::detail::enable_if_is_supported_char<CharType>>
114
115 } // namespace gnu_gettext
116
118
119}} // namespace boost::locale
120
121#ifdef BOOST_MSVC
122# pragma warning(pop)
123#endif
124
125#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:53
domain(const std::string &n)
Definition gnu_gettext.hpp:62
bool operator!=(const domain &other) const
Check whether two objects are distinct, only names are compared, encoding is ignored.
Definition gnu_gettext.hpp:77
std::string encoding
The character encoding for the domain.
Definition gnu_gettext.hpp:55
bool operator==(const domain &other) const
Check whether two objects are equivalent, only names are compared, encoding is ignored.
Definition gnu_gettext.hpp:75
std::string name
The name of the domain.
Definition gnu_gettext.hpp:54
This structure holds all information required for creating gnu-gettext message catalogs,...
Definition gnu_gettext.hpp:36
std::string language
The language we load the catalog for, like "ru", "en", "de".
Definition gnu_gettext.hpp:39
domains_type domains
Definition gnu_gettext.hpp:82
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:84
std::vector< domain > domains_type
Definition gnu_gettext.hpp:80
std::string locale_category
Definition gnu_gettext.hpp:44
std::string encoding
Definition gnu_gettext.hpp:42
callback_type callback
Definition gnu_gettext.hpp:100
std::function< std::vector< char >(const std::string &file_name, const std::string &encoding)> callback_type
Definition gnu_gettext.hpp:96
std::string country
The country we load the catalog for, like "US", "IL".
Definition gnu_gettext.hpp:40
std::string variant
Language variant, like "euro" so it would look for catalog like de_DE@euro.
Definition gnu_gettext.hpp:41