Table of Contents

Class TranslationService

Namespace
Vintagestory.API.Config
Assembly
VintagestoryAPI.dll

A service, which provides access to translated strings, based on key/value pairs read from JSON files.

public class TranslationService : ITranslationService
Inheritance
TranslationService
Implements
Inherited Members
Extension Methods

Constructors

TranslationService(string, ILogger, IAssetManager, EnumLinebreakBehavior)

Initialises a new instance of the TranslationService class.

public TranslationService(string languageCode, ILogger logger, IAssetManager assetManager = null, EnumLinebreakBehavior lbBehavior = EnumLinebreakBehavior.AfterWord)

Parameters

languageCode string

The language code that this translation service caters for.

logger ILogger

The ILogger instance used within the sided API.

assetManager IAssetManager

The IAssetManager instance used within the sided API.

lbBehavior EnumLinebreakBehavior

Properties

LanguageCode

Gets the language code that this translation service caters for.

public string LanguageCode { get; }

Property Value

string

A string, that contains the language code that this translation service caters for.

LineBreakBehavior

public EnumLinebreakBehavior LineBreakBehavior { get; set; }

Property Value

EnumLinebreakBehavior

Methods

EnsureLoaded()

protected void EnsureLoaded()

Format(string, params object[])

protected string Format(string value, params object[] args)

Parameters

value string
args object[]

Returns

string

Get(string, params object[])

Gets a translation for a given key.

public string Get(string key, params object[] args)

Parameters

key string

The key.

args object[]

The arguments to interpolate into the resulting string.

Returns

string

Returns the key as a default value, if no results are found; otherwise returns the pre-formatted, translated value.

GetAllEntries()

Retrieves a list of all translation entries within the cache.

public IDictionary<string, string> GetAllEntries()

Returns

IDictionary<string, string>

A dictionary of localisation entries.

GetIfExists(string, params object[])

Gets a translation for a given key, if any matching wildcarded keys are found within the cache.

public string GetIfExists(string key, params object[] args)

Parameters

key string

The key.

args object[]

The arguments to interpolate into the resulting string.

Returns

string

Returns the key as a default value, if no results are found; otherwise returns the pre-formatted, translated value.

GetMatching(string, params object[])

Gets a translation for a given key, if any matching wildcarded keys are found within the cache.

public string GetMatching(string key, params object[] args)

Parameters

key string

The key.

args object[]

The arguments to interpolate into the resulting string.

Returns

string

Returns the key as a default value, if no results are found; otherwise returns the pre-formatted, translated value.

GetMatchingIfExists(string, params object[])

Gets a translation for a given key, if any matching wildcarded keys are found within the cache.

public string GetMatchingIfExists(string key, params object[] args)

Parameters

key string

The key.

args object[]

The arguments to interpolate into the resulting string.

Returns

string

Returns null as a default value, if no results are found; otherwise returns the pre-formatted, translated value.

GetUnformatted(string)

Gets the raw, unformatted translated value for the key provided.

public string GetUnformatted(string key)

Parameters

key string

The key.

Returns

string

Returns the key as a default value, if no results are found; otherwise returns the unformatted, translated value.

HasTranslation(string, bool)

Determines whether the specified key has a translation.

public bool HasTranslation(string key, bool findWildcarded = true)

Parameters

key string

The key.

findWildcarded bool

if set to true, the scan will include any wildcarded values.

Returns

bool

true if the specified key has a translation; otherwise, false.

HasTranslation(string, bool, bool)

Determines whether the specified key has a translation.

public bool HasTranslation(string key, bool findWildcarded, bool logErrors)

Parameters

key string

The key.

findWildcarded bool

if set to true, the scan will include any wildcarded values.

logErrors bool

if set to true, will add "Lang key not found" logging

Returns

bool

true if the specified key has a translation; otherwise, false.

InitialiseSearch()

Used to compile the regexes, to save time on the first 'actual' wildcard search - saves about 300ms

public void InitialiseSearch()

Invalidate()

Sets the loaded flag to false, so that the next lookup causes it to reload all translation entries

public void Invalidate()

Load(bool)

Loads translation key/value pairs from all relevant JSON files within the Asset Manager.

public void Load(bool lazyLoad = false)

Parameters

lazyLoad bool

PreLoad(string, bool)

Loads only the vanilla JSON files, without dealing with mods, or resource-packs.

public void PreLoad(string assetsPath, bool lazyLoad = false)

Parameters

assetsPath string

The root assets path to load the vanilla files from.

lazyLoad bool

PreLoadModWorldConfig(string, string, bool)

Loads the mod worldconfig language JSON files only.

public void PreLoadModWorldConfig(string modPath = null, string modDomain = null, bool lazyLoad = false)

Parameters

modPath string

The assets path to load the mod files from.

modDomain string

The mod domain to use when loading the files.

lazyLoad bool

UseAssetManager(IAssetManager)

Specifies an asset manager to use, when the service has been lazy-loaded.

public void UseAssetManager(IAssetManager assetManager)

Parameters

assetManager IAssetManager

The IAssetManager instance used within the sided API.

See Also