|
VoltMod
C++23 framework for CS2 server plugins
|
Localization system. Loads one JSON file per language; nested objects flatten into dotted keys (category.punish). Use Get(key, slot) for per-player text.
More...
#include <Translations.hpp>
Public Member Functions | |
| Translations (PlayerLanguages &languages) | |
| bool | Load (std::string_view dirPath) |
| void | SetLanguage (std::string_view lang) |
| const std::string & | GetLanguage () const |
| std::string | Get (std::string_view key) const |
| std::string | Get (std::string_view key, int slot) const |
| std::string | GetOr (std::string_view key, int slot, std::string_view fallback) const |
| std::string | Get (std::string_view key, int slot, const Tokens &tokens) const |
| std::string | Get (std::string_view key, const Tokens &tokens) const |
| std::vector< std::string > | GetAvailableLanguages () const |
| void | SetPlayerLanguage (int slot, std::string_view lang) |
| std::string_view | PlayerLanguage (int slot) const |
Localization system. Loads one JSON file per language; nested objects flatten into dotted keys (category.punish). Use Get(key, slot) for per-player text.
Lookup order: the slot's language (PlayerLanguage), the active language, English, the framework's English defaults for its own keys (cmd.*, target.*), then the key verbatim.
Definition at line 21 of file Translations.hpp.
|
explicit |
languages holds each player's pick and must outlive this.
Definition at line 76 of file Translations.cpp.
| std::string VoltMod::Translations::Get | ( | std::string_view | key | ) | const |
Look up a key in the active (server) language, falling back to English. For broadcasts; prefer Get(key, slot) for any message addressed to a specific player.
Definition at line 199 of file Translations.cpp.
References VoltMod::Get, and VoltMod::ReadFile().
Referenced by VoltMod::CenterHtmlMenu::CloseAll(), VoltMod::PanoramaMenu::CloseAll(), VoltMod::CommandRouter::Dispatch(), VoltMod::Messages::SendKey(), VoltMod::Caller::Text(), and VoltMod::CommandRouter::Usage().
Active-language variant of the token-substituting Get.
Definition at line 239 of file Translations.cpp.
References VoltMod::Get, and VoltMod::ReadFile().
| std::string VoltMod::Translations::Get | ( | std::string_view | key, |
| int | slot | ||
| ) | const |
Look up a key in slot's registered language, falling back to the active language then English.
Definition at line 224 of file Translations.cpp.
References VoltMod::ReadFile().
| std::string VoltMod::Translations::Get | ( | std::string_view | key, |
| int | slot, | ||
| const Tokens & | tokens | ||
| ) | const |
Get(key, slot), then replace each {token} occurrence from tokens.
Definition at line 234 of file Translations.cpp.
References VoltMod::Get, VoltMod::ReadFile(), and VoltMod::Strings::SubstituteTokens().
| std::vector< std::string > VoltMod::Translations::GetAvailableLanguages | ( | ) | const |
Language codes that were successfully loaded (one per JSON file).
Definition at line 163 of file Translations.cpp.
References VoltMod::ReadFile().
| const std::string & VoltMod::Translations::GetLanguage | ( | ) | const |
Definition at line 158 of file Translations.cpp.
| std::string VoltMod::Translations::GetOr | ( | std::string_view | key, |
| int | slot, | ||
| std::string_view | fallback | ||
| ) | const |
Get(key, slot), but fallback instead of the key itself when nothing carries it. For text the framework or a plugin can render without the consumer shipping the key.
Definition at line 229 of file Translations.cpp.
References VoltMod::ReadFile().
Referenced by VoltMod::MenuStack::Describe(), VoltMod::CenterHtmlMenu::Translate(), and VoltMod::PanoramaMenu::Translate().
| bool VoltMod::Translations::Load | ( | std::string_view | dirPath | ) |
Definition at line 78 of file Translations.cpp.
References VoltMod::FlattenInto(), VoltMod::Log::Info(), VoltMod::Json::ParseDocument(), VoltMod::ReadAllText(), VoltMod::ReadFile(), VoltMod::ResolvePath(), and VoltMod::Log::Warn().
| std::string_view VoltMod::Translations::PlayerLanguage | ( | int | slot | ) | const |
Empty means the active language. Valid until the next change.
Definition at line 180 of file Translations.cpp.
References VoltMod::PlayerLanguages::Language(), and VoltMod::ReadFile().
Referenced by VoltMod::Internal::ClientLanguage::ClientLanguage().
| void VoltMod::Translations::SetLanguage | ( | std::string_view | lang | ) |
Definition at line 153 of file Translations.cpp.
References VoltMod::ReadFile().
Set slot's language for every plugin. Empty means the active language.
Definition at line 175 of file Translations.cpp.
References VoltMod::ReadFile(), and VoltMod::PlayerLanguages::SetLanguage().
Referenced by VoltMod::Internal::ClientLanguage::ClientLanguage().