Boost.Locale
Message Formatting (translation)

Modules

 I/O Stream manipulators
 

Namespaces

namespace  boost::locale::gnu_gettext
 This namespace holds classes that provide GNU Gettext message catalogs support.
 
namespace  boost::locale::as
 This namespace includes all manipulators that can be used on IO streams.
 

Classes

class  boost::locale::message_format< CharType >
 This facet provides message formatting abilities. More...
 
class  boost::locale::basic_message< CharType >
 This class represents a message that can be converted to a specific locale message. More...
 

Typedefs

using boost::locale::count_type = long long
 Type used for the count/n argument to the translation functions choosing between singular and plural forms.
 
typedef CharType boost::locale::message_format< CharType >::char_type
 Character type.
 
typedef std::basic_string< CharType > boost::locale::message_format< CharType >::string_type
 String type.
 
typedef CharType boost::locale::basic_message< CharType >::char_type
 The character this message object is used with.
 
typedef std::basic_string< char_typeboost::locale::basic_message< CharType >::string_type
 The string type this object can be used with.
 
typedef message_format< char_typeboost::locale::basic_message< CharType >::facet_type
 The type of the facet the messages are fetched with.
 
typedef basic_message< char > boost::locale::message
 Convenience typedef for char.
 
typedef basic_message< wchar_t > boost::locale::wmessage
 Convenience typedef for wchar_t.
 
typedef basic_message< char8_t > boost::locale::u8message
 Convenience typedef for char8_t.
 
typedef basic_message< char16_t > boost::locale::u16message
 Convenience typedef for char16_t.
 
typedef basic_message< char32_t > boost::locale::u32message
 Convenience typedef for char32_t.
 

Functions

 boost::locale::message_format< CharType >::message_format (size_t refs=0)
 Standard constructor.
 
virtual const char_typeboost::locale::message_format< CharType >::get (int domain_id, const char_type *context, const char_type *id) const =0
 
virtual const char_typeboost::locale::message_format< CharType >::get (int domain_id, const char_type *context, const char_type *single_id, count_type n) const =0
 
virtual int boost::locale::message_format< CharType >::domain (const std::string &domain) const =0
 Convert a string that defines domain to the integer id used by get functions.
 
virtual const char_typeboost::locale::message_format< CharType >::convert (const char_type *msg, string_type &buffer) const =0
 
 boost::locale::basic_message< CharType >::basic_message ()
 Create default empty message.
 
 boost::locale::basic_message< CharType >::basic_message (const char_type *id)
 
 boost::locale::basic_message< CharType >::basic_message (const char_type *single, const char_type *plural, count_type n)
 
 boost::locale::basic_message< CharType >::basic_message (const char_type *context, const char_type *id)
 
 boost::locale::basic_message< CharType >::basic_message (const char_type *context, const char_type *single, const char_type *plural, count_type n)
 
 boost::locale::basic_message< CharType >::basic_message (const string_type &id)
 Create a simple message from a string.
 
 boost::locale::basic_message< CharType >::basic_message (const string_type &single, const string_type &plural, count_type number)
 
 boost::locale::basic_message< CharType >::basic_message (const string_type &context, const string_type &id)
 Create a simple message from a string with context.
 
 boost::locale::basic_message< CharType >::basic_message (const string_type &context, const string_type &single, const string_type &plural, count_type number)
 
 boost::locale::basic_message< CharType >::basic_message (const basic_message &)=default
 Copy an object.
 
 boost::locale::basic_message< CharType >::basic_message (basic_message &&) noexcept=default
 
basic_messageboost::locale::basic_message< CharType >::operator= (const basic_message &)=default
 Assign other message object to this one.
 
basic_messageboost::locale::basic_message< CharType >::operator= (basic_message &&) noexcept(std::is_nothrow_move_assignable< string_type >::value)=default
 
void boost::locale::basic_message< CharType >::swap (basic_message &other) noexcept(noexcept(std::declval< string_type & >().swap(std::declval< string_type & >())))
 Swap two message objects.
 
 boost::locale::basic_message< CharType >::operator string_type () const
 Message class can be explicitly converted to string class.
 
