|
Player12
An open source football management simulator
|
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 |
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.
|
private |
|
privatedefault |
|
inline |
The language last requested (even if it fell back).
|
private |
Reads the English table once; false when it cannot be read.
| 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).
| key | The key to look up the translation for. |
|
inlinestatic |
Gets the singleton instance of the LanguageManager.
| 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).
| bool LanguageManager::loadLanguage | ( | Language | lang | ) |
Loads the JSON file for the specific language into memory.
| lang | The Language enum value to load. |
|
inline |
Number and money conventions of the loaded texts.
|
private |
|
inline |
Outcome of the last load, for a notice in the UI.
|
private |
|
private |
|
private |
|
private |
|
private |
Texts of the current language; empty while English is current.