libnick 2025.9.1
A cross-platform base for native Nickvision applications.
Loading...
Searching...
No Matches
Nickvision::Localization::Gettext Namespace Reference

Functions

bool init (const std::string &domainName) noexcept
 Initializes the gettext system. This function should only be called once, regardless of with different domain names.
 
const std::string & getDomainName () noexcept
 Gets the domain name used for gettext translations.
 
const std::vector< std::string > & getAvailableLanguages () noexcept
 Gets the list of available translated languages.
 
bool changeLanguage (const std::string &language) noexcept
 Changes the current language for gettext translations.
 
const char * dgettext (const char *msgid) noexcept
 Translates a message.
 
const char * dngettext (const char *msg, const char *msgPlural, unsigned long n) noexcept
 Translates a plural message.
 
template<typename... Args>
std::string fgettext (const char *msg, Args &&... args) noexcept
 Translates a message and formats it with the given arguments.
 
template<typename... Args>
std::string fngettext (const char *msg, const char *msgPlural, unsigned long n, Args &&... args) noexcept
 Translates a plural message and formats it with the given arguments.
 
const char * pgettext (const char *context, const char *msg) noexcept
 Translates a message for a given context.
 
const char * pngettext (const char *context, const char *msg, const char *msgPlural, unsigned long n) noexcept
 Translates a plural message for a given context.
 

Function Documentation

◆ changeLanguage()

bool Nickvision::Localization::Gettext::changeLanguage ( const std::string & language)
noexcept

Changes the current language for gettext translations.

Parameters
languageThe language code to change translations to (use "C" to turn off translations; use "" to use the system default language)
Returns
True if the language was changed successfully, else false

◆ dgettext()

const char * Nickvision::Localization::Gettext::dgettext ( const char * msgid)
noexcept

Translates a message.

Parameters
msgidThe message to translate
Returns
The translated message

◆ dngettext()

const char * Nickvision::Localization::Gettext::dngettext ( const char * msg,
const char * msgPlural,
unsigned long n )
noexcept

Translates a plural message.

Parameters
msgThe message to translate
msgPluralThe plural version of the message to translate
nThe number of objects (used to determine whether or not to use the plural version of the message)
Returns
The translated message for the given number of objects

◆ fgettext()

template<typename... Args>
std::string Nickvision::Localization::Gettext::fgettext ( const char * msg,
Args &&... args )
noexcept

Translates a message and formats it with the given arguments.

Parameters
msgThe message to translate
argsThe arguments to format the translated message with
Returns
The formatted translated message

◆ fngettext()

template<typename... Args>
std::string Nickvision::Localization::Gettext::fngettext ( const char * msg,
const char * msgPlural,
unsigned long n,
Args &&... args )
noexcept

Translates a plural message and formats it with the given arguments.

Parameters
msgThe message to translate
msgPluralThe plural version of the message to translate
nThe number of objects (used to determine whether or not to use the plural version of the message)
argsThe arguments to format the translated message with
Returns
The formatted translated message for the given number of objects

◆ getAvailableLanguages()

const std::vector< std::string > & Nickvision::Localization::Gettext::getAvailableLanguages ( )
noexcept

Gets the list of available translated languages.

Does not include the "C" language (the default language).

Returns
The list of available translated languages.

◆ getDomainName()

const std::string & Nickvision::Localization::Gettext::getDomainName ( )
noexcept

Gets the domain name used for gettext translations.

Returns
The gettext domain name

◆ init()

bool Nickvision::Localization::Gettext::init ( const std::string & domainName)
noexcept

Initializes the gettext system. This function should only be called once, regardless of with different domain names.

Parameters
domainNameThe domain name to use for gettext translations. Must be lowercase and contain no spaces
Returns
True if initialized, else false

◆ pgettext()

const char * Nickvision::Localization::Gettext::pgettext ( const char * context,
const char * msg )
noexcept

Translates a message for a given context.

Parameters
contextThe context of the message
msgThe message to translate
Returns
The translated message for the given context.

◆ pngettext()

const char * Nickvision::Localization::Gettext::pngettext ( const char * context,
const char * msg,
const char * msgPlural,
unsigned long n )
noexcept

Translates a plural message for a given context.

Parameters
contextThe context of the message
msgThe message to translate
msgPluralThe plural version of the message to translate
nThe number of objects (used to determine whether or not to use the plural version of the message)
Returns
The translated message for the given context and number of objects.