VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::Translations Class Reference

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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Translations()

VoltMod::Translations::Translations ( PlayerLanguages &  languages)
explicit

languages holds each player's pick and must outlive this.

Definition at line 76 of file Translations.cpp.

Member Function Documentation

◆ Get() [1/4]

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().

◆ Get() [2/4]

std::string VoltMod::Translations::Get ( std::string_view  key,
const Tokens &  tokens 
) const

Active-language variant of the token-substituting Get.

Definition at line 239 of file Translations.cpp.

References VoltMod::Get, and VoltMod::ReadFile().

◆ Get() [3/4]

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().

◆ Get() [4/4]

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().

◆ GetAvailableLanguages()

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().

◆ GetLanguage()

const std::string & VoltMod::Translations::GetLanguage ( ) const

Definition at line 158 of file Translations.cpp.

◆ GetOr()

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().

◆ Load()

bool VoltMod::Translations::Load ( std::string_view  dirPath)

◆ PlayerLanguage()

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().

◆ SetLanguage()

void VoltMod::Translations::SetLanguage ( std::string_view  lang)

Definition at line 153 of file Translations.cpp.

References VoltMod::ReadFile().

◆ SetPlayerLanguage()

void VoltMod::Translations::SetPlayerLanguage ( int  slot,
std::string_view  lang 
)

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().


The documentation for this class was generated from the following files: