Player12
An open source football management simulator
Loading...
Searching...
No Matches
LanguageManager Class Reference

Singleton class that manages localization and translations. More...

#include <language_manager.h>

Classes

struct  Status
 What the last load left in place. More...
 
struct  StringHash
 

Public Member Functions

bool loadLanguage (Language lang)
 Loads the JSON file for the specific language into memory.
 
bool loadFromFile (const std::string &path, Language lang)
 Loads path as the texts of lang, with the same English fallback as loadLanguage() (which calls it with the packaged file).
 
const char * get (const char *key) const
 Retrieves the localized string: the current language's, else the English one, else the key itself (the same pointer).
 
Language current () const
 The language last requested (even if it fell back).
 
const Status & status () const
 Outcome of the last load, for a notice in the UI.
 
const NumberFormat::Locale & numberLocale () const
 Number and money conventions of the loaded texts.
 

Static Public Member Functions

static LanguageManager & instance ()
 Gets the singleton instance of the LanguageManager.
 

Private Types

using Table = std::unordered_map< std::string, std::string, StringHash, std::equal_to<> >
 

Private Member Functions

 LanguageManager ()=default
 
bool ensureEnglish ()
 
void refreshNumberLocale ()
 

Private Attributes

Table translations
 
Table english
 
bool english_loaded = false
 
Status status_
 
NumberFormat::Locale number_locale
 

Detailed Description

Singleton class that manages localization and translations.

English is always kept loaded as the fallback: a key missing from the current language, or a language file that cannot be read at all, shows the English text instead of the raw key. status() tells the UI when that happened so it can say so.

Member Typedef Documentation

◆ Table

using LanguageManager::Table = std::unordered_map<std::string, std::string, StringHash, std::equal_to<> >
private

Constructor & Destructor Documentation

◆ LanguageManager()

LanguageManager::LanguageManager ( )
privatedefault

Member Function Documentation

◆ current()

Language LanguageManager::current ( ) const
inline

The language last requested (even if it fell back).

◆ ensureEnglish()

bool LanguageManager::ensureEnglish ( )
private

Reads the English table once; false when it cannot be read.

◆ get()

const char * LanguageManager::get ( const char *  key) const

Retrieves the localized string: the current language's, else the English one, else the key itself (the same pointer).

Parameters
keyThe key to look up the translation for.

◆ instance()

static LanguageManager & LanguageManager::instance ( )
inlinestatic

Gets the singleton instance of the LanguageManager.

Returns
A reference to the LanguageManager instance.

◆ loadFromFile()

bool LanguageManager::loadFromFile ( const std::string &  path,
Language  lang 
)

Loads path as the texts of lang, with the same English fallback as loadLanguage() (which calls it with the packaged file).

◆ loadLanguage()

bool LanguageManager::loadLanguage ( Language  lang)

Loads the JSON file for the specific language into memory.

Parameters
langThe Language enum value to load.
Returns
True if the language was loaded; false when it fell back to English for the whole file (English itself failing as well leaves the raw keys).

◆ numberLocale()

const NumberFormat::Locale & LanguageManager::numberLocale ( ) const
inline

Number and money conventions of the loaded texts.

◆ refreshNumberLocale()

void LanguageManager::refreshNumberLocale ( )
private

◆ status()

const Status & LanguageManager::status ( ) const
inline

Outcome of the last load, for a notice in the UI.

Member Data Documentation

◆ english

Table LanguageManager::english
private

◆ english_loaded

bool LanguageManager::english_loaded = false
private

◆ number_locale

NumberFormat::Locale LanguageManager::number_locale
private

◆ status_

Status LanguageManager::status_
private

◆ translations

Table LanguageManager::translations
private

Texts of the current language; empty while English is current.


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