Table of Contents

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

bool

KeyOrValue

The key, or the raw text when this is not a key.

public string KeyOrValue { get; }

Property Value

string

Methods

Exists(string)

Whether the current language, or the fallback language, has a key.

public static bool Exists(string key)

Parameters

key string

Returns

bool

FromKey(string)

Wraps a key to look up in the current language.

public static LocalizedString FromKey(string key)

Parameters

key string

Returns

LocalizedString

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

key string
args object[]

Returns

LocalizedString

FromRaw(string)

Wraps text to show as written, with no lookup.

public static LocalizedString FromRaw(string raw)

Parameters

raw string

Returns

LocalizedString

Resolve()

Returns the text in the current language. A key that neither language has is returned as the key itself.

public string Resolve()

Returns

string

Resolve(string)

Returns the text in the language with this code, rather than the current one.

public string Resolve(string languageCode)

Parameters

languageCode string

Returns

string

ToString()

Returns the same text as Resolve().

public override string ToString()

Returns

string

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

key string
value string

Returns

bool

Operators

implicit operator string(LocalizedString)

Resolves the text in the current language.

public static implicit operator string(LocalizedString localizedString)

Parameters

localizedString LocalizedString

Returns

string

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

raw string

Returns

LocalizedString