File include/brisk/core/Localization.hpp
¶
Locale
class¶
Locale
LocaleAbstract base class for localization.
This class defines the interface for translating keys into localized strings.
translate
function (Locale::translate
)¶
virtual const std::string &
translate(std::string_view key) const noexcept = 0
Translates a given key into a localized string.
Param key
The key to translate.
Returns A reference to the localized string.
locale
variable¶
extern RC<const Locale> locale
External reference to the current locale.
stripLocaleContext
function (Internal::stripLocaleContext
)¶
constexpr std::string_view
stripLocaleContext(std::string_view key)
Strips the locale context from a translation key.
This function removes any context information from a translation key
that is separated by "||".
Param key
The translation key potentially containing context.
Returns A string view to the stripped key.
SimpleLocale
class¶
SimpleLocale
SimpleLocaleA concrete implementation of the Locale class.
This class provides methods to manage translations in a simple way, including adding, removing, and clearing translations.
translate
function (SimpleLocale::translate
)¶
const std::string &
translate(std::string_view key) const noexcept final
Translates a given key into a localized string.
Param key
The key to translate.
Returns A reference to the localized string.
removeTranslation
function (SimpleLocale::removeTranslation
)¶
void removeTranslation(std::string_view key)
Removes a translation entry.
Param key
The key for the translation to remove.
clear
function (SimpleLocale::clear
)¶
void clear()
Clears all translations.
addTranslation
function (SimpleLocale::addTranslation
)¶
void addTranslation(std::string_view key, std::string value)
Adds a new translation entry.
Param key
The key for the translation.
Param value
The localized string corresponding to the key.
LocaleFormatString
class¶
template <Internal::FixedString key> LocaleFormatString
Template param key
A fixed string representing a translation key.LocaleFormatStringA structure for formatting localized strings with arguments.
This structure provides functionality for formatting strings that may contain placeholders.
str
function (LocaleFormatString::str
)¶
static constexpr std::string_view str()
Returns the stripped translation key.
Returns A string view to the stripped key.
checkFormatArgs
function (LocaleFormatString::checkFormatArgs
)¶
template <typename... Args>
static consteval void checkFormatArgs()
Checks the format arguments at compile-time.
This function checks if the provided arguments are compatible
with the format string.
Template param Args
The types of the arguments to check.
operator()
function (LocaleFormatString::operator()
)¶
template <typename... Args>
std::string operator()(Args &&...args) const
Formats a localized string with the provided arguments.
Template param Args
The types of the arguments.
Param args
The arguments to format into the string.
Returns The formatted localized string.
operator""_tr
function¶
template <Internal::FixedString s>
inline std::string operator""_tr() noexcept
User-defined literal for translating a fixed string.
This operator allows using the _tr literal to easily translate
fixed strings.
Template param s
The fixed string to translate.
Returns The translated string.
std::string greeting = "hello"_tr; // Translates the key "hello" to the localized string.
std::cout << greeting; // Output: "Hola" if the locale is Spanish.
operator""_trfmt
function¶
template <Internal::FixedString s>
constexpr LocaleFormatString<s> operator""_trfmt() noexcept
User-defined literal for formatting a localized string.
This operator allows using the _trfmt literal to create a
LocaleFormatString for fixed strings.
Template param s
The fixed string for formatting.
Returns A LocaleFormatString object.
constexpr auto welcomeMessage = "welcome_msg"_trfmt; // Creates a LocaleFormatString for "welcome_msg".
std::string formattedMessage = welcomeMessage("John"); // Formats the message with the name "John".
std::cout << formattedMessage; // Output: "Welcome, John!" if the translation is "Welcome, {0}!".
Auto-generated from sources, Revision , https://github.com/brisklib/brisk/blob//include/brisk/