Table of Contents

Class Lang

Namespace
Vintagestory.API.Config
Assembly
VintagestoryAPI.dll

Utility class for enabling i18n. Loads language entries from assets/[locale].json

public static class Lang
Inheritance
Lang
Inherited Members

Remarks

Kept legacy code structure and arguments for backwards compatibility.

Properties

AvailableLanguages

public static Dictionary<string, ITranslationService> AvailableLanguages { get; }

Property Value

Dictionary<string, ITranslationService>

CurrentLocale

Gets the language code that this currently used to translate values.

public static string CurrentLocale { get; }

Property Value

string

A string, that contains he language code that this currently used to translate values.

DefaultLocale

public static string DefaultLocale { get; set; }

Property Value

string

Methods

ChangeLanguage(string)

Changes the current language for the game.

public static void ChangeLanguage(string languageCode)

Parameters

languageCode string

The language code to set as the language for the game.

Get(string, params object[])

Gets a translation entry for given key using the current locale

public static 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 static IDictionary<string, string> GetAllEntries()

Returns

IDictionary<string, string>

A dictionary of localisation entries.

GetIfExists(string, params object[])

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

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

GetL(string, string, params object[])

Gets a translation entry for given key using given locale

public static string GetL(string langcode, string key, params object[] args)

Parameters

langcode string
key string
args object[]

Returns

string

GetMatching(string, params object[])

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

public static 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 entry for given key, if any matching wildcarded keys are found within the cache.

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

GetMatchingL(string, string, params object[])

public static string GetMatchingL(string langcode, string key, params object[] args)

Parameters

langcode string
key string
args object[]

Returns

string

GetNamePlaceHolder(AssetLocation)

public static string GetNamePlaceHolder(AssetLocation code)

Parameters

code AssetLocation

Returns

string

GetUnformatted(string)

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

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

GetWithFallback(string, string, params object[])

Gets a translation entry for given key using the current locale. Also tries the fallback key - useful if we change a key but not all languages updated yet

public static string GetWithFallback(string key, string fallbackKey, params object[] args)

Parameters

key string
fallbackKey string
args object[]

Returns

string

HasTranslation(string, bool, bool)

Determines whether the specified key has a translation.

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

Parameters

key string

The key.

findWildcarded bool

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

logErrors bool

Returns

bool

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

InitialiseSearch()

public static void InitialiseSearch()

Load(ILogger, IAssetManager, string)

Loads all translations

public static void Load(ILogger logger, IAssetManager assetManager, string language = "en")

Parameters

logger ILogger

The ILogger instance used within the sided API.

assetManager IAssetManager

The IAssetManager instance used within the sided API.

language string

The desired language

LoadLanguage(ILogger, IAssetManager, string, bool, EnumLinebreakBehavior)

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

public static void LoadLanguage(ILogger logger, IAssetManager assetManager, string languageCode = "en", bool lazyLoad = false, EnumLinebreakBehavior lbBehavior = EnumLinebreakBehavior.AfterWord)

Parameters

logger ILogger

The ILogger instance used within the sided API.

assetManager IAssetManager

The IAssetManager instance used within the sided API.

languageCode string

The language code to use as the default language.

lazyLoad bool
lbBehavior EnumLinebreakBehavior

PreLoad(ILogger, string, string)

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

public static void PreLoad(ILogger logger, string assetsPath, string defaultLanguage = "en")

Parameters

logger ILogger

The ILogger instance used within the sided API.

assetsPath string

The root assets path to load the vanilla files from.

defaultLanguage string

The language code to use as the default language.

PreLoadModWorldConfig(string, string, string)

Loads the mod worldconfig language JSON files only.

public static void PreLoadModWorldConfig(string modPath, string modDomain, string defaultLanguage = "en")

Parameters

modPath string

The assets path to load the mod files from.

modDomain string

The mod domain to use when loading the files.

defaultLanguage string

The language code to use as the default language.

UsesNonLatinCharacters(string)

public static bool UsesNonLatinCharacters(string lang)

Parameters

lang string

Returns

bool