HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
hi::v1::txt Class Reference

#include <hikogui/l10n/txt.hpp>

Public Member Functions

 txt (txt const &other) noexcept
 txt (txt &&other) noexcept
txt & operator= (txt const &other) noexcept
txt & operator= (txt &&other) noexcept
template<typename... Args>
 txt (std::string msg_id, Args &&...args) noexcept
 Construct a localizable message.
constexpr bool empty () const noexcept
constexpr operator bool () const noexcept
 Check if the message is in use.
gstring translate (std::locale const &loc=os_settings::locale(), std::vector< language_tag > const &languages=os_settings::language_tags()) const noexcept
 Translate and format the message.
gstring translate (std::vector< language_tag > const &languages) const noexcept
 Translate and format the message.
gstring original () const noexcept
 operator std::string () const noexcept

Friends

constexpr friend bool operator== (txt const &lhs, txt const &rhs) noexcept

Detailed Description

A localizable message.

The translation and formatting of the message is delayed until displaying it to the user. This allows the user to change the language while the application is running.

Constructor & Destructor Documentation

◆ txt()

template<typename... Args>
hi::v1::txt::txt ( std::string msg_id,
Args &&... args )
inlinenoexcept

Construct a localizable message.

It is recommended to use the parentheses form of the constructor so that it will look like a function which is recognized by the gettext tool.

Parameters
msg_idA English string that is looked up in the translation database or, when not found, as-is. The msg_id may contain placeholders using the std::format format. Plurality is based on the first std::integral arguments.
first_argThe first argument passed to std::format().
argsArguments passed to std::format().

Member Function Documentation

◆ operator bool()

hi::v1::txt::operator bool ( ) const
inlineexplicitnodiscardconstexprnoexcept

Check if the message is in use.

◆ translate() [1/2]

gstring hi::v1::txt::translate ( std::locale const & loc = os_settings::locale(),
std::vector< language_tag > const & languages = os_settings::language_tags() ) const
inlinenodiscardnoexcept

Translate and format the message.

Find the translation of the message, then format it.

Parameters
locThe locale to use when formatting the message.
languagesA list of languages to search for translations.
Returns
The translated and formatted message.

◆ translate() [2/2]

gstring hi::v1::txt::translate ( std::vector< language_tag > const & languages) const
inlinenodiscardnoexcept

Translate and format the message.

Find the translation of the message, then format it.

Parameters
languagesA list of languages to search for translations.
Returns
The translated and formatted message.

The documentation for this class was generated from the following file: