Class TextResolver
- Namespace
- TDMaker.Unity.Localization
- Assembly
- TDMaker.Unity.dll
Resolves text keys for the selected language. Lookup order: the optional custom Provider, the Tables of the selected Language, the English tables, the built-in English texts (English), then the caller's fallback, then the key itself. The merged table is rebuilt only when the language, the table list or a table changes; lookups do not allocate. Version changes on every rebuild, so views can cache formatted strings and refresh them only then. The scene's instance is Texts.
public sealed class TextResolver
- Inheritance
-
TextResolver
- Inherited Members
Constructors
TextResolver(string, IList<TextTable>)
Creates a resolver for languageCode over textTables (both optional).
public TextResolver(string languageCode = "en", IList<TextTable> textTables = null)
Parameters
Fields
EnglishCode
Language of the built-in texts and the fallback language.
public const string EnglishCode = "en"
Field Value
Properties
Language
The selected language code (for example "en" or "ko"). Setting it rebuilds the lookup on next use.
public string Language { get; set; }
Property Value
Provider
Optional source consulted before the tables (for example an adapter to another localization system).
public ITextProvider Provider { get; set; }
Property Value
Tables
Tables to search (any languages; those matching Language and English are used).
public IList<TextTable> Tables { get; set; }
Property Value
Version
Changes whenever the resolved texts may have changed (language, tables, provider, or a table edited). Unique across resolvers, so a cached value never matches a different resolver by accident.
public int Version { get; }
Property Value
Methods
Format(string, object)
Formats the text of key with one argument (allocates; call when the value changes).
public string Format(string key, object arg0)
Parameters
Returns
Format(string, object, object)
Formats the text of key with two arguments (allocates; call when a value changes).
public string Format(string key, object arg0, object arg1)
Parameters
Returns
Format(string, object, object, object)
Formats the text of key with three arguments (allocates; call when a value changes).
public string Format(string key, object arg0, object arg1, object arg2)
Parameters
Returns
FormatText(string, object)
Formats an already resolved format text (for example from Get(string, string)) with one
argument; a text with broken placeholders is returned unformatted (and logged once) instead of throwing.
public string FormatText(string format, object arg0)
Parameters
Returns
Get(string)
The text for key, or the key itself when no source has it.
public string Get(string key)
Parameters
keystring
Returns
Get(string, string)
The text for key, or fallback (then the key) when no source has it.
public string Get(string key, string fallback)
Parameters
Returns
Has(string)
Whether any source (provider, tables, built-in English) has a text for key.
public bool Has(string key)
Parameters
keystring
Returns
Invalidate()
Forces a rebuild on next use (call after an external Provider switched language).
public void Invalidate()
LanguageMatches(string, string)
Whether a table code serves a requested language: equal ignoring case, or equal primary subtags ("ko" serves "ko-KR" and the other way round).
public static bool LanguageMatches(string tableCode, string language)