Table of Contents

Class LocaleExtensions

Namespace
MonkeyLoader.Resonite
Assembly
MonkeyLoader.Resonite.Integration.dll

Contains helper methods to create Elements.Core.LocaleStrings prefixed with a Id.

public static class LocaleExtensions
Inheritance
LocaleExtensions
Inherited Members

Fields

FallbackLocaleCode

Gets the locale code for the fallback locale.

public const string FallbackLocaleCode = "en"

Field Value

string

ModLocaleStringIndicatorArgumentName

The name of the argument added to Mod's locale strings to indicate that they belong to a identifiable.

public const string ModLocaleStringIndicatorArgumentName = "MonkeyLoader.Mod.LocaleString"

Field Value

string

Properties

CurrentLocale

Gets the latest loaded Elements.Assets.LocaleResource data for the current locale.

public static LocaleResource CurrentLocale { get; }

Property Value

LocaleResource

FallbackLocale

Gets the latest loaded Elements.Assets.LocaleResource data for the fallback locale.

public static LocaleResource FallbackLocale { get; }

Property Value

LocaleResource

Methods

FormatWithCurrent(LocaleString, bool)

Gets the formatted, localized message of this Elements.Core.LocaleString according to the current locale.

public static string? FormatWithCurrent(this LocaleString localeString, bool returnNullIfNotFound = false)

Parameters

localeString LocaleString

The locale string to get the localized message of.

returnNullIfNotFound bool

Whether to return null if the current locale does not have a message for the locale key.

Returns

string

Elements.Core.LocaleString.content if it's not a locale key; otherwise, the formatted, localized message, or null if returnNullIfNotFound is true and the key does not have a message.

FormatWithFallback(LocaleString, bool)

Gets the formatted, localized message of this Elements.Core.LocaleString according to the fallback locale.

public static string? FormatWithFallback(this LocaleString localeString, bool returnNullIfNotFound = false)

Parameters

localeString LocaleString

The locale string to get the localized message of.

returnNullIfNotFound bool

Whether to return null if the current locale does not have a message for the locale key.

Returns

string

Elements.Core.LocaleString.content if it's not a locale key; otherwise, the formatted, localized message, or null if returnNullIfNotFound is true and the key does not have a message.

FormatWithLocale(LocaleString, LocaleResource, bool)

Gets the formatted, localized message of this Elements.Core.LocaleString according to the given locale.

public static string? FormatWithLocale(this LocaleString localeString, LocaleResource locale, bool returnNullIfNotFound = false)

Parameters

localeString LocaleString

The locale string to get the localized message of.

locale LocaleResource

The locale to localize the message in.

returnNullIfNotFound bool

Whether to return null if the current locale does not have a message for the locale key.

Returns

string

Elements.Core.LocaleString.content if it's not a locale key; otherwise, the formatted, localized message, or null if returnNullIfNotFound is true and the key does not have a message.

FormatWithLocale(LocaleString, LocaleResource, bool)

Gets the formatted, localized message of this Elements.Core.LocaleString according to the given locale.

public static string? FormatWithLocale(this LocaleString localeString, LocaleResource locale, bool returnNullIfNotFound = false)

Parameters

localeString LocaleString

The locale string to get the localized message of.

locale LocaleResource

The locale to localize the message in.

returnNullIfNotFound bool

Whether to return null if the current locale does not have a message for the locale key.

Returns

string

Elements.Core.LocaleString.content if it's not a locale key; otherwise, the formatted, localized message, or null if returnNullIfNotFound is true and the key does not have a message.

GetLocaleKey(IIdentifiable, string)

Creates a locale key prefixed with identifiable's FullId, in the format: $"{identifiable.FullId}.{key}".

public static string GetLocaleKey(this IIdentifiable identifiable, string key)

Parameters

identifiable IIdentifiable

The IIdentifiable whose FullId to use as a prefix.

key string

The locale key to prefix.

Returns

string

The prefixed locale key.

GetLocaleString(IIdentifiable, string, bool, Dictionary<string, object>?)

Uses identifiable.GetLocaleKey(key) as the key to create a Elements.Core.LocaleString using the other arguments.

public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, bool continuous, Dictionary<string, object>? arguments = null)

Parameters

identifiable IIdentifiable

The IIdentifiable whose FullId to use as a prefix.

key string

The locale key to prefix.

continuous bool

Whether to assign the locale message once or continuously.

arguments Dictionary<string, object>

The arguments used to format the locale message.

Returns

LocaleString

The Mod-Elements.Core.LocaleString created from the key with the arguments.

GetLocaleString(IIdentifiable, string, string?, bool, Dictionary<string, object>?)

Uses identifiable.GetLocaleKey(key) as the key to create a Elements.Core.LocaleString using the other arguments.

public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, string? format = null, bool continuous = true, Dictionary<string, object>? arguments = null)

Parameters

identifiable IIdentifiable

The IIdentifiable whose FullId to use as a prefix.

key string

The locale key to prefix.

format string

An additional format string to insert the locale message into.

continuous bool

Whether to assign the locale message once or continuously.

arguments Dictionary<string, object>

The arguments used to format the locale message.

Returns

LocaleString

The Mod-Elements.Core.LocaleString created from the key with the arguments.

GetLocaleString(IIdentifiable, string, string, object)

Uses identifiable.GetLocaleKey(key) as the key to create a Elements.Core.LocaleString using the other arguments.

public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, string argName, object argField)

Parameters

identifiable IIdentifiable

The IIdentifiable whose FullId to use as a prefix.

key string

The locale key to prefix.

argName string

The name of the single argument used to format the locale message.

argField object

The value of the single argument used to format the locale message.

Returns

LocaleString

The Mod-Elements.Core.LocaleString created from the key with the arguments.

GetLocaleString(IIdentifiable, string, string, string, object)

Uses identifiable.GetLocaleKey(key) as the key to create a Elements.Core.LocaleString using the other arguments.

public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, string format, string argName, object argField)

Parameters

identifiable IIdentifiable

The IIdentifiable whose FullId to use as a prefix.

key string

The locale key to prefix.

format string

An additional format string to insert the locale message into.

argName string

The name of the single argument used to format the locale message.

argField object

The value of the single argument used to format the locale message.

Returns

LocaleString

The Mod-Elements.Core.LocaleString created from the key with the arguments.

GetLocaleString(IIdentifiable, string, string, params (string, object)[])

Uses identifiable.GetLocaleKey(key) as the key to create a Elements.Core.LocaleString using the other arguments.

public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, string format, params (string, object)[] arguments)

Parameters

identifiable IIdentifiable

The IIdentifiable whose FullId to use as a prefix.

key string

The locale key to prefix.

format string

An additional format string to insert the locale message into.

arguments (string, object)[]

The arguments used to format the locale message.

Returns

LocaleString

The Mod-Elements.Core.LocaleString created from the key with the arguments.

GetLocaleString(IIdentifiable, string, params (string, object)[])

Uses identifiable.GetLocaleKey(key) as the key to create a Elements.Core.LocaleString using the other arguments.

public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, params (string, object)[] arguments)

Parameters

identifiable IIdentifiable

The IIdentifiable whose FullId to use as a prefix.

key string

The locale key to prefix.

arguments (string, object)[]

The arguments used to format the locale message.

Returns

LocaleString

The Mod-Elements.Core.LocaleString created from the key with the arguments.

GetMessageInCurrent(IIdentifiable, string)

Gets the formatted, localized message of the given locale key prefixed with the identifiable's FullId according to the current locale.

public static string GetMessageInCurrent(this IIdentifiable identifiable, string key)

Parameters

identifiable IIdentifiable

The IIdentifiable whose FullId to use as a prefix.

key string

The locale key to prefix.

Returns

string

GetMessageInFallback(IIdentifiable, string)

Gets the formatted, localized message of the given locale key prefixed with the identifiable's FullId according to the fallback locale.

public static string GetMessageInFallback(this IIdentifiable identifiable, string key)

Parameters

identifiable IIdentifiable

The IIdentifiable whose FullId to use as a prefix.

key string

The locale key to prefix.

Returns

string

GetMessageInLocale(IIdentifiable, string, LocaleResource)

Gets the formatted, localized message of the given locale key prefixed with the identifiable's FullId according to the given locale.

public static string GetMessageInLocale(this IIdentifiable identifiable, string key, LocaleResource locale)

Parameters

identifiable IIdentifiable

The IIdentifiable whose FullId to use as a prefix.

key string

The locale key to prefix.

locale LocaleResource

The locale to localize the message in.

Returns

string

HasMessageInCurrent(LocaleString)

Checks whether this Elements.Core.LocaleString has a message in the current locale.

public static bool HasMessageInCurrent(this LocaleString localeString)

Parameters

localeString LocaleString

The locale string to check for a message for.

Returns

bool

true if a message was found in the current locale; otherwise, false.

HasMessageInCurrent(string?)

Checks whether this locale key has a message in the current locale.

public static bool HasMessageInCurrent(this string? localeKey)

Parameters

localeKey string

The locale key to check for a message for.

Returns

bool

true if a message was found in the current locale; otherwise, false.

HasMessageInFallback(LocaleString)

Checks whether this Elements.Core.LocaleString has a message in the fallback locale.

public static bool HasMessageInFallback(this LocaleString localeString)

Parameters

localeString LocaleString

The locale string to check for a message for.

Returns

bool

true if a message was found in the fallback locale; otherwise, false.

HasMessageInFallback(string?)

Checks whether this locale key has a message in the fallback locale.

public static bool HasMessageInFallback(this string? localeKey)

Parameters

localeKey string

The locale key to check for a message for.

Returns

bool

true if a message was found in the fallback locale; otherwise, false.

HasMessageInLocale(LocaleString, LocaleResource)

Checks whether this Elements.Core.LocaleString has a message in the given locale.

public static bool HasMessageInLocale(this LocaleString localeString, LocaleResource locale)

Parameters

localeString LocaleString

The locale string to check for a message for.

locale LocaleResource

The locale to check for a message in.

Returns

bool

true if a message was found in the locale; otherwise, false.

HasMessageInLocale(string?, LocaleResource)

Checks whether this locale key has a message in the given locale.

public static bool HasMessageInLocale(this string? localeKey, LocaleResource locale)

Parameters

localeKey string

The locale key to check for a message for.

locale LocaleResource

The locale to check for a message in.

Returns

bool

true if a message was found in the locale; otherwise, false.

IsModLocaleString(LocaleString)

Determines whether this Elements.Core.LocaleString belongs to an identifiable.

public static bool IsModLocaleString(this LocaleString localeString)

Parameters

localeString LocaleString

The Elements.Core.LocaleString to check.

Returns

bool

true if the given Elements.Core.LocaleString belongs to an identifiable; otherwise, false.