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. Open in GitHub
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
languageCodestringThe language code that this translation service caters for.
loggerILoggerThe ILogger instance used within the sided API.
assetManagerIAssetManagerThe IAssetManager instance used within the sided API.
lbBehaviorEnumLinebreakBehavior
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
nullas 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
keystringThe 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
keystringThe key.
findWildcardedboolif set to
true, the scan will include any wildcarded values.
Returns
- bool
trueif 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
keystringThe key.
findWildcardedboolif set to
true, the scan will include any wildcarded values.logErrorsboolif set to
true, will add "Lang key not found" logging
Returns
- bool
trueif 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
lazyLoadbool
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
modPathstringThe assets path to load the mod files from.
modDomainstringThe mod domain to use when loading the files.
lazyLoadbool
UseAssetManager(IAssetManager)
Specifies an asset manager to use, when the service has been lazy-loaded.
public void UseAssetManager(IAssetManager assetManager)
Parameters
assetManagerIAssetManagerThe IAssetManager instance used within the sided API.