Deluge Firmware
1.3.0
Build date: 2026.08.29
Toggle main menu visibility
Loading...
Searching...
No Matches
language.h
1
#pragma once
2
#include "gui/l10n/strings.h"
3
#include "util/misc.h"
4
#include <array>
5
#include <optional>
6
#include <string>
7
#include <string_view>
8
#include <utility>
9
10
namespace
deluge::l10n {
11
12
class
Language
;
13
constexpr
size_t
kMaxNumLanguages = 4;
14
extern
Language
const
* chosenLanguage;
15
16
class
Language {
17
using
entry_type = std::pair<l10n::String, std::string_view>;
18
19
public
:
20
using
map_type = std::array<std::optional<std::string_view>, kNumStrings>;
21
22
Language(std::string name, Language
const
* fallback =
nullptr
) : name_(std::move(name)) {
23
std::copy(fallback->map_.cbegin(), fallback->map_.cend(), this->map_.begin());
24
};
25
27
consteval
Language
(
char
const
* name, std::initializer_list<entry_type> stringmaps,
28
const
Language* fallback =
nullptr
)
29
: name_(name), fallback_(fallback) {
30
31
// Replace with stringmap values for valid entries
32
for
(
auto
[string_id, s] : stringmaps) {
33
map_.at(util::to_underlying(string_id)) = s;
34
}
35
}
36
37
[[nodiscard]]
constexpr
map_type::value_type get(String entry)
const
{
return
map_.at(util::to_underlying(entry)); }
38
39
constexpr
Language& add(
String
entry, map_type::value_type value) {
40
size_t
idx = util::to_underlying(entry);
41
map_[idx] = value;
42
return
*
this
;
43
}
44
45
[[nodiscard]]
constexpr
std::string_view name()
const
{
return
name_; }
46
47
[[nodiscard]]
constexpr
bool
hasFallback()
const
{
return
fallback_ !=
nullptr
; }
48
[[nodiscard]]
constexpr
const
Language& fallback()
const
{
return
*fallback_; }
49
50
private
:
51
std::string name_;
52
map_type map_{};
53
const
Language* fallback_ =
nullptr
;
54
};
55
56
}
// namespace deluge::l10n
57
58
namespace
deluge::l10n::built_in {
59
extern
deluge::l10n::Language english;
60
extern
deluge::l10n::Language seven_segment;
61
}
// namespace deluge::l10n::built_in
String
Definition
d_string.h:41
deluge::l10n::Language
Definition
language.h:16
deluge::l10n::Language::Language
consteval Language(char const *name, std::initializer_list< entry_type > stringmaps, const Language *fallback=nullptr)
Builder-style constructor for creating localization language maps (compile-time only).
Definition
language.h:27