string_type boost::locale::basic_message< CharType >::str () const
 Translate message to a string in the default global locale, using default domain.
 
string_type boost::locale::basic_message< CharType >::str (const std::locale &locale) const
 Translate message to a string in the locale locale, using default domain.
 
string_type boost::locale::basic_message< CharType >::str (const std::locale &locale, const std::string &domain_id) const
 Translate message to a string using locale locale and message domain domain_id.
 
string_type boost::locale::basic_message< CharType >::str (const std::string &domain_id) const
 Translate message to a string using the default locale and message domain domain_id.
 
string_type boost::locale::basic_message< CharType >::str (const std::locale &loc, int id) const
 Translate message to a string using locale loc and message domain index id.
 
void boost::locale::basic_message< CharType >::write (std::basic_ostream< char_type > &out) const
 
template<typename CharType >
std::basic_ostream< CharType > & boost::locale::operator<< (std::basic_ostream< CharType > &out, const basic_message< CharType > &msg)
 Translate message msg and write it to stream.
 

Friends

void boost::locale::basic_message< CharType >::swap (basic_message &x, basic_message &y) noexcept(noexcept(x.swap(y)))
 

Indirect message translation function family

template<typename CharType >
basic_message< CharType > boost::locale::translate (const CharType *msg)
 Translate a message, msg is not copied.
 
template<typename CharType >
basic_message< CharType > boost::locale::translate (const CharType *context, const CharType *msg)
 Translate a message in context, msg and context are not copied.
 
template<typename CharType >
basic_message< CharType > boost::locale::translate (const CharType *single, const CharType *plural, count_type n)
 Translate a plural message form, single and plural are not copied.
 
template<typename CharType >
basic_message< CharType > boost::locale::translate (const CharType *context, const CharType *single, const CharType *plural, count_type n)
 Translate a plural message from in context, context, single and plural are not copied.
 
template<typename CharType >
basic_message< CharType > boost::locale::translate (const std::basic_string< CharType > &msg)
 Translate a message, msg is copied.
 
template<typename CharType >
basic_message< CharType > boost::locale::translate (const std::basic_string< CharType > &context, const std::basic_string< CharType > &msg)
 Translate a message in context,context and msg is copied.
 
template<typename CharType >
basic_message< CharType > boost::locale::translate (const std::basic_string< CharType > &context, const std::basic_string< CharType > &single, const std::basic_string< CharType > &plural, count_type n)
 Translate a plural message form in context, context, single and plural are copied.
 
template<typename CharType >
basic_message< CharType > boost::locale::translate (const std::basic_string< CharType > &single, const std::basic_string< CharType > &plural, count_type n)
 Translate a plural message form, single and plural are copied.
 

Direct message translation functions family

template<typename CharType >
std::basic_string< CharType > boost::locale::gettext (const CharType *id, const std::locale &loc=std::locale())
 Translate message id according to locale loc.
 
template<typename CharType >
std::basic_string< CharType > boost::locale::ngettext (const CharType *s, const CharType *p, count_type n, const std::locale &loc=std::locale())
 Translate plural form according to locale loc.
 
template<typename CharType >
std::basic_string< CharType > boost::locale::dgettext (const char *domain, const CharType *id, const std::locale &loc=std::locale())
 Translate message id according to locale loc in domain domain.
 
template<typename CharType >
std::basic_string< CharType > boost::locale::dngettext (const char *domain, const CharType *s, const CharType *p, count_type n, const std::locale &loc=std::locale())
 Translate plural form according to locale loc in domain domain.
 
template<typename CharType >
std::basic_string< CharType > boost::locale::pgettext (const CharType *context, const CharType *id, const std::locale &loc=std::locale())
 Translate message id according to locale loc in context context.
 
template<typename CharType >
std::basic_string< CharType > boost::locale::npgettext (const CharType *context, const CharType *s, const CharType *p, count_type n, const std::locale &loc=std::locale())
 Translate plural form according to locale loc in context context.
 
