Chris@16: // Chris@16: // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See Chris@16: // accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Chris@16: #ifndef BOOST_LOCLAE_GNU_GETTEXT_HPP Chris@16: #define BOOST_LOCLAE_GNU_GETTEXT_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace locale { Chris@16: /// \addtogroup message Chris@16: /// @{ Chris@16: Chris@16: Chris@16: /// Chris@16: /// \brief This namespace holds classes that provide GNU Gettext message catalogs support. Chris@16: /// Chris@16: namespace gnu_gettext { Chris@16: Chris@16: /// Chris@16: /// \brief This structure holds all information required for creating gnu-gettext message catalogs, Chris@16: /// Chris@16: /// The user is expected to set its parameters to load these catalogs correctly. This structure Chris@16: /// also allows providing functions for charset conversion. Note, you need to provide them, Chris@16: /// so this structure is not useful for wide characters without subclassing and it will also Chris@16: /// ignore gettext catalogs that use a charset different from \a encoding. Chris@16: /// Chris@16: struct messages_info { Chris@16: messages_info() : Chris@16: language("C"), Chris@16: locale_category("LC_MESSAGES") Chris@16: { Chris@16: } Chris@16: Chris@16: std::string language; ///< The language we load the catalog for, like "ru", "en", "de" Chris@16: std::string country; ///< The country we load the catalog for, like "US", "IL" Chris@16: std::string variant; ///< Language variant, like "euro" so it would look for catalog like de_DE\@euro Chris@16: std::string encoding; ///< Required target charset encoding. Ignored for wide characters. Chris@16: ///< For narrow, should specify the correct encoding required for this catalog Chris@16: std::string locale_category; ///< Locale category, is set by default to LC_MESSAGES, but may be changed Chris@16: /// Chris@16: /// \brief This type represents GNU Gettext domain name for the messages. Chris@16: /// Chris@16: /// It consists of two parameters: Chris@16: /// Chris@16: /// - name - the name of the domain - used for opening the file name Chris@16: /// - encoding - the encoding of the keys in the sources, default - UTF-8 Chris@16: /// Chris@16: struct domain { Chris@16: Chris@16: std::string name; ///< The name of the domain Chris@16: std::string encoding; ///< The character encoding for the domain Chris@16: domain() {} Chris@16: /// Chris@16: /// Create a domain object from the name that can hold an encoding after symbol "/" Chris@16: /// such that if n is "hello/cp1255" then the name would be "hello" and "encoding" would Chris@16: /// be "cp1255" and if n is "hello" then the name would be the same but encoding would be Chris@16: /// "UTF-8" Chris@16: /// Chris@16: domain(std::string const &n) Chris@16: { Chris@16: size_t pos = n.find("/"); Chris@16: if(pos==std::string::npos) { Chris@16: name = n; Chris@16: encoding = "UTF-8"; Chris@16: } Chris@16: else { Chris@16: name = n.substr(0,pos); Chris@16: encoding = n.substr(pos+1); Chris@16: } Chris@16: Chris@16: } Chris@16: Chris@16: /// Chris@16: /// Check whether two objects are equivalent, only names are compared, encoding is ignored Chris@16: /// Chris@16: bool operator==(domain const &other) const Chris@16: { Chris@16: return name==other.name; Chris@16: } Chris@16: /// Chris@16: /// Check whether two objects are distinct, only names are compared, encoding is ignored Chris@16: /// Chris@16: bool operator!=(domain const &other) const Chris@16: { Chris@16: return !(*this==other); Chris@16: } Chris@16: Chris@16: }; Chris@16: Chris@16: typedef std::vector domains_type; ///< Type that defines a list of domains that are loaded Chris@16: ///< The first one is the default one Chris@16: domains_type domains; ///< Message domains - application name, like my_app. So files named my_app.mo Chris@16: ///< would be loaded Chris@16: std::vector paths; ///< Paths to search files in. Under MS Windows it uses encoding Chris@16: ///< parameter to convert them to wide OS specific paths. Chris@16: Chris@16: /// Chris@16: /// The callback for custom file system support. This callback should read the file named \a file_name Chris@16: /// encoded in \a encoding character set into std::vector and return it. Chris@16: /// Chris@16: /// - If the file does not exist, it should return an empty vector. Chris@16: /// - If a error occurs during file read it should throw a error. Chris@16: /// Chris@16: /// \note The user should support only the encodings the locales are created for. So if the user Chris@16: /// uses only one encoding or the file system is encoding agnostic, he may ignore the \a encoding parameter. Chris@16: /// Chris@16: typedef function< Chris@16: std::vector( Chris@16: std::string const &file_name, Chris@16: std::string const &encoding Chris@16: ) Chris@16: > callback_type; Chris@16: Chris@16: /// Chris@16: /// The callback for handling custom file systems, if it is empty, the real OS file-system Chris@16: /// is being used. Chris@16: /// Chris@16: callback_type callback; Chris@16: Chris@16: }; Chris@16: Chris@16: /// Chris@16: /// Create a message_format facet using GNU Gettext catalogs. It uses \a info structure to get Chris@16: /// information about where to read them from and uses it for character set conversion (if needed) Chris@16: /// Chris@16: Chris@16: template Chris@16: message_format *create_messages_facet(messages_info const &info); Chris@16: Chris@16: /// \cond INTERNAL Chris@16: Chris@16: template<> Chris@16: BOOST_LOCALE_DECL message_format *create_messages_facet(messages_info const &info); Chris@16: Chris@16: template<> Chris@16: BOOST_LOCALE_DECL message_format *create_messages_facet(messages_info const &info); Chris@16: Chris@16: #ifdef BOOST_HAS_CHAR16_T Chris@16: template<> Chris@16: BOOST_LOCALE_DECL message_format *create_messages_facet(messages_info const &info); Chris@16: #endif Chris@16: Chris@16: #ifdef BOOST_HAS_CHAR32_T Chris@16: template<> Chris@16: BOOST_LOCALE_DECL message_format *create_messages_facet(messages_info const &info); Chris@16: #endif Chris@16: Chris@16: /// \endcond Chris@16: Chris@16: } // gnu_gettext Chris@16: Chris@16: /// @} Chris@16: Chris@16: } // locale Chris@16: } // boost Chris@16: Chris@16: #endif Chris@16: Chris@16: // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 Chris@16: