7#include "translation.hpp"
8#include "po_parser.hpp"
9#include "../i18n/i18n.hpp"
10#include "../formula/formula.hpp"
11#include "../utility/utility.hpp"
12#include "../settings/settings.hpp"
13#include "../unicode/unicode.hpp"
14#include "../telemetry/telemetry.hpp"
15#include "../macros.hpp"
19#include <unordered_map>
22hi_export_module(hikogui.l10n.translation);
33 return hash_mix(msgid, language);
55inline void add_translation(std::string_view msgid, language_tag language,
std::vector<std::string> const &plural_forms)
noexcept
57 auto key = translation_key{
std::string{msgid}, language};
58 translations[key] = plural_forms;
61inline void add_translations(po_translations
const &po_translations)
noexcept
63 for (hilet &translation : po_translations.translations) {
64 auto msgid = translation.msgctxt ? *translation.msgctxt +
'|' + translation.msgid : translation.msgid;
65 add_translation(
std::move(msgid), po_translations.language, translation.msgstr);
69inline void load_translations(std::filesystem::path path)
71 hi_log_info(
"Loading translation file {}.", path.string());
72 return add_translations(parse_po(path));
75inline void load_translations()
77 if (not translations_loaded.exchange(
true)) {
80 load_translations(path);
81 }
catch (std::exception
const &e) {
82 hi_log_error(
"Could not load translation file. {}", e.
what());
88[[nodiscard]]
inline std::pair<std::string_view, language_tag>
89get_translation(std::string_view msgid,
long long n, std::vector<language_tag>
const &languages)
noexcept
96 for (hilet language : languages) {
97 key.language = language;
99 hilet i = translations.find(key);
100 if (i != translations.cend()) {
102 hilet &translation = i->second[
plurality];
103 if (translation.size() != 0) {
104 return {translation, language};
108 hi_log_debug(
"No translation found for '{}'", msgid);
generator< std::filesystem::path > glob(glob_pattern pattern)
Find paths on the filesystem that match the glob pattern.
Definition glob.hpp:879
@ resource_dirs
The location of application resources.
Definition path_location_intf.hpp:27
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
The HikoGUI API version 1.
Definition lookahead_iterator.hpp:6
constexpr plurality cardinal_plural(language_tag language, std::integral auto n) noexcept
Get plural information of a number in a given language.
Definition unicode_plural.hpp:927
The IETF BCP 47 language tag.
Definition language_tag_intf.hpp:28
Definition translation.hpp:27
Plurality of a number.
Definition unicode_plural.hpp:89