xoreos  0.0.5
Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Aurora::LanguageManager Class Reference

The global language manager. More...

#include <language.h>

Inheritance diagram for Aurora::LanguageManager:
Inheritance graph
[legend]
Collaboration diagram for Aurora::LanguageManager:
Collaboration graph
[legend]

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< LanguagegetLanguages () 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::MemoryReadStreampreParseColorCodes (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, DeclarationLanguageByID
 
typedef std::map< Language, DeclarationLanguageByLanguage
 

Private Member Functions

const Declarationfind (Language language) const
 
const Declarationfind (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 ()
 

Detailed Description

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.

Member Typedef Documentation

◆ LanguageByID

Definition at line 258 of file language.h.

◆ LanguageByLanguage

Definition at line 259 of file language.h.

Constructor & Destructor Documentation

◆ LanguageManager()

Aurora::LanguageManager::LanguageManager ( )

Definition at line 38 of file language.cpp.

◆ ~LanguageManager()

Aurora::LanguageManager::~LanguageManager ( )

Definition at line 44 of file language.cpp.

Member Function Documentation

◆ addLanguage() [1/3]

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

Here is the caller graph for this function:

◆ addLanguage() [2/3]

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.

Here is the call graph for this function:

◆ addLanguage() [3/3]

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.

◆ addLanguages()

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

Here is the call graph for this function:

◆ clear()

void Aurora::LanguageManager::clear ( )

◆ convertLanguageIDToGendered()

uint32 Aurora::LanguageManager::convertLanguageIDToGendered ( uint32  languageID,
LanguageGender  gender 
)
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().

Here is the caller graph for this function:

◆ convertLanguageIDToUngendered()

uint32 Aurora::LanguageManager::convertLanguageIDToUngendered ( uint32  languageID)
static

Convert a gendered language ID to an ungendered language ID.

Definition at line 233 of file language.cpp.

References Aurora::kLanguageInvalid.

Referenced by getLanguage().

Here is the caller graph for this function:

◆ find() [1/2]

const LanguageManager::Declaration * Aurora::LanguageManager::find ( Language  language) const
private

Definition at line 104 of file language.cpp.

References _langByLang.

Referenced by getEncoding(), getEncodingLocString(), getLanguage(), and getLanguageID().

Here is the caller graph for this function:

◆ find() [2/2]

const LanguageManager::Declaration * Aurora::LanguageManager::find ( uint32  id) const
private

Definition at line 112 of file language.cpp.

References _langByID.

◆ getCurrentEncoding()

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

Here is the call graph for this function:

◆ getCurrentEncodingLocString()

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

Here is the call graph for this function:

◆ getCurrentGender()

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

Here is the caller graph for this function:

◆ getCurrentLanguageText()

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

Here is the caller graph for this function:

◆ getCurrentLanguageVoice()

Language Aurora::LanguageManager::getCurrentLanguageVoice ( ) const

Return the current language for voices.

Definition at line 196 of file language.cpp.

References _currentLanguageVoice.

◆ getEncoding()

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getEncodingLocString()

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getLanguage() [1/2]

Language Aurora::LanguageManager::getLanguage ( uint32  languageID) const

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getLanguage() [2/2]

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.

Here is the call graph for this function:

◆ getLanguageGender()

LanguageGender Aurora::LanguageManager::getLanguageGender ( uint32  languageID)
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().

Here is the caller graph for this function:

◆ getLanguageGendered()

Language Aurora::LanguageManager::getLanguageGendered ( uint32  languageID) const

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

Here is the call graph for this function:

◆ getLanguageID() [1/2]

uint32 Aurora::LanguageManager::getLanguageID ( Language  language) const

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.

Here is the call graph for this function:

◆ getLanguageID() [2/2]

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.

Here is the call graph for this function:

◆ getLanguageName()

Common::UString Aurora::LanguageManager::getLanguageName ( Language  language)
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.

◆ getLanguages()

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.

◆ parseLanguage()

Language Aurora::LanguageManager::parseLanguage ( const Common::UString str)
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().

Here is the call graph for this function:

◆ preParseColorCodes()

Common::MemoryReadStream * Aurora::LanguageManager::preParseColorCodes ( Common::SeekableReadStream stream)
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().

Here is the call graph for this function:

◆ setCurrentGender()

void Aurora::LanguageManager::setCurrentGender ( LanguageGender  gender)

Change the gender modulating the current language.

Definition at line 188 of file language.cpp.

References _currentGender.

◆ setCurrentLanguage() [1/2]

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

Here is the call graph for this function:

◆ setCurrentLanguage() [2/2]

void Aurora::LanguageManager::setCurrentLanguage ( Language  languageText,
Language  languageVoice 
)

Change the current language, separately for text and voice.

Definition at line 183 of file language.cpp.

References setCurrentLanguageText(), and setCurrentLanguageVoice().

Here is the call graph for this function:

◆ setCurrentLanguageText()

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

Here is the caller graph for this function:

◆ setCurrentLanguageVoice()

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

Here is the caller graph for this function:

◆ swapLanguageGender()

uint32 Aurora::LanguageManager::swapLanguageGender ( uint32  languageID)
static

Swap the gender of this gendered language ID.

Definition at line 247 of file language.cpp.

References Aurora::kLanguageInvalid.

Member Data Documentation

◆ _currentGender

LanguageGender Aurora::LanguageManager::_currentGender
private

Definition at line 266 of file language.h.

Referenced by clear(), getCurrentGender(), and setCurrentGender().

◆ _currentLanguageText

Language Aurora::LanguageManager::_currentLanguageText
private

Definition at line 264 of file language.h.

Referenced by clear(), getCurrentLanguageText(), and setCurrentLanguageText().

◆ _currentLanguageVoice

Language Aurora::LanguageManager::_currentLanguageVoice
private

Definition at line 265 of file language.h.

Referenced by clear(), getCurrentLanguageVoice(), and setCurrentLanguageVoice().

◆ _langByID

LanguageByID Aurora::LanguageManager::_langByID
private

Definition at line 261 of file language.h.

Referenced by addLanguage(), clear(), and find().

◆ _langByLang

LanguageByLanguage Aurora::LanguageManager::_langByLang
private

Definition at line 262 of file language.h.

Referenced by addLanguage(), clear(), find(), and getLanguages().


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