7#include "translation.hpp"
8#include "../utility/utility.hpp"
9#include "../unicode/unicode.hpp"
10#include "../settings/settings.hpp"
11#include "../macros.hpp"
19hi_export_module(hikogui.l10n.txt);
21hi_export
namespace hi {
inline namespace v1 {
33template<
typename... Types>
35 template<
typename... Args>
36 constexpr txt_arguments(Args&&...args) : _args(std::forward<Args>(args)...)
43 [](
auto const&...args) {
44 return std::make_unique<txt_arguments>(args...);
52 [&](
auto const&...args) {
53 return std::vformat(loc, fmt, std::make_format_args(args...));
61 return _args == rhs_->_args;
70template<
typename... Args>
74 return std::make_unique<txt_arguments_type>(std::forward<Args>(args)...);
79[[nodiscard]]
constexpr long long get_first_integer_argument() noexcept
84template<
typename First,
typename... Rest>
85[[nodiscard]]
constexpr long long get_first_integer_argument(First
const& first, Rest
const&...rest)
noexcept
87 if constexpr (std::is_integral_v<First>) {
88 return narrow_cast<long long>(first);
90 return get_first_integer_argument(rest...);
104 constexpr txt() noexcept : _first_integer_argument(), _msg_id(), _args(detail::make_unique_txt_arguments()) {}
107 _first_integer_argument(
other._first_integer_argument), _msg_id(
other._msg_id), _args(
other._args->make_unique_copy())
113 std::swap(_first_integer_argument,
other._first_integer_argument);
121 _first_integer_argument =
other._first_integer_argument;
122 _msg_id =
other._msg_id;
123 _args =
other._args->make_unique_copy();
131 std::swap(_first_integer_argument,
other._first_integer_argument);
150 template<
typename... Args>
152 _first_integer_argument(get_first_integer_argument(args...)),
154 _args(detail::make_unique_txt_arguments(std::forward<Args>(args)...))
158 [[nodiscard]]
constexpr bool empty() const noexcept
160 return _msg_id.
empty();
165 [[nodiscard]]
constexpr explicit operator bool() const noexcept
170 [[nodiscard]]
constexpr friend bool operator==(
txt const& lhs,
txt const& rhs)
noexcept
172 hi_axiom_not_null(lhs._args);
173 hi_axiom_not_null(rhs._args);
174 return lhs._msg_id == rhs._msg_id and lhs._args->equal_to(*rhs._args);
188 hi_axiom_not_null(_args);
189 auto const[fmt,
language_tag] = ::hi::get_translation(_msg_id, _first_integer_argument, languages);
190 auto const msg = _args->format(loc, fmt);
202 return translate(os_settings::locale(), languages);
205 [[nodiscard]] gstring original() const noexcept
207 hi_axiom_not_null(_args);
218 long long _first_integer_argument = 0;
227struct std::formatter<
hi::txt, char> : std::formatter<std::string, char> {
228 auto format(
hi::txt const& t,
auto& fc)
const
230 return std::formatter<std::string, char>::format(
std::string{t}, fc);
@ other
The gui_event does not have associated data.
The HikoGUI namespace.
Definition array_generic.hpp:20
hi_export constexpr It apply_markup(It first, ItEnd last, language_tag default_language=language_tag{"en-US"}, phrasing default_phrasing=phrasing::regular) noexcept
Inplace-apply markup to a string of graphemes.
Definition markup.hpp:59
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
The IETF BCP 47 language tag.
Definition language_tag_intf.hpp:30
A localizable message.
Definition txt.hpp:100
gstring translate(std::vector< language_tag > const &languages) const noexcept
Translate and format the message.
Definition txt.hpp:200
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.
Definition txt.hpp:184
txt(std::string msg_id, Args &&...args) noexcept
Construct a localizable message.
Definition txt.hpp:151