29 void add(std::string_view key, std::string_view value);
36 std::string
translate(std::string_view key,
const std::vector<std::string>& args)
const;
39 std::string
t(std::string_view key)
const {
return translate(key); }
42 bool has(std::string_view key)
const;
45 int count()
const {
return static_cast<int>(strings_.size()); }
48 void clear() { strings_.clear(); }
51 const std::string&
locale()
const {
return locale_; }
52 void set_locale(std::string_view loc) { locale_ = std::string(loc); }
63 std::map<std::string, std::string, std::less<>> strings_;
64 std::string locale_ =
"en";
68inline std::string
tr(std::string_view key) {
73inline std::string
tr(std::string_view key,
const std::vector<std::string>& args) {
void set_locale(std::string_view loc)
Definition i18n.hpp:52
static LocalisedStrings & instance()
Get the global translation instance.
void clear()
Clear all translations.
Definition i18n.hpp:48
void add(std::string_view key, std::string_view value)
Add a single translation.
std::string translate(std::string_view key) const
Look up a translation. Returns the key itself if not found.
bool load_json_file(std::string_view path)
Load translations from a JSON file ({"key": "value"}).
std::string translate(std::string_view key, const std::vector< std::string > &args) const
Look up with positional argument substitution.
bool load_strings_file(std::string_view path)
Load translations from a .strings file (Apple format: "key" = "value";).
LocalisedStrings()=default
int count() const
Number of translations loaded.
Definition i18n.hpp:45
bool load_po_file(std::string_view path)
Load translations from a .po file (gettext format).
std::string t(std::string_view key) const
Shorthand: t("key") == translate("key").
Definition i18n.hpp:39
const std::string & locale() const
The locale identifier (e.g., "en", "de", "ja").
Definition i18n.hpp:51
bool has(std::string_view key) const
Whether a key has a translation.
static std::string system_locale()
Detect the system locale.
Definition generated_event_source.hpp:33
std::string tr(std::string_view key)
Convenience: translate a key using the global instance.
Definition i18n.hpp:68