C12Adapter Opensource C++ Interface
MMessageCatalog Class Reference

Catalog of local strings. More...

Inheritance diagram for MMessageCatalog:

Public Types

enum  NoThrowEnum { NoThrowConstructor = 0 }
 Dummy type that makes possible calling a no-throw version of the constructor.
 
typedef std::vector< MMessageFile * > MessageFileVector
 Vector of message sources.
 
typedef bool(* TranslationDelegate) (MStdString &result, const MMessageCatalog *self, MConstChars domain, MConstLocalChars str, unsigned strSize)
 Translation delegate shall return true if it performed translation of a given string to local language. More...
 

Public Member Functions

 MMessageCatalog (MConstChars domain=NULL)
 Message catalog constructor that takes one domain name. More...
 
 MMessageCatalog (NoThrowEnum, MConstChars domain)
 No-throw version of message catalog constructor that takes one domain name. More...
 
virtual ~MMessageCatalog ()
 Message catalog destructor.
 
void AddDomain (const MStdString &domainName)
 Add translation domain to the catalog. More...
 
void Clear ()
 Clear all messages from the catalog.
 
MStdString GetText (MConstLocalChars str) const
 Translate the given English text into current language. More...
 
MStdString GetText (MConstLocalChars str, unsigned strSize) const
 Translate the given English text into current language. More...
 
MStdString GetText (MConstChars domain, MConstLocalChars str) const
 Translate the given English text into current language given the translation domain. More...
 
MStdString GetText (MConstChars domain, MConstLocalChars str, unsigned strSize) const
 Translate the given English text into current language given the translation domain. More...
 
MStdString GetFormattedText (MConstLocalChars str,...) const
 Translate the given English text with parameters into current language. More...
 
MStdString GetFormattedText (MConstChars domain, MConstLocalChars str,...) const
 Translate the given English text with parameters into current language given the translation domain. More...
 
MStdString GetVaText (MConstLocalChars str, va_list va) const
 Translate the given English text with parameters into current language. More...
 
MStdString GetVaText (MConstChars domain, MConstLocalChars str, va_list va) const
 Translate the given English text with parameters into current language given the translation domain. More...
 
MStdString GetStdString (const MStdString &str) const
 Translate the given English text into current language. More...
 
MStdString GetStdStringDomain (const MStdString &domain, const MStdString &str) const
 Translate the given English text into current language given the translation domain. More...
 
void SetTranslationDelegate (TranslationDelegate delegate=NULL)
 
TranslationDelegate GetTranslationDelegate () const
 
void SetPath (const MStdString &)
 
const MStdStringGetPath () const
 
const MStdStringGetLocale () const
 
void SetLocale (const MStdString &locale)
 
- Public Member Functions inherited from MObject
virtual ~MObject ()
 Object destructor.
 
virtual const MClassGetClass () const =0
 Get the final class of the object. More...
 
virtual unsigned GetEmbeddedSizeof () const
 For embedded object types, return the size of the class. More...
 
bool IsEmbeddedObject () const
 Tell if the object is of embedded kind. More...
 
SHOW_INTERNAL MVariant Call (const MStdString &name, const MVariant &params)
 Call the object service with parameters, given as variant. More...
 
MVariant Call0 (const MStdString &name)
 Call the object service with no parameters. More...
 
MVariant Call1 (const MStdString &name, const MVariant &p1)
 Call the object service with one parameter. More...
 
MVariant Call2 (const MStdString &name, const MVariant &p1, const MVariant &p2)
 Call the object service with two parameter. More...
 
MVariant Call3 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3)
 Call the object service with three parameter. More...
 
MVariant Call4 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4)
 Call the object service with four parameter. More...
 
MVariant Call5 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5)
 Call the object service with five parameter. More...
 
MVariant Call6 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5, const MVariant &p6)
 Call the object service with six parameter. More...
 
virtual MVariant CallV (const MStdString &name, const MVariant::VariantVector &params)
 Call the object service with parameters, given as variant vector. More...
 
virtual bool IsPropertyPresent (const MStdString &name) const
 Tell if the property with the given name exists.
 
virtual bool IsServicePresent (const MStdString &name) const
 Tell if the service with the given name exists.
 
virtual MVariant GetProperty (const MStdString &name) const
 Get the property value using name of the property. More...
 
virtual void SetProperty (const MStdString &name, const MVariant &value)
 Set the property using name of the property, and value. More...
 
virtual MStdStringVector GetAllPropertyNames () const
 Return the list of publicly available properties, persistent or not. More...
 
virtual MStdStringVector GetAllPersistentPropertyNames () const
 Return the list of persistent properties. More...
 
virtual void SetPersistentPropertiesToDefault ()
 Set the persistent properties of the object to their default values. More...
 
virtual MVariant GetPersistentPropertyDefaultValue (const MStdString &name) const
 Get the default value of persistent property with the name given. More...
 
virtual void SetPersistentPropertyToDefault (const MStdString &name)
 Set the persistent property with the name given to default value. More...
 
virtual const char * GetType () const
 Get the name of the type for the object (could be the same as class name).
 
virtual void SetType (const MStdString &)
 Intentionally, it will set the name of the type for the object, but the service will not allow setting the name to anything other than the current name. More...
 
virtual void Validate ()
 Validate internal structures of the object. More...
 

Static Public Member Functions

static const MMessageCatalogGetDefaultConst ()
 Access the constant global default message catalog. More...
 
static void SetLocaleToAllCatalogs (const MStdString &locale)
 Enumerate all created catalogs and set the given locale string to each.
 
static MStdString GetTextDefault (MConstLocalChars str)
 Static variant that calls GetText of the default catalog. More...
 
static MStdString GetTextDefault (MConstLocalChars str, unsigned strSize)
 Static variant that calls GetText of the default catalog. More...
 
static MStdString GetTextDefault (MConstChars domain, MConstLocalChars str)
 Static variant that calls GetText of the default catalog. More...
 
static MStdString GetTextDefault (MConstChars domain, MConstLocalChars str, unsigned strSize)
 Static variant that calls GetText of the default catalog. More...
 
static MStdString GetFormattedTextDefault (MConstLocalChars str,...)
 Static variant that calls GetFormattedText of the default catalog. More...
 
static MStdString GetFormattedTextDefault (MConstChars domain, MConstLocalChars str,...)
 Static variant that calls GetFormattedText of the default catalog. More...
 
static MStdString GetVaTextDefault (MConstLocalChars str, va_list va)
 Static variant that calls GetVaText of the default catalog. More...
 
static MStdString GetVaTextDefault (MConstChars domain, MConstLocalChars str, va_list va)
 Static variant that calls GetVaText of the default catalog. More...
 
static MStdString GetStdStringDefault (const MStdString &str)
 Static variant that calls GetStdString of the default catalog. More...
 
static MStdString GetStdStringDomainDefault (const MStdString &domain, const MStdString &str)
 Static variant that calls GetStdString of the default catalog. More...
 
static MStdString StaticGetLocaleDescription (const MStdString &lang)
 Get a human readable description of the given locale. More...
 
static MMessageCatalogGetDefault ()
 
static void SetDefault (MMessageCatalog *def)
 
- Static Public Member Functions inherited from MObject
static const MClassGetStaticClass ()
 Get the declared class of this particular object. More...
 
static bool IsClassPresent (const MStdString &name)
 Tells if the given class name is available. More...
 

Additional Inherited Members

- Static Public Attributes inherited from MObject
static const MClass s_class
 Class of MObject.
 
- Protected Member Functions inherited from MObject
 MObject ()
 Object constructor, protected as the class is abstract.
 
void DoSetPersistentPropertiesToDefault (const MClass *staticClass)
 Set the persistent properties to their default values for one object provided the class for that object. More...
 

Detailed Description

Catalog of local strings.

The design and concepts of this class is done after standard POSIX gettext facility. Please see the documentation available on the web to refer to the notions, file formats, and so on.

