Class Lang
- Namespace
- Vintagestory.API.Config
- Assembly
- VintagestoryAPI.dll
Utility class for enabling i18n. Loads language entries from assets/[locale].json Open in GitHub
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 the 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
languageCodestringThe 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
nullas 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
codeAssetLocation
Returns
GetUnformatted(string)
Gets the raw, unformatted translated value for the key provided.
public static string GetUnformatted(string key)
Parameters
keystringThe 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
keystringThe key.
findWildcardedboolif set to
true, the scan will include any wildcarded values.logErrorsbool
Returns
- bool
trueif 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
loggerILoggerThe ILogger instance used within the sided API.
assetManagerIAssetManagerThe IAssetManager instance used within the sided API.
languagestringThe 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
loggerILoggerThe ILogger instance used within the sided API.
assetManagerIAssetManagerThe IAssetManager instance used within the sided API.
languageCodestringThe language code to use as the default language.
lazyLoadboollbBehaviorEnumLinebreakBehavior
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
loggerILoggerThe ILogger instance used within the sided API.
assetsPathstringThe root assets path to load the vanilla files from.
defaultLanguagestringThe 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
modPathstringThe assets path to load the mod files from.
modDomainstringThe mod domain to use when loading the files.
defaultLanguagestringThe language code to use as the default language.
UsesNonLatinCharacters(string)
public static bool UsesNonLatinCharacters(string lang)
Parameters
langstring