Drag[en]gine Script Module DragonScript 1.35
Loading...
Searching...
No Matches
Dragengine.Utils.TranslationManager Class Reference

Manage language translator and language packs. More...

Inheritance diagram for Dragengine.Utils.TranslationManager:

Public Member Functions

void add (LanguagePack languagePack)
 Add language pack.
void addFromDirectory (String directory, bool recursive)
 Scan directory for language pack files loading and adding them.
void addFromDirectory (String directory, String pattern, bool recursive)
 Scan directory for language pack files loading and adding them.
Array allSorted ()
 Array with all languages sorted alphabetically by name.
void forEach (Block ablock)
 Visit language packs with block with parameter LanguagePack.
int getCount ()
 Number of language packs.
LanguagePack getFallback ()
 Fallback language pack.
LanguagePack getNamed (UnicodeString name)
 Named language pack or null if absent.
Array getNames ()
 Get array of language pack names as array of UnicodeString.
UnicodeString getTextNoLanguagePack ()
 Missing language pack translation.
TranslationManager new ()
 Create translation manager.
TranslationManager new (TranslationManager manager)
 Create copy of translation manager.
void removeAll ()
 Remove all language packs.
void setActiveNamed (UnicodeString name)
 Set active language pack by name.
void setActiveNamedIfPresent (UnicodeString name)
 Set active language pack by name if present.
void setActiveWithId (String identifier)
 Set active language pack by identifier.
void setActiveWithIdIfPresent (String identifier)
 Set active language pack by identifier if present.
void setFallback (LanguagePack languagePack)
 Set fallback language pack.
void setFallbackWithId (String identifier)
 Set fallback language pack by identifier.
void setFallbackWithIdIfPresent (String identifier)
 Set fallback language pack by identifier if present.
void setTextNoLanguagePack (UnicodeString text)
 Set missing language pack translation.
UnicodeString translate (String name)
 Translation for entry name or missing text if absent.
UnicodeString translate (String name, UnicodeString defaultValue)
 Translation for entry name or default value if absent.
UnicodeString translateIf (UnicodeString text, int marker)
 Translate text if it starts with a translation character.
UnicodeString translateIf (UnicodeString text, int marker, UnicodeString defaultValue)
 Translate text if it starts with a translation character.

Static Public Member Functions

static TranslationManager get ()
 Get TranslationManager from BaseGameApp.

Public Attributes

LanguagePack pActiveLanguagePack
LanguagePack pFallbackLanguagePack
Dictionary pLanguagePacks
UnicodeString pTextNoLanguagePack

Detailed Description

Manage language translator and language packs.

Provides support to load language packs into memory and seleting one of them to translate texts with. Upon switching the active language pack users have to call the translation methods again to obtain the new text.

Member Function Documentation

◆ add()

void Dragengine.Utils.TranslationManager.add ( LanguagePack languagePack)

Add language pack.

Referenced by addFromDirectory(), and setFallbackWithIdIfPresent().

◆ addFromDirectory() [1/2]

void Dragengine.Utils.TranslationManager.addFromDirectory ( String directory,
bool recursive )

Scan directory for language pack files loading and adding them.

After calling this method call setActiveLanguagePack to choose one of the loaded language packs to use.

Parameters
directoryAbsolute path to directory to scan for files.
recursiveIf true scans also in all child directories.

References getNames(), pLanguagePacks, and removeAll().

Referenced by addFromDirectory().

◆ addFromDirectory() [2/2]

void Dragengine.Utils.TranslationManager.addFromDirectory ( String directory,
String pattern,
bool recursive )

Scan directory for language pack files loading and adding them.

After calling this method call setActiveLanguagePack to choose one of the loaded language packs to use.

Parameters
directoryAbsolute path to directory to scan for files.
patternFile pattern to match. Has to be of the form "*.extension"
recursiveIf true scans also in all child directories.

References add(), addFromDirectory(), allSorted(), forEach(), getFallback(), getNamed(), pActiveLanguagePack, pFallbackLanguagePack, pLanguagePacks, setActiveNamed(), setActiveNamedIfPresent(), setActiveWithId(), setActiveWithIdIfPresent(), setFallback(), setFallbackWithId(), and setFallbackWithIdIfPresent().

◆ allSorted()

Array Dragengine.Utils.TranslationManager.allSorted ( )

Array with all languages sorted alphabetically by name.

Version
1.20

Referenced by addFromDirectory().

◆ forEach()

void Dragengine.Utils.TranslationManager.forEach ( Block ablock)

Visit language packs with block with parameter LanguagePack.

Referenced by addFromDirectory().

◆ get()

TranslationManager Dragengine.Utils.TranslationManager.get ( )
static

Get TranslationManager from BaseGameApp.

Version
1.16

Convenience method for BehaviorElementClass.sharedFactoryHelper.getTranslationManager() .

◆ getCount()

int Dragengine.Utils.TranslationManager.getCount ( )

Number of language packs.

Referenced by getFallback().

◆ getFallback()

LanguagePack Dragengine.Utils.TranslationManager.getFallback ( )

Fallback language pack.

Version
1.16

References getCount(), and pLanguagePacks.

Referenced by addFromDirectory().

◆ getNamed()

LanguagePack Dragengine.Utils.TranslationManager.getNamed ( UnicodeString name)

Named language pack or null if absent.

Deprecated
Use getWithId.