Member Typedef Documentation

typedef bool(* MMessageCatalog::TranslationDelegate) (MStdString &result, const MMessageCatalog *self, MConstChars domain, MConstLocalChars str, unsigned strSize)

Translation delegate shall return true if it performed translation of a given string to local language.

See also
SetTranslationDelegate

Constructor & Destructor Documentation

MMessageCatalog::MMessageCatalog ( MConstChars  domain = NULL)

Message catalog constructor that takes one domain name.

This constructor can throw an exception related to domain logging.

MMessageCatalog::MMessageCatalog ( NoThrowEnum  ,
MConstChars  domain 
)

No-throw version of message catalog constructor that takes one domain name.

This constructor will silently suppress any exception, while there is a debug check for such. The result catalog, if loaded with errors, is not going to translate any messages.

Member Function Documentation

void MMessageCatalog::AddDomain ( const MStdString domainName)

Add translation domain to the catalog.

Parameters
domainNamedomain
static MMessageCatalog* MMessageCatalog::GetDefault ( )
static

Access the global default message catalog.

Default global message catalog is the one used by default by the whole application.

static const MMessageCatalog* MMessageCatalog::GetDefaultConst ( )
inlinestatic

Access the constant global default message catalog.

See also
GetDefault
MStdString MMessageCatalog::GetFormattedText ( MConstLocalChars  str,
  ... 
) const

Translate the given English text with parameters into current language.

Parameters
strText with parameters, typically in English.
...Optional parameters that should correspond to printf specifiers in str.
Returns
Translated text in a locale specific language.
MStdString MMessageCatalog::GetFormattedText ( MConstChars  domain,
MConstLocalChars  str,
  ... 
) const

Translate the given English text with parameters into current language given the translation domain.

Parameters
domainTranslation domain, a string denoting the sub-dictionary.
strText with parameters, typically in English.
...Optional parameters that should correspond to printf specifiers in str.
Returns
Translated text in a locale specific language.
static MStdString MMessageCatalog::GetFormattedTextDefault ( MConstLocalChars  str,
  ... 
)
static

Static variant that calls GetFormattedText of the default catalog.

See also
GetFormattedText(MConstLocalChars,...)
GetDefault
static MStdString MMessageCatalog::GetFormattedTextDefault ( MConstChars  domain,
MConstLocalChars  str,
  ... 
)
static

Static variant that calls GetFormattedText of the default catalog.

See also
GetFormattedText(MConstChars,MConstLocalChars,...)
GetDefault
const MStdString& MMessageCatalog::GetLocale ( ) const
inline

Language of this catalog, locale code.

Setting an empty string to this catalog will mean this catalog does not do any translation.

const MStdString& MMessageCatalog::GetPath ( ) const
inline

Catalog path.

MStdString MMessageCatalog::GetStdString ( const MStdString str) const

Translate the given English text into current language.

Parameters
strText, typically in English.
Returns
Translated text in a locale specific language.
static MStdString MMessageCatalog::GetStdStringDefault ( const MStdString str)
static

Static variant that calls GetStdString of the default catalog.

See also
GetStdString
GetDefault
MStdString MMessageCatalog::GetStdStringDomain ( const MStdString domain,
const MStdString str 
) const

Translate the given English text into current language given the translation domain.

Parameters
domainTranslation domain, a string denoting the sub-dictionary.
strText, typically in English.
Returns
Translated text in a locale specific language.
static MStdString MMessageCatalog::GetStdStringDomainDefault ( const MStdString domain,
const MStdString str 
)
static

Static variant that calls GetStdString of the default catalog.

See also
GetStdStringDomain
GetDefault
MStdString MMessageCatalog::GetText ( MConstLocalChars  str) const

Translate the given English text into current language.

Parameters
strText, typically in English.
Returns
Translated text in a locale specific language.
MStdString MMessageCatalog::GetText ( MConstLocalChars  str,
unsigned  strSize 
) const

Translate the given English text into current language.

Parameters
strText, typically in English.
strSizeLength of the text.
Returns
Translated text in a locale specific language.
MStdString MMessageCatalog::GetText ( MConstChars  domain,
MConstLocalChars  str 
) const

Translate the given English text into current language given the translation domain.

Parameters
domainTranslation domain, a string denoting the sub-dictionary.
strText, typically in English.
Returns
Translated text in a locale specific language.
MStdString MMessageCatalog::GetText ( MConstChars  domain,
MConstLocalChars  str,
unsigned  strSize 
) const

Translate the given English text into current language given the translation domain.

Parameters
domainTranslation domain, a string denoting the sub-dictionary.
strText, typically in English.
strSizeLength of the text.
Returns
Translated text in a locale specific language.
static MStdString MMessageCatalog::GetTextDefault ( MConstLocalChars  str)
static

Static variant that calls GetText of the default catalog.

See also
GetText(MConstLocalChars)const
GetDefault
static MStdString MMessageCatalog::GetTextDefault ( MConstLocalChars  str,
unsigned  strSize 
)
static

Static variant that calls GetText of the default catalog.

See also
GetText(MConstLocalChars,unsigned)const
GetDefault
static MStdString MMessageCatalog::GetTextDefault ( MConstChars  domain,
MConstLocalChars  str 
)
static

Static variant that calls GetText of the default catalog.

See also
GetText(MConstChars,MConstLocalChars)const
GetDefault
static MStdString MMessageCatalog::GetTextDefault ( MConstChars  domain,
MConstLocalChars  str,
unsigned  strSize 
)
static

Static variant that calls GetText of the default catalog.

See also
GetText(MConstChars,MConstLocalChars,unsigned)const
GetDefault
TranslationDelegate MMessageCatalog::GetTranslationDelegate ( ) const
inline

Translation delegate procedure to use for translating messages.

This is to set an alternative translation mechanism. This is usually not a translation but a mapping between an English string and a localized string.

MStdString MMessageCatalog::GetVaText ( MConstLocalChars  str,
va_list  va 
) const

Translate the given English text with parameters into current language.

Parameters
strText with parameters, typically in English.
vaParameter list that should correspond to printf specifiers in str.
Returns
Translated text in a locale specific language.
MStdString MMessageCatalog::GetVaText ( MConstChars  domain,
MConstLocalChars  str,
va_list  va 
) const

Translate the given English text with parameters into current language given the translation domain.

Parameters
domainTranslation domain, a string denoting the sub-dictionary.
strText with parameters, typically in English.
vaParameter list that should correspond to printf specifiers in str.
Returns
Translated text in a locale specific language.
static MStdString MMessageCatalog::GetVaTextDefault ( MConstLocalChars  str,
va_list  va 
)
static

Static variant that calls GetVaText of the default catalog.

See also
GetVaText(MConstLocalChars,va_list)const
GetDefault
static MStdString MMessageCatalog::GetVaTextDefault ( MConstChars  domain,
MConstLocalChars  str,
va_list  va 
)
static

Static variant that calls GetVaText of the default catalog.

See also
GetVaText(MConstChars,MConstLocalChars,va_list)const
GetDefault
static void MMessageCatalog::SetDefault ( MMessageCatalog def)
static

Access the global default message catalog.

Default global message catalog is the one used by default by the whole application.

void MMessageCatalog::SetLocale ( const MStdString locale)

Language of this catalog, locale code.

Setting an empty string to this catalog will mean this catalog does not do any translation.

void MMessageCatalog::SetPath ( const MStdString )

Catalog path.

void MMessageCatalog::SetTranslationDelegate ( TranslationDelegate  delegate = NULL)
inline

Translation delegate procedure to use for translating messages.

This is to set an alternative translation mechanism. This is usually not a translation but a mapping between an English string and a localized string.

static MStdString MMessageCatalog::StaticGetLocaleDescription ( const MStdString lang)
static

Get a human readable description of the given locale.

Parameters
langLocale name, which is the language code.
Returns
Human readable description of the locale.