template<typename CharType >
std::basic_string< CharType > boost::locale::dpgettext (const char *domain, const CharType *context, const CharType *id, const std::locale &loc=std::locale())
 Translate message id according to locale loc in domain domain in context context.
 
template<typename CharType >
std::basic_string< CharType > boost::locale::dnpgettext (const char *domain, const CharType *context, const CharType *s, const CharType *p, count_type n, const std::locale &loc=std::locale())
 Translate plural form according to locale loc in domain domain in context context.
 

Detailed Description

This module provides message translation functionality, i.e. allow your application to speak native language

Function Documentation

◆ basic_message() [1/6]

template<typename CharType >
boost::locale::basic_message< CharType >::basic_message ( const char_type context,
const char_type id 
)
inlineexplicit

Create a simple message from 0 terminated strings, with context information. The string should exist until the message is destroyed. Generally useful with static constant strings

◆ basic_message() [2/6]

template<typename CharType >
boost::locale::basic_message< CharType >::basic_message ( const char_type context,
const char_type single,
const char_type plural,
count_type  n 
)
inlineexplicit

Create a simple plural form message from 0 terminated strings, with context. The strings should exist until the message is destroyed. Generally useful with static constant strings.

n is the number, single and plural are singular and plural forms of the message

◆ basic_message() [3/6]

template<typename CharType >
boost::locale::basic_message< CharType >::basic_message ( const char_type id)
inlineexplicit

Create a simple message from 0 terminated string. The string should exist until the message is destroyed. Generally useful with static constant strings

◆ basic_message() [4/6]

template<typename CharType >
boost::locale::basic_message< CharType >::basic_message ( const char_type single,
const char_type plural,
count_type  n 
)
inlineexplicit

Create a simple plural form message from 0 terminated strings. The strings should exist until the message is destroyed. Generally useful with static constant strings.

n is the number, single and plural are singular and plural forms of the message

◆ basic_message() [5/6]

template<typename CharType >
boost::locale::basic_message< CharType >::basic_message ( const string_type context,
const string_type single,
const string_type plural,
count_type  number 
)
inlineexplicit

Create a simple plural form message from strings.

n is the number, single and plural are single and plural forms of the message

◆ basic_message() [6/6]

template<typename CharType >
boost::locale::basic_message< CharType >::basic_message ( const string_type single,
const string_type plural,
count_type  number 
)
inlineexplicit

Create a simple plural form message from strings.

n is the number, single and plural are single and plural forms of the message

◆ convert()

template<typename CharType >
virtual const char_type * boost::locale::message_format< CharType >::convert ( const char_type msg,
string_type buffer 
) const
pure virtual

Convert the string msg to target locale's encoding. If msg is already in target encoding it would be returned otherwise the converted string is stored in temporary buffer and buffer.c_str() is returned.

Note: for char_type that is char16_t, char32_t and wchar_t it is no-op, returns msg

◆ get() [1/2]

template<typename CharType >
virtual const char_type * boost::locale::message_format< CharType >::get ( int  domain_id,
const char_type context,
const char_type id 
) const
pure virtual

This function returns a pointer to the string for a message defined by a context and identification string id. Both create a single key for message lookup in a domain defined by domain_id.

If context is NULL it is not considered to be a part of the key

If a translated string is found, it is returned, otherwise NULL is returned

◆ get() [2/2]

template<typename CharType >
virtual const char_type * boost::locale::message_format< CharType >::get ( int  domain_id,
const char_type context,
const char_type single_id,
count_type  n 
) const
pure virtual

This function returns a pointer to the string for a plural message defined by a context and identification string single_id.

If context is NULL it is not considered to be a part of the key

Both create a single key for message lookup in a domain defined domain_id. n is used to pick the correct translation string for a specific number.

If a translated string is found, it is returned, otherwise NULL is returned

◆ write()

template<typename CharType >
void boost::locale::basic_message< CharType >::write ( std::basic_ostream< char_type > &  out) const
inline

Translate message and write to stream out, using imbued locale and domain set to the stream