Referenced by addFromDirectory(), and setFallback().

◆ getNames()

Array Dragengine.Utils.TranslationManager.getNames ( )

Get array of language pack names as array of UnicodeString.

Deprecated
Use getIdentifiers()

Referenced by addFromDirectory().

◆ getTextNoLanguagePack()

UnicodeString Dragengine.Utils.TranslationManager.getTextNoLanguagePack ( )

Missing language pack translation.

Referenced by setActiveNamedIfPresent().

◆ new() [1/2]

TranslationManager Dragengine.Utils.TranslationManager.new ( )

Create translation manager.

References new(), pLanguagePacks, and pTextNoLanguagePack.

Referenced by new().

◆ new() [2/2]

TranslationManager Dragengine.Utils.TranslationManager.new ( TranslationManager manager)

Create copy of translation manager.

Version
1.20

References pActiveLanguagePack, pFallbackLanguagePack, pLanguagePacks, and pTextNoLanguagePack.

◆ removeAll()

void Dragengine.Utils.TranslationManager.removeAll ( )

Remove all language packs.

References translate(), and translateIf().

Referenced by addFromDirectory().

◆ setActiveNamed()

void Dragengine.Utils.TranslationManager.setActiveNamed ( UnicodeString name)

Set active language pack by name.

Deprecated
Use setActiveWithId.

References translate(), and translateIf().

Referenced by addFromDirectory().

◆ setActiveNamedIfPresent()

void Dragengine.Utils.TranslationManager.setActiveNamedIfPresent ( UnicodeString name)

Set active language pack by name if present.

Deprecated
Use setActiveWithIdIfPresent.

References getTextNoLanguagePack(), and pTextNoLanguagePack.

Referenced by addFromDirectory().

◆ setActiveWithId()

void Dragengine.Utils.TranslationManager.setActiveWithId ( String identifier)

Set active language pack by identifier.

Version
1.16

Referenced by addFromDirectory().

◆ setActiveWithIdIfPresent()

void Dragengine.Utils.TranslationManager.setActiveWithIdIfPresent ( String identifier)

Set active language pack by identifier if present.

Version
1.16

References pTextNoLanguagePack, and setTextNoLanguagePack().

Referenced by addFromDirectory().

◆ setFallback()

void Dragengine.Utils.TranslationManager.setFallback ( LanguagePack languagePack)

Set fallback language pack.

Version
1.16

References getNamed(), and pLanguagePacks.

Referenced by addFromDirectory().

◆ setFallbackWithId()

void Dragengine.Utils.TranslationManager.setFallbackWithId ( String identifier)

Set fallback language pack by identifier.

Version
1.16

Referenced by addFromDirectory().

◆ setFallbackWithIdIfPresent()

void Dragengine.Utils.TranslationManager.setFallbackWithIdIfPresent ( String identifier)

Set fallback language pack by identifier if present.

Version
1.16

References add(), and pLanguagePacks.

Referenced by addFromDirectory().

◆ setTextNoLanguagePack()

void Dragengine.Utils.TranslationManager.setTextNoLanguagePack ( UnicodeString text)

Set missing language pack translation.

Referenced by setActiveWithIdIfPresent().

◆ translate() [1/2]

UnicodeString Dragengine.Utils.TranslationManager.translate ( String name)

Translation for entry name or missing text if absent.

Referenced by removeAll(), setActiveNamed(), translate(), and translateIf().

◆ translate() [2/2]

UnicodeString Dragengine.Utils.TranslationManager.translate ( String name,
UnicodeString defaultValue )

Translation for entry name or default value if absent.

References pActiveLanguagePack, and translate().

◆ translateIf() [1/2]

UnicodeString Dragengine.Utils.TranslationManager.translateIf ( UnicodeString text,
int marker )

Translate text if it starts with a translation character.

Version
1.16

This call can be used for plain text and text prefixed with a marker character. If text is empty or the first character in text does not match the translation character the text is returned unmodified. Otherwise the entire text after the translation character converted to UTF-8 encoding is used as name in a call to translate(String).

Choose the marker character to not be found at the start of any text you can possibly encounter. A typical choice is '@'.

References pActiveLanguagePack, pFallbackLanguagePack, pTextNoLanguagePack, and translate().

Referenced by removeAll(), and setActiveNamed().

◆ translateIf() [2/2]

UnicodeString Dragengine.Utils.TranslationManager.translateIf ( UnicodeString text,
int marker,
UnicodeString defaultValue )

Translate text if it starts with a translation character.

Version
1.16

This call can be used for plain text and text prefixed with a marker character. If text is empty or the first character in text does not match the translation character the text is returned unmodified. Otherwise the entire text after the translation character converted to UTF-8 encoding is used as name in a call to translate(String, UnicodeString).

Choose the marker character to not be found at the start of any text you can possibly encounter. A typical choice is '@'.

References pFallbackLanguagePack.

Member Data Documentation

◆ pActiveLanguagePack

LanguagePack Dragengine.Utils.TranslationManager.pActiveLanguagePack

◆ pFallbackLanguagePack

LanguagePack Dragengine.Utils.TranslationManager.pFallbackLanguagePack

◆ pLanguagePacks

Dictionary Dragengine.Utils.TranslationManager.pLanguagePacks

◆ pTextNoLanguagePack

UnicodeString Dragengine.Utils.TranslationManager.pTextNoLanguagePack

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