Table of Contents

Interface ITranslationService

Namespace
Vintagestory.API.Config
Assembly
VintagestoryAPI.dll

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

public interface ITranslationService
Extension Methods

Properties

LanguageCode

Gets the language code that this translation service caters for.

string LanguageCode { get; }

Property Value

string

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

LineBreakBehavior

EnumLinebreakBehavior LineBreakBehavior { get; }

Property Value

EnumLinebreakBehavior

Methods

Get(string, params object[])

Gets a translation for a given key.

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 if no results are found; otherwise returns the pre-formatted, translated value.

GetAllEntries()

Retrieves a list of all translation entries within the cache.

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.

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

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

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 if no results are found; otherwise returns the pre-formatted, translated value.

GetUnformatted(string)

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

string GetUnformatted(string key)

Parameters

key string

The key.

Returns

string

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

HasTranslation(string, bool)

Determines whether the specified key has a translation.

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.

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

void InitialiseSearch()

Invalidate()

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

void Invalidate()

Load(bool)

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

void Load(bool lazyload = false)

Parameters

lazyload bool

PreLoad(string, bool)

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

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.

void PreLoadModWorldConfig(string modPath, string modDomain, 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.

void UseAssetManager(IAssetManager assetManager)

Parameters

assetManager IAssetManager

The IAssetManager instance used within the sided API.