MeshLib C++ Docs
Loading...
Searching...
No Matches
MR::Locale Namespace Reference

Functions

constexpr auto translate_noop (const char *str) noexcept
 special no-op inline functions to mark string literal as translatable
constexpr auto translate_noop (const char *ctx, const char *str) noexcept
constexpr auto translate_noop (const char *single, const char *plural, Int64 n) noexcept
constexpr auto translate_noop (const char *ctx, const char *single, const char *plural, Int64 n) noexcept
std::string translate (const char *msg, int domainId=0)
 Translates a message using the active locale.
std::string translate (const char *context, const char *msg, int domainId=0)
 Translates a message in context using the active locale.
std::string translate (const char *single, const char *plural, Int64 n, int domainId=0)
 Translates a plural message form using the active locale.
std::string translate (const char *context, const char *single, const char *plural, Int64 n, int domainId=0)
 Translates a plural message form in context using the active locale.
const std::locale & get ()
 Returns the active locale.
const std::string & getName ()
 Returns the active locale's name.
const std::locale & set (std::string localeName)
 Loads and sets the active locale by its name. UTF-8 is always used as an encoding.
boost::signals2::connection onChanged (const std::function< void(const std::string &)> &cb)
 Connects to a signal emitted every time the active locale is changed.
std::vector< std::string > getAvailableLocales ()
 Returns the list of the names of locales with available .mo files. "en" is always included as the default locale.
void addCatalogPath (const std::filesystem::path &path)
 Adds a path to .mo files. The path is expected to have the following directory structure: <locale name>/LC_MESSAGES/<domain name>.mo The active locale is reloaded on every call.
int addDomain (const char *domainName)
 Adds a new domain. The active locale is reloaded on every call.
int addDomain (const std::string &domainName)
 Adds a new domain. The active locale is reloaded on every call.
int findDomain (const char *domainName)
 Find an id for the given domain that can be passed to the translate functions.
int findDomain (const std::string &domainName)
 Find an id for the given domain that can be passed to the translate functions.
std::string getDisplayName (const std::string &localeName)
 Returns a display name for the given locale.
void setDisplayName (const std::string &localeName, const std::string &displayName)
 Adds or updates a display name for the given locale.

Function Documentation

◆ addCatalogPath()

void MR::Locale::addCatalogPath ( const std::filesystem::path & path)

Adds a path to .mo files. The path is expected to have the following directory structure: <locale name>/LC_MESSAGES/<domain name>.mo The active locale is reloaded on every call.

◆ addDomain() [1/2]

int MR::Locale::addDomain ( const char * domainName)

Adds a new domain. The active locale is reloaded on every call.

Note
This overload is meant to be used with string literals for faster lookups.
Returns
The id of the added domain.

◆ addDomain() [2/2]

int MR::Locale::addDomain ( const std::string & domainName)

Adds a new domain. The active locale is reloaded on every call.

Returns
The id of the added domain.

◆ findDomain() [1/2]

int MR::Locale::findDomain ( const char * domainName)

Find an id for the given domain that can be passed to the translate functions.

Returns
The domain id if the domain is previously added and 0 (the default domain id) otherwise.
Note
This overload is meant to be used with string literals for faster lookups. translate

◆ findDomain() [2/2]

int MR::Locale::findDomain ( const std::string & domainName)

Find an id for the given domain that can be passed to the translate functions.

Returns
The domain id if the domain is previously added and 0 (the default domain id) otherwise. translate

◆ get()

const std::locale & MR::Locale::get ( )

Returns the active locale.

◆ getAvailableLocales()

std::vector< std::string > MR::Locale::getAvailableLocales ( )

Returns the list of the names of locales with available .mo files. "en" is always included as the default locale.

◆ getDisplayName()

std::string MR::Locale::getDisplayName ( const std::string & localeName)

Returns a display name for the given locale.

Returns
  • The display name explicitly set with setDisplayName;
  • or the display name from the compiled-in list of names generated from CLDR data;
  • or the locale name as is. setDisplayName

◆ getName()

const std::string & MR::Locale::getName ( )

Returns the active locale's name.

Note
If the locale was set manually, this function will return its name as is, without any normalization.

◆ onChanged()

boost::signals2::connection MR::Locale::onChanged ( const std::function< void(const std::string &)> & cb)

Connects to a signal emitted every time the active locale is changed.

◆ set()

const std::locale & MR::Locale::set ( std::string localeName)

Loads and sets the active locale by its name. UTF-8 is always used as an encoding.

Returns
Reference to the new locale.

◆ setDisplayName()

void MR::Locale::setDisplayName ( const std::string & localeName,
const std::string & displayName )

Adds or updates a display name for the given locale.

◆ translate() [1/4]

std::string MR::Locale::translate ( const char * context,
const char * msg,
int domainId = 0 )

Translates a message in context using the active locale.

◆ translate() [2/4]

std::string MR::Locale::translate ( const char * context,
const char * single,
const char * plural,
Int64 n,
int domainId = 0 )

Translates a plural message form in context using the active locale.

◆ translate() [3/4]

std::string MR::Locale::translate ( const char * msg,
int domainId = 0 )

Translates a message using the active locale.

◆ translate() [4/4]

std::string MR::Locale::translate ( const char * single,
const char * plural,
Int64 n,
int domainId = 0 )

Translates a plural message form using the active locale.