This class is used to store international texts. More...
#include <GUILocalisationHandler.h>
Public Member Functions | |
TextResource_t | AddDynamicText (const eC_String &kNewText) |
void | DeInit () |
void | FreeDynamicText (const TextResource_t eID) |
eC_String | GetLocalisationFilename () const |
eC_UInt | GetNOFLocalisationTexts () const |
const eC_String * | GetText (const TextResource_t &eTextResourcesIdx) const |
eC_Bool | IsValidID (const TextResource_t &eID) const |
void | LoadLocalisationFile (const eC_String &kLangFileName) |
void | RegisterTextFragments (const TextResource_t &eID, const eC_UInt &uiCount) |
eC_Bool | SetNOFLocalisationTexts (eC_UInt uiNOFLocalisationTexts) |
void | SetText (TextResource_t eID, const eC_String &rkText, eC_Bool bNotifyObservers=true) |
void | SetTextFragment (const TextResource_t &eID, const eC_UInt &uiFragmentIndex, const eC_String &kText, const eC_Bool &bNotifyObservers=false) |
void | UnregisterTextFragments (const TextResource_t &eID) |
eC_Bool | WriteLocalisationFile (const eC_String &kPath) const |
![]() | |
CGUISubject () | |
Default constructor. | |
virtual | ~CGUISubject () |
Default destructor. | |
void | AddObserver (CGUIObserver *pObserver) |
void | ClearObservers () |
Removes all observers from the internal list. | |
const eC_TListDoubleLinked< CGUIObserver * > & | GetObserverList () const |
void | NotifyObservers () |
void | NotifyObservers (const CGUIObject *const pkUpdatedObject) |
void | NotifyObservers (const CGUIValue &kObservedValue, const CGUIObject *const pkUpdatedObject, const eC_UInt uiX=0, const eC_UInt uiY=0) |
void | NotifyObservers (const eC_String &kMessage) |
void | RemoveObserver (CGUIObserver *pObserver) |
Static Public Member Functions | |
static void | CreateInstance () |
static void | DeleteInstance () |
Friends | |
class | CGUI |
class | CGUIComponentManager |
This class is used to store international texts.
The localisation handler maps abstract text resource identifiers (of type TextResource_t) to strings of the currently active language. (Please refer to chapter Internationalization for further details on how internationalization is handled within Guiliani.)
Switching between two languages is therefore only a matter of loading another language file. Language files are generally UTF-8 encoded text files in which each line of text corresponds to one TextTesource ID. Note that strings within the language file must be in the same order as their corresponding TextResource IDs (which are typically stored in UserTextResource.h)
Note that the localisation handler is an observable subject, and all CGUIText objects within the user interface will be automatically notified via the subject/observer pattern when a TextResource gets updated by a call to SetText().
Example code for loading a language file:
Example code for retrieving the string which is associated with a TextResource ID (defined in UserTextResource.h) within the given language:
TextResource_t CGUILocalisationHandler::AddDynamicText | ( | const eC_String & | kNewText | ) |
Adds a new Text and returns the associated dynamically created TextResource ID.
kNewText | String for which a new TextResource ID shall be created |
|
static |
Create instance
void CGUILocalisationHandler::DeInit | ( | ) |
Should only be called by the destructor. As a workaround for memory leak detection ~CGUI() may call it too, but it is forbidden to be called by other code.
|
static |
Delete instance
void CGUILocalisationHandler::FreeDynamicText | ( | const TextResource_t | eID | ) |
Frees the given TextResource ID.
eID | TextID which shall be freed |
eC_String CGUILocalisationHandler::GetLocalisationFilename | ( | ) | const |
Return the name of the currenly loaded localisation-file
eC_UInt CGUILocalisationHandler::GetNOFLocalisationTexts | ( | ) | const |
Returns the total number of localisation texts
const eC_String * CGUILocalisationHandler::GetText | ( | const TextResource_t & | eTextResourcesIdx | ) | const |
Retrieves a text from the internal text table.
eTextResourcesIdx | Index of text to retrieve. |
eC_Bool CGUILocalisationHandler::IsValidID | ( | const TextResource_t & | eID | ) | const |
Checks if TextResource ID is valid.
eID | TextResourceID to check. |
void CGUILocalisationHandler::LoadLocalisationFile | ( | const eC_String & | kLangFileName | ) |
Loads international text strings from a file to a table. In case of error, the state of the internally stored Textstrings is undefined.
kLangFileName | File to load texts from. |
void CGUILocalisationHandler::RegisterTextFragments | ( | const TextResource_t & | eID, |
const eC_UInt & | uiCount | ||
) |
Register text-fragments for a TextResource
eID | ID of the TextResource |
uiCount | number of fragments which should be registered |
eC_Bool CGUILocalisationHandler::SetNOFLocalisationTexts | ( | eC_UInt | uiNOFLocalisationTexts | ) |
Sets the total number of texts.
uiNOFLocalisationTexts | Number of texts |
void CGUILocalisationHandler::SetText | ( | TextResource_t | eID, |
const eC_String & | rkText, | ||
eC_Bool | bNotifyObservers = true |
||
) |
Sets (changes) the text for a specific ID.
eID | The ID of the text to be changed. |
rkText | The text to be used for the ID. |
bNotifyObservers | If true notification of all obeservers will be done. |
void CGUILocalisationHandler::SetTextFragment | ( | const TextResource_t & | eID, |
const eC_UInt & | uiFragmentIndex, | ||
const eC_String & | kText, | ||
const eC_Bool & | bNotifyObservers = false |
||
) |
Set the text for a text-fragment
eID | ID of the TextResource |
uiFragmentIndex | index of the fragment |
kText | text to use in placeholder |
bNotifyObservers | if true all observers are notified |
void CGUILocalisationHandler::UnregisterTextFragments | ( | const TextResource_t & | eID | ) |
Unregister text-fragments for a TextResource
eID | ID of the TextResource |
eC_Bool CGUILocalisationHandler::WriteLocalisationFile | ( | const eC_String & | kPath | ) | const |
Writes all registered TextResources of the GUI to File.
kPath | Path and name of the destination file. |
CGUIException | if destinationfile could not be opened. |
|
friend |
|
friend |