xoreos
0.0.5
|
The global language manager. More...
#include <language.h>
Classes | |
struct | Declaration |
Public Member Functions | |
LanguageManager () | |
~LanguageManager () | |
void | clear () |
Clear all managed languages from the LanguageManager. More... | |
void | addLanguage (Language language, uint32 id, Common::Encoding encoding) |
Add a supported language for the current game to the LanguageManager, together with its internal (ungendered) language ID and usual encoding. More... | |
void | addLanguage (Language language, uint32 id, Common::Encoding encoding, Common::Encoding encodingLocString) |
Add a supported language for the current game to the LanguageManager, together with its internal (ungendered) language ID, the usual encoding, and the encoding when reading an embedded LocString string. More... | |
void | addLanguage (const Declaration &languageDeclaration) |
Add a supported language for the current game to the LanguageManager, together with its internal (ungendered) language ID and usual encoding. More... | |
void | addLanguages (const Declaration *languageDeclarations, size_t count) |
Add several supported language for the current game to the LanguageManager, together with their internal (ungendered) language ID and usual encoding. More... | |
std::vector< Language > | getLanguages () const |
Return all declared supported languages for the current game. More... | |
uint32 | getLanguageID (Language language) const |
Construct the internal language ID for an ungendered use of a language. More... | |
uint32 | getLanguageID (Language language, LanguageGender gender) const |
Construct the internal language ID for an gendered use of a language. More... | |
Language | getLanguage (uint32 languageID) const |
Decode the internal language ID for an ungendered use of a language. More... | |
Language | getLanguage (uint32 languageID, LanguageGender &gender) const |
Decode the internal language ID for a gendered use of a language. More... | |
Language | getLanguageGendered (uint32 languageID) const |
Decode the internal language ID for a gendered use of a language (and ignore the language gender). More... | |
Common::Encoding | getEncoding (Language language) const |
Return the encoding used for the given language. More... | |
Common::Encoding | getEncodingLocString (Language language) const |
Return the encoding used for the given language, for reading an embedded LocString string. More... | |
void | setCurrentLanguage (Language language) |
Change the current language, setting both text and voice to the same language. More... | |
void | setCurrentLanguage (Language languageText, Language languageVoice) |
Change the current language, separately for text and voice. More... | |
void | setCurrentLanguageText (Language language) |
Change the current language, for text only. More... | |
void | setCurrentLanguageVoice (Language language) |
Change the current language, for voice only. More... | |
void | setCurrentGender (LanguageGender gender) |
Change the gender modulating the current language. More... | |
Language | getCurrentLanguageText () const |
Return the current language for text. More... | |
Language | getCurrentLanguageVoice () const |
Return the current language for voices. More... | |
LanguageGender | getCurrentGender () const |
Return the gender modulating the current language. More... | |
Common::Encoding | getCurrentEncoding () const |
Return the encoding for the current text language. More... | |
Common::Encoding | getCurrentEncodingLocString () const |
Return the encoding for the current text language, for reading an embedded LocString string. More... | |
Static Public Member Functions | |
static Common::UString | getLanguageName (Language language) |
Return the human readable name of a language. More... | |
static Language | parseLanguage (const Common::UString &str) |
Parse this string into a language. More... | |
static uint32 | convertLanguageIDToGendered (uint32 languageID, LanguageGender gender) |
Convert an ungendered language ID to a gendered language ID. More... | |
static uint32 | convertLanguageIDToUngendered (uint32 languageID) |
Convert a gendered language ID to an ungendered language ID. More... | |
static LanguageGender | getLanguageGender (uint32 languageID) |
Return the gender of this gendered language ID. More... | |
static uint32 | swapLanguageGender (uint32 languageID) |
Swap the gender of this gendered language ID. More... | |
static Common::MemoryReadStream * | preParseColorCodes (Common::SeekableReadStream &stream) |
Pre-parse and fix color codes found in UI and dialogue strings in Aurora games. More... | |
Static Public Member Functions inherited from Common::Singleton< LanguageManager > | |
static LanguageManager & | instance () |
static void | destroy () |
Private Types | |
typedef std::map< uint32, Declaration > | LanguageByID |
typedef std::map< Language, Declaration > | LanguageByLanguage |
Private Member Functions | |
const Declaration * | find (Language language) const |
const Declaration * | find (uint32 id) const |
Private Attributes | |
LanguageByID | _langByID |
LanguageByLanguage | _langByLang |
Language | _currentLanguageText |
Language | _currentLanguageVoice |
LanguageGender | _currentGender |
Additional Inherited Members | |
Protected Types inherited from Common::Singleton< LanguageManager > | |
typedef LanguageManager | SingletonBaseType |
Protected Member Functions inherited from Common::Singleton< LanguageManager > | |
Singleton () | |
virtual | ~Singleton () |
The global language manager.
The language manager holds all known supported languages of a game, as well as the currently selected language(s) and gender (see below for details).
A language consists of these parts:
Since the encoding can be different when reading LocStrings, two different functions exist to query the encoding of language strings: one for LocStrings and one for other string.s
Depending on the game, two different languages might be selected at the same time, differentiating between use: the current language for text and the current language for speech. Therefore, there are also two functions to query the current language: one for the current text language, one for the current speech language.
A language ID exists in two variants: gendered and ungendered. Some data files specify ungendered language IDs, some gendered. A gendered language ID is used to describe strings that may exist in two versions: one for male player characters and one for female player characters. The ungendered language ID used when describing a language as such.
The ungendered language IDs of a game are usually a simple running index. The gendered variant of an ungendered language ID x is 2 * x + 0 for male and 2 * x + 1 for female. The LanguageManager has functions to convert between gendered language IDs and ungendered language IDs plus Gender value.
Likewise, the LanguageManager holds the value of the current gender of the player character.
Definition at line 114 of file language.h.
|
private |
Definition at line 258 of file language.h.
|
private |
Definition at line 259 of file language.h.
Aurora::LanguageManager::LanguageManager | ( | ) |
Definition at line 38 of file language.cpp.
Aurora::LanguageManager::~LanguageManager | ( | ) |
Definition at line 44 of file language.cpp.
void Aurora::LanguageManager::addLanguage | ( | Language | language, |
uint32 | id, | ||
Common::Encoding | encoding | ||
) |
Add a supported language for the current game to the LanguageManager, together with its internal (ungendered) language ID and usual encoding.
Definition at line 57 of file language.cpp.
References Aurora::LanguageManager::Declaration::encoding, Aurora::LanguageManager::Declaration::encodingLocString, Aurora::LanguageManager::Declaration::id, and Aurora::LanguageManager::Declaration::language.
Referenced by addLanguage(), and addLanguages().
void Aurora::LanguageManager::addLanguage | ( | Language | language, |
uint32 | id, | ||
Common::Encoding | encoding, | ||
Common::Encoding | encodingLocString | ||
) |
Add a supported language for the current game to the LanguageManager, together with its internal (ungendered) language ID, the usual encoding, and the encoding when reading an embedded LocString string.
Definition at line 69 of file language.cpp.
References addLanguage(), Aurora::LanguageManager::Declaration::encoding, Aurora::LanguageManager::Declaration::encodingLocString, Aurora::LanguageManager::Declaration::id, and Aurora::LanguageManager::Declaration::language.
void Aurora::LanguageManager::addLanguage | ( | const Declaration & | languageDeclaration | ) |
Add a supported language for the current game to the LanguageManager, together with its internal (ungendered) language ID and usual encoding.
Definition at line 82 of file language.cpp.
References _langByID, _langByLang, Aurora::LanguageManager::Declaration::id, Aurora::kLanguageInvalid, and Aurora::LanguageManager::Declaration::language.
void Aurora::LanguageManager::addLanguages | ( | const Declaration * | languageDeclarations, |
size_t | count | ||
) |
Add several supported language for the current game to the LanguageManager, together with their internal (ungendered) language ID and usual encoding.
Definition at line 90 of file language.cpp.
References addLanguage().
void Aurora::LanguageManager::clear | ( | ) |
Clear all managed languages from the LanguageManager.
Definition at line 47 of file language.cpp.
References _currentGender, _currentLanguageText, _currentLanguageVoice, _langByID, _langByLang, Aurora::kLanguageGenderMale, and Aurora::kLanguageInvalid.
|
static |
Convert an ungendered language ID to a gendered language ID.
Definition at line 220 of file language.cpp.
References Aurora::kLanguageGenderMAX, and Aurora::kLanguageInvalid.
Referenced by getLanguageID().
Convert a gendered language ID to an ungendered language ID.
Definition at line 233 of file language.cpp.
References Aurora::kLanguageInvalid.
Referenced by getLanguage().
|
private |
Definition at line 104 of file language.cpp.
References _langByLang.
Referenced by getEncoding(), getEncodingLocString(), getLanguage(), and getLanguageID().
|
private |
Definition at line 112 of file language.cpp.
References _langByID.
Common::Encoding Aurora::LanguageManager::getCurrentEncoding | ( | ) | const |
Return the encoding for the current text language.
Definition at line 212 of file language.cpp.
References getCurrentLanguageText(), and getEncoding().
Common::Encoding Aurora::LanguageManager::getCurrentEncodingLocString | ( | ) | const |
Return the encoding for the current text language, for reading an embedded LocString string.
Definition at line 216 of file language.cpp.
References getCurrentLanguageText(), and getEncodingLocString().
LanguageGender Aurora::LanguageManager::getCurrentGender | ( | ) | const |
Return the gender modulating the current language.
Definition at line 208 of file language.cpp.
References _currentGender.
Referenced by getLanguageID().
Language Aurora::LanguageManager::getCurrentLanguageText | ( | ) | const |
Return the current language for text.
Definition at line 192 of file language.cpp.
References _currentLanguageText.
Referenced by getCurrentEncoding(), and getCurrentEncodingLocString().
Language Aurora::LanguageManager::getCurrentLanguageVoice | ( | ) | const |
Return the current language for voices.
Definition at line 196 of file language.cpp.
References _currentLanguageVoice.
Common::Encoding Aurora::LanguageManager::getEncoding | ( | Language | language | ) | const |
Return the encoding used for the given language.
Definition at line 162 of file language.cpp.
References Aurora::LanguageManager::Declaration::encoding, find(), and Common::kEncodingInvalid.
Referenced by getCurrentEncoding().
Common::Encoding Aurora::LanguageManager::getEncodingLocString | ( | Language | language | ) | const |
Return the encoding used for the given language, for reading an embedded LocString string.
Definition at line 170 of file language.cpp.
References Aurora::LanguageManager::Declaration::encodingLocString, find(), and Common::kEncodingInvalid.
Referenced by getCurrentEncodingLocString().
Decode the internal language ID for an ungendered use of a language.
See getLanguageID() on what constitutes gendered and ungendered language use.
Definition at line 139 of file language.cpp.
References find(), Aurora::kLanguageInvalid, and Aurora::LanguageManager::Declaration::language.
Referenced by getLanguageGendered().
Language Aurora::LanguageManager::getLanguage | ( | uint32 | languageID, |
LanguageGender & | gender | ||
) | const |
Decode the internal language ID for a gendered use of a language.
See getLanguageID() on what constitutes gendered and ungendered language use.
Definition at line 147 of file language.cpp.
References convertLanguageIDToUngendered(), find(), getLanguageGender(), Aurora::kLanguageInvalid, and Aurora::LanguageManager::Declaration::language.
|
static |
Return the gender of this gendered language ID.
Definition at line 240 of file language.cpp.
References Aurora::kLanguageGenderMale, and Aurora::kLanguageInvalid.
Referenced by getLanguage().
Decode the internal language ID for a gendered use of a language (and ignore the language gender).
See getLanguageID() on what constitutes gendered and ungendered language use.
Definition at line 157 of file language.cpp.
References getLanguage().
Construct the internal language ID for an ungendered use of a language.
This is used by Aurora games in contexts where the gender of a player character is not relevant, for example when querying or setting the language the whole game runs.
Definition at line 120 of file language.cpp.
References find(), Aurora::LanguageManager::Declaration::id, and Aurora::kLanguageInvalid.
uint32 Aurora::LanguageManager::getLanguageID | ( | Language | language, |
LanguageGender | gender | ||
) | const |
Construct the internal language ID for an gendered use of a language.
This is used by Aurora games in contexts where the gender of a player character is relevant, for example when displaying dialogue strings that might change depending on whether the player character is male or female.
Definition at line 128 of file language.cpp.
References convertLanguageIDToGendered(), find(), getCurrentGender(), Aurora::LanguageManager::Declaration::id, Aurora::kLanguageGenderCurrent, and Aurora::kLanguageInvalid.
|
static |
Return the human readable name of a language.
Definition at line 254 of file language.cpp.
References Aurora::kLanguageChinese, Aurora::kLanguageMAX, and Aurora::kLanguageNames.
std::vector< Language > Aurora::LanguageManager::getLanguages | ( | ) | const |
Return all declared supported languages for the current game.
Definition at line 95 of file language.cpp.
References _langByLang.
|
static |
Parse this string into a language.
Definition at line 264 of file language.cpp.
References ARRAYSIZE, Common::UString::empty(), Aurora::kLanguageInvalid, Aurora::kLanguageStrings, Aurora::LanguageStrings::language, and Common::UString::toLower().
|
static |
Pre-parse and fix color codes found in UI and dialogue strings in Aurora games.
Aurora games (or Neverwinter Nights at least) allow for color codes of the form "<c???>" (and closing with "</c>"). The ??? are direct byte values taken as red, green and blue values, breaking the usual text encoding.
To fix that, we pre-parse those strings, converting "<c???>" into "<cXXXXXX>", where XXXXXX are the byte values in hexadecimal notation.
Note that this function will only work for encodings where ASCII values are directly encoded as ASCII. Namely, ASCII, Latin9, UTF-8, Windows CP-1250, Windows CP-1252 and many of the variable-byte Windows codepages used for Asian languages. This function will not work for UTF-16 and UTF-32.
Also note that we're hoping that "<c???>" won't collide with valid characters inside multibyte sequences. This is reasonable likely to never happen.
Definition at line 283 of file language.cpp.
References Common::UString::format(), Common::MemoryWriteStreamDynamic::getData(), Common::ReadStream::read(), Common::MemoryWriteStreamDynamic::reserve(), Common::MemoryWriteStreamDynamic::size(), Common::SeekableReadStream::size(), Common::MemoryWriteStreamDynamic::write(), Common::WriteStream::writeByte(), and Common::WriteStream::writeString().
void Aurora::LanguageManager::setCurrentGender | ( | LanguageGender | gender | ) |
Change the gender modulating the current language.
Definition at line 188 of file language.cpp.
References _currentGender.
void Aurora::LanguageManager::setCurrentLanguage | ( | Language | language | ) |
Change the current language, setting both text and voice to the same language.
Definition at line 178 of file language.cpp.
References setCurrentLanguageText(), and setCurrentLanguageVoice().
Change the current language, separately for text and voice.
Definition at line 183 of file language.cpp.
References setCurrentLanguageText(), and setCurrentLanguageVoice().
void Aurora::LanguageManager::setCurrentLanguageText | ( | Language | language | ) |
Change the current language, for text only.
Definition at line 200 of file language.cpp.
References _currentLanguageText.
Referenced by setCurrentLanguage().
void Aurora::LanguageManager::setCurrentLanguageVoice | ( | Language | language | ) |
Change the current language, for voice only.
Definition at line 204 of file language.cpp.
References _currentLanguageVoice.
Referenced by setCurrentLanguage().
Swap the gender of this gendered language ID.
Definition at line 247 of file language.cpp.
References Aurora::kLanguageInvalid.
|
private |
Definition at line 266 of file language.h.
Referenced by clear(), getCurrentGender(), and setCurrentGender().
|
private |
Definition at line 264 of file language.h.
Referenced by clear(), getCurrentLanguageText(), and setCurrentLanguageText().
|
private |
Definition at line 265 of file language.h.
Referenced by clear(), getCurrentLanguageVoice(), and setCurrentLanguageVoice().
|
private |
Definition at line 261 of file language.h.
Referenced by addLanguage(), clear(), and find().
|
private |
Definition at line 262 of file language.h.
Referenced by addLanguage(), clear(), find(), and getLanguages().