Struct LocalizedString
- Namespace
- BSGameLib.Game.Localization
- Assembly
- BSGameLib.Game.dll
Text that is either a key into the current language or a raw string shown as written.
public readonly struct LocalizedString
- Inherited Members
Remarks
Converts implicitly to and from string, so anything that wants text takes
either kind. A key is resolved in the current language, then in the fallback language,
and shows as the key itself if neither has it. Arguments are formatted into the resolved
text with Format(string, params object[]), so a language file writes
{0} where each goes and may reorder them; an argument that is itself a
LocalizedString is resolved as it is formatted in.
Properties
IsKey
True when this is a key rather than raw text.
public bool IsKey { get; }
Property Value
KeyOrValue
The key, or the raw text when this is not a key.
public string KeyOrValue { get; }
Property Value
Methods
Exists(string)
Whether the current language, or the fallback language, has a key.
public static bool Exists(string key)
Parameters
keystring
Returns
FromKey(string)
Wraps a key to look up in the current language.
public static LocalizedString FromKey(string key)
Parameters
keystring
Returns
FromKey(string, params object[])
Wraps a key with arguments, which are formatted into the resolved text with
string.Format.
public static LocalizedString FromKey(string key, params object[] args)
Parameters
Returns
FromRaw(string)
Wraps text to show as written, with no lookup.
public static LocalizedString FromRaw(string raw)
Parameters
rawstring
Returns
Resolve()
Returns the text in the current language. A key that neither language has is returned as the key itself.
public string Resolve()
Returns
Resolve(string)
Returns the text in the language with this code, rather than the current one.
public string Resolve(string languageCode)
Parameters
languageCodestring
Returns
ToString()
Returns the same text as Resolve().
public override string ToString()
Returns
TryResolve(string, out string)
Resolves a key without falling back to showing the key itself.
public static bool TryResolve(string key, out string value)
Parameters
Returns
Operators
implicit operator string(LocalizedString)
Resolves the text in the current language.
public static implicit operator string(LocalizedString localizedString)
Parameters
localizedStringLocalizedString
Returns
implicit operator LocalizedString(string)
Wraps raw as raw text, so a string can be used wherever a
LocalizedString is wanted.
public static implicit operator LocalizedString(string raw)
Parameters
rawstring