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
stringThe language code that this translation service caters for.
logger
ILoggerThe ILogger instance used within the sided API.
assetManager
IAssetManagerThe 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
Methods
EnsureLoaded()
protected void EnsureLoaded()
Format(string, params object[])
protected string Format(string value, params object[] args)
Parameters
Returns
Get(string, params object[])
Gets a translation for a given key.
public 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 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
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
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
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
stringThe 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
stringThe key.
findWildcarded
boolif 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
stringThe key.
findWildcarded
boolif set to
true
, the scan will include any wildcarded values.logErrors
boolif 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
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
stringThe assets path to load the mod files from.
modDomain
stringThe 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
IAssetManagerThe IAssetManager instance used within the sided API.