7#include "translation.hpp"
8#include "../forward_value.hpp"
9#include "../utility/module.hpp"
10#include "../os_settings.hpp"
11#include "../text/module.hpp"
17namespace hi::inline
v1 {
42 [[nodiscard]]
virtual long long n() const noexcept = 0;
52 return lhs.equal_to(rhs);
60template<
typename... Values>
80 template<
typename... Args>
87 return std::make_unique<translate_args>(*
this);
93 return _values == rhs_->_values;
109 template<std::
size_t I>
110 [[nodiscard]]
long long n_recurse() const noexcept
112 if constexpr (I <
sizeof...(Values)) {
113 if constexpr (std::is_integral_v<decltype(std::get<I>(_values))>) {
114 return narrow_cast<long long>(std::get<I>(_values));
116 return n_recurse<I + 1>();
123 [[nodiscard]]
long long n() const noexcept
override
125 return n_recurse<0>();
131 template<
typename... Args>
132 static std::string format_wrapper(std::string_view fmt, Args
const&...args)
134 return std::vformat(fmt, std::make_format_args(args...));
137 template<
typename... Args>
138 static std::string format_locale_wrapper(
std::locale const& loc, std::string_view fmt, Args
const&...args)
140 return std::vformat(loc, fmt, std::make_format_args(args...));
144template<
typename... Args>
145translate_args(Args&&...) -> translate_args<forward_value_t<Args>...>;
161 constexpr translate() noexcept : _msg_id(), _args(
nullptr), _has_args(false) {}
164 _msg_id(
std::move(other._msg_id)), _args(
nullptr), _has_args(other._has_args)
171 constexpr translate& operator=(translate&& other)
noexcept
174 _has_args =
other._has_args;
181 constexpr translate(translate
const& other) noexcept : _msg_id(
other._msg_id), _args(
nullptr), _has_args(
other._has_args)
184 _args =
other._args->unique_copy();
188 constexpr translate& operator=(translate
const& other)
noexcept
190 _msg_id =
other._msg_id;
191 _has_args =
other._has_args;
193 _args =
other._args->unique_copy();
198 [[nodiscard]]
constexpr bool empty() const noexcept
200 return _msg_id.empty();
205 [[nodiscard]]
constexpr explicit operator bool() const noexcept
220 constexpr translate(std::string_view msg_id) noexcept : _msg_id(msg_id), _args(
nullptr), _has_args(
false) {}
234 template<
typename FirstArg,
typename... Args>
235 translate(std::string_view msg_id, FirstArg
const& first_arg, Args
const&...args) noexcept :
251 hilet[fmt,
language_tag] = ::hi::get_translation(_msg_id, _args->n(), languages);
252 hilet msg = _args->format(fmt);
254 return to_text_with_markup(msg, default_attributes);
259 return to_text_with_markup(msg, default_attributes);
274 hilet[fmt,
language_tag] = ::hi::get_translation(_msg_id, _args->n(), languages);
275 hilet msg = _args->format(loc, fmt);
277 return to_text_with_markup(msg, default_attributes);
282 return to_text_with_markup(msg, default_attributes);
294 if (lhs._has_args != rhs._has_args) {
298 if (lhs._has_args and *lhs._args != *rhs._args) {
302 return lhs._msg_id == rhs._msg_id;
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
@ other
The gui_event does not have associated data.
DOXYGEN BUG.
Definition algorithm.hpp:13
typename forward_value< T >::type forward_value_t
Get the storage type of the forward_value functor.
Definition forward_value.hpp:83
The IETF BCP 47 language tag.
Definition language_tag.hpp:25
language_tag expand() const noexcept
Expand the language tag to include script and language.
Definition translate.hpp:19
virtual std::string format(std::string_view fmt) const noexcept=0
Format text from the arguments and the given format string.
virtual long long n() const noexcept=0
The numeric value of the first numeric argument.
virtual std::string format(std::locale const &loc, std::string_view fmt) const noexcept=0
Format text from the arguments and the given format string.
Delayed formatting.
Definition translate.hpp:61
std::unique_ptr< translate_args_base > unique_copy() const noexcept override
Make a unique copy of the arguments.
Definition translate.hpp:85
long long n() const noexcept override
The numeric value of the first numeric argument.
Definition translate.hpp:123
std::string format(std::string_view fmt) const noexcept override
Format text from the arguments and the given format string.
Definition translate.hpp:99
std::string format(std::locale const &loc, std::string_view fmt) const noexcept override
Format text from the arguments and the given format string.
Definition translate.hpp:104
translate_args(Args const &...args) noexcept
Construct a translate arguments.
Definition translate.hpp:81
A localizable message.
Definition translate.hpp:155
constexpr friend bool operator==(translate const &lhs, translate const &rhs) noexcept
Compare two localizable messages.
Definition translate.hpp:292
translate(std::string_view msg_id, FirstArg const &first_arg, Args const &...args) noexcept
Construct a localizable message.
Definition translate.hpp:235
text operator()(std::vector< language_tag > const &languages=os_settings::language_tags()) const noexcept
Translate and format the message.
Definition translate.hpp:248
constexpr translate(std::string_view msg_id) noexcept
Construct a localizable message.
Definition translate.hpp:220
constexpr translate() noexcept
Construct an empty message.
Definition translate.hpp:161
text operator()(std::locale const &loc, std::vector< language_tag > const &languages=os_settings::language_tags()) const noexcept
Translate and format the message.
Definition translate.hpp:271