7#include "iso_15924.hpp"
10#include "../utility/utility.hpp"
11#include "../algorithm/algorithm.hpp"
12#include "../macros.hpp"
19hi_export_module(hikogui.i18n.language_tag : intf);
21hi_export
namespace hi {
inline namespace v1 {
35 uint16_t _reserved = 0;
43 constexpr language_tag(iso_639
const& language,
iso_15924 const& script = {}, iso_3166
const& region = {})
noexcept :
44 language(language), script(script), region(region)
48 constexpr language_tag(iso_639
const& language, iso_3166
const& region) noexcept :
language_tag(language, {}, region) {}
72 [[nodiscard]]
bool empty() const noexcept
74 return language.empty() and script.empty() and region.empty();
79 explicit operator bool() const noexcept
91 [[nodiscard]] generator<language_tag>
variants() const noexcept
94 if (script and region) {
98 if (script or region) {
113 auto const check =
expand();
114 for (
auto const& tag :
variants()) {
115 if (tag.expand() == check) {
128 for (
auto const variant :
variants()) {
129 auto expanded_variant = variant.expand();
130 for (
auto const expanded_variant_variants : expanded_variant.variants()) {
131 if (
std::find(r.begin(), r.end(), expanded_variant_variants) == r.end()) {
132 r.push_back(expanded_variant_variants);
149 auto last_variant = *
this;
151 last_variant = variant;
177 r += rhs.language.code();
180 r += rhs.script.code4();
184 r += rhs.region.code2();
193 if (lhs.language and rhs.language and lhs.language != rhs.language) {
196 if (lhs.script and rhs.script and lhs.script != rhs.script) {
199 if (lhs.region and rhs.region and lhs.region != rhs.region) {
233struct std::formatter<
hi::language_tag, char> : std::formatter<std::string_view, char> {
236 return std::formatter<std::string_view, char>::format(
to_string(t), fc);
243struct std::formatter<
std::
vector<hi::language_tag>, char> : std::formatter<std::string_view, char> {
247 for (
auto const language : t) {
251 r += std::format(
"{}", language);
253 return std::formatter<std::string_view, char>::format(r, fc);
The HikoGUI namespace.
Definition array_generic.hpp:20
std::vector< language_tag > variants(std::vector< language_tag > languages)
Add variants to the list of languages.
Definition language_tag_impl.hpp:2077
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
ISO-15924 script code.
Definition iso_15924_intf.hpp:23
constexpr bool left_to_right() const noexcept
Is this script written left-to-right.
Definition iso_15924_impl.hpp:349
The IETF BCP 47 language tag.
Definition language_tag_intf.hpp:30
language_tag expand() const noexcept
Expand the language tag to include script and language.
Definition language_tag_impl.hpp:2043
bool empty() const noexcept
Check if the language tag is empty.
Definition language_tag_intf.hpp:72
generator< language_tag > canonical_variants() const noexcept
Get variants of the language_tag.
Definition language_tag_intf.hpp:111
bool left_to_right() const noexcept
The language direction for this language-tag.
Definition language_tag_intf.hpp:169
iso_15924 default_script() const noexcept
Get the default-script for this language.
Definition language_tag_intf.hpp:160
generator< language_tag > variants() const noexcept
Get variants of the language_tag.
Definition language_tag_intf.hpp:91
constexpr friend bool matches(language_tag const &lhs, language_tag const &rhs) noexcept
Check if two language_tags match for their non-empty fields.
Definition language_tag_intf.hpp:191
static language_tag parse(std::string_view str)
Parse the language, script and region raw from the string.
Definition language_tag_impl.hpp:1969
std::vector< language_tag > all_variants() const noexcept
Creates variants of a language tag, including those by expanding the normal variants.
Definition language_tag_intf.hpp:123
language_tag shrink() const noexcept
Get a tag with only the language.
Definition language_tag_intf.hpp:147