std::messages

From Cppreference

Jump to: navigation, search
Defined in header <locale>

template< class charT >
class messages;

Class std::messages encapsulates retrieval of strings from message catalogs, such as the ones provided by GNU gettext or by POSIX catgets.

Two specializations are provided by the standard library and are implemented by all locale objects created in a C++ program:

Defined in header <locale>
std::messages<char> accesses narrow string message catalog
std::codecvt<wchar_t> accesses wide string message catalog

Contents

[edit] Member types

Member type Definition
char_type charT
string_type std::basic_string<charT>

[edit] Member objects

Member name Type
id (static) std::locale::id

[edit] Member functions

(constructor)
constructs a new messages facet
(public member function)
(destructor)
destructs a messages facet
(protected member function)
Public member functions (pubic interface)
open
invokes do_open
(public member function)
get
invokes do_get
(public member function)
close
invokes do_close
(public member function)
Virtual member functions (can be overridden in a user-defined facet derived from codecvt
do_open [virtual]
opens a named message catalog
(virtual protected member function)
do_get [virtual]
retrieves a message from an open message catalog
(virtual protected member function)
do_close [virtual]
closes a message catalog
(virtual protected member function)

Inherited from std::messages_base

Type Definition
catalog int


[edit] Example

The following example demonstrated retrieval of GNU gettext messages

#include <iostream>
#include <locale>
int main()
{
    std::locale loc("de_DE");
    auto& facet = std::use_facet<std::messages<char>>(loc);
    const char* dir = "/usr/share/gcc-data/x86_64-pc-linux-gnu/4.6.1/locale";
    auto cat = facet.open("libstdc++", loc, dir);
    std::cout << "\"please\" in German: "
              << facet.get(cat, 0, 0, "please") << '\n'
              << "\"thank you\" in German: "
              << facet.get(cat, 0, 0, "thank you") << '\n';
    facet.close(cat);
}

Output:

"please" in German: bitte
"thank you" in German: danke

[edit] See also

messages_base
defines messages catalog type
(class template)
messages_byname
creates a messages facet for the named locale
(class template)