Namespaces
Variants
Views
Actions

std::messages::open, std::messages::do_open

From cppreference.com
< cpp‎ | locale‎ | messages
Revision as of 21:08, 25 February 2013 by Cubbi (Talk | contribs)

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <locale>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td >
public:
catalog open( const std::basic_string<char>& name, const std::locale& loc) const;
</td>

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
protected:
virtual catalog do_open( const std::basic_string<char>& name, const std::locale& loc) const;
</td>

<td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

1) public member function, calls the protected virtual member function do_open of the most derived class.

2) Obtains a value of type catalog (inherited from std::messages_base), which can be passed to Template:rlpf to retrieve messages from the message catalog named by name. This value is usable until passed to Template:rlpf.

Contents

Parameters

name - name of the message catalog to open
loc - a locale object that provides additional facets that may be required to read messages from the catalog, such as std::codecvt to perform wide/multibyte conversions

Return value

The non-negative value of type catalog that can be used with Template:rlpf and Template:rlpf. Returns a negative value if the catalog could not be opened.

Notes

On POSIX systems, this function call usually translates to a call to catopen(). In GNU libstdc++, it calls textdomain.

The actual catalog location is implementation-defined: for the catalog "sed" (message catalogs installed with the Unix utility 'sed') in German locale, for example, the file opened by this function call may be /usr/lib/nls/msg/de_DE/sed.cat, /usr/lib/locale/de_DE/LC_MESSAGES/sed.cat, or /usr/share/locale/de/LC_MESSAGES/sed.mo.

Example

The following example demonstrated retrieval of messages: on a typical GNU/Linux system it reads from /usr/share/locale/de/LC_MESSAGES/sed.mo

#include <iostream>
#include <locale>
 
int main()
{
    std::locale loc("de_DE.utf8");
    std::cout.imbue(loc);
    auto& facet = std::use_facet<std::messages<char>>(loc);
    auto cat = facet.open("sed", loc);
    if(cat < 0 )
        std::cout << "Could not open german \"sed\" message catalog\n";
    else
        std::cout << "\"No match\" in German: "
                  << facet.get(cat, 0, 0, "No match") << '\n'
                  << "\"Memory exhausted\" in German: "
                  << facet.get(cat, 0, 0, "Memory exhausted") << '\n';
    facet.close(cat);
}

Output:

"No match" in German: Keine Übereinstimmung
"Memory exhausted" in German: Speicher erschöpft

See also