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
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
Methods
ChangeLanguage(string)
Changes the current language for the game.
public static void ChangeLanguage(string languageCode)
Parameters
languageCode
stringThe 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
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
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
Returns
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
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
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
Returns
GetNamePlaceHolder(AssetLocation)
public static string GetNamePlaceHolder(AssetLocation code)
Parameters
code
AssetLocation
Returns
GetUnformatted(string)
Gets the raw, unformatted translated value for the key provided.
public static string GetUnformatted(string key)
Parameters
key
stringThe 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
Returns
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
stringThe key.
findWildcarded
boolif 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
ILoggerThe ILogger instance used within the sided API.
assetManager
IAssetManagerThe IAssetManager instance used within the sided API.
language
stringThe 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
ILoggerThe ILogger instance used within the sided API.
assetManager
IAssetManagerThe IAssetManager instance used within the sided API.
languageCode
stringThe language code to use as the default language.
lazyLoad
boollbBehavior
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
ILoggerThe ILogger instance used within the sided API.
assetsPath
stringThe root assets path to load the vanilla files from.
defaultLanguage
stringThe 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
stringThe assets path to load the mod files from.
modDomain
stringThe mod domain to use when loading the files.
defaultLanguage
stringThe language code to use as the default language.
UsesNonLatinCharacters(string)
public static bool UsesNonLatinCharacters(string lang)
Parameters
lang
string