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

Static Public Member Functions

static TranslationManager get ()
 Get TranslationManager from BaseGameApp. More...
 

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.

◆ 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.

◆ 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.

◆ allSorted()

Array Dragengine.Utils.TranslationManager.allSorted ( )

Array with all languages sorted alphabetically by name.

Version
1.20

◆ forEach()

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

Visit language packs with block with parameter LanguagePack.

◆ get()

static TranslationManager Dragengine.Utils.TranslationManager.get ( )
static

Get TranslationManager from BaseGameApp.

Version
1.16

Convenience method for BaseGameApp.getApp().getTranslationManager() .

◆ getCount()

int Dragengine.Utils.TranslationManager.getCount ( )

Number of language packs.

◆ getFallback()

LanguagePack Dragengine.Utils.TranslationManager.getFallback ( )

Fallback language pack.

Version
1.16

◆ getNamed()

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

Named language pack or null if absent.

Deprecated:
Use getWithId.

◆ getNames()

Array Dragengine.Utils.TranslationManager.getNames ( )

Get array of language pack names as array of UnicodeString.

Deprecated:
Use getIdentifiers()

◆ getTextNoLanguagePack()

UnicodeString Dragengine.Utils.TranslationManager.getTextNoLanguagePack ( )

Missing language pack translation.

◆ new() [1/2]

TranslationManager Dragengine.Utils.TranslationManager.new ( )

Create translation manager.

◆ new() [2/2]

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

Create copy of translation manager.

Version
1.20

◆ removeAll()

void Dragengine.Utils.TranslationManager.removeAll ( )

Remove all language packs.

◆ setActiveNamed()

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

Set active language pack by name.

Deprecated:
Use setActiveWithId.

◆ setActiveNamedIfPresent()

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

Set active language pack by name if present.

Deprecated:
Use setActiveWithIdIfPresent.

◆ setActiveWithId()

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

Set active language pack by identifier.

Version
1.16

◆ setActiveWithIdIfPresent()

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

Set active language pack by identifier if present.

Version
1.16

◆ setFallback()

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

Set fallback language pack.

Version
1.16

◆ setFallbackWithId()

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

Set fallback language pack by identifier.

Version
1.16

◆ setFallbackWithIdIfPresent()

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

Set fallback language pack by identifier if present.

Version
1.16

◆ setTextNoLanguagePack()

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

Set missing language pack translation.

◆ translate() [1/2]

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

Translation for entry name or missing text if absent.

◆ translate() [2/2]

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

Translation for entry name or default value if absent.

◆ 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 '@'.

◆ translateIf() [2/2]

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

Translation 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 '@'.

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: