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
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
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
LocaleStringThe locale string to get the localized message of.
returnNullIfNotFound
boolWhether 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
ifreturnNullIfNotFound
istrue
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
LocaleStringThe locale string to get the localized message of.
returnNullIfNotFound
boolWhether 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
ifreturnNullIfNotFound
istrue
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
LocaleStringThe locale string to get the localized message of.
locale
LocaleResourceThe locale to localize the message in.
returnNullIfNotFound
boolWhether 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
ifreturnNullIfNotFound
istrue
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
LocaleStringThe locale string to get the localized message of.
locale
LocaleResourceThe locale to localize the message in.
returnNullIfNotFound
boolWhether 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
ifreturnNullIfNotFound
istrue
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
IIdentifiableThe IIdentifiable whose FullId to use as a prefix.
key
stringThe locale key to prefix.
Returns
- string
The prefixed locale key.
GetLocaleString(IIdentifiable, string, bool, Dictionary<string, object>?)
Uses
as the key to create a Elements.Core.LocaleString using the other arguments.identifiable
.GetLocaleKey(key
)
public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, bool continuous, Dictionary<string, object>? arguments = null)
Parameters
identifiable
IIdentifiableThe IIdentifiable whose FullId to use as a prefix.
key
stringThe locale key to prefix.
continuous
boolWhether 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
as the key to create a Elements.Core.LocaleString using the other arguments.identifiable
.GetLocaleKey(key
)
public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, string? format = null, bool continuous = true, Dictionary<string, object>? arguments = null)
Parameters
identifiable
IIdentifiableThe IIdentifiable whose FullId to use as a prefix.
key
stringThe locale key to prefix.
format
stringAn additional format string to insert the locale message into.
continuous
boolWhether 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
as the key to create a Elements.Core.LocaleString using the other arguments.identifiable
.GetLocaleKey(key
)
public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, string argName, object argField)
Parameters
identifiable
IIdentifiableThe IIdentifiable whose FullId to use as a prefix.
key
stringThe locale key to prefix.
argName
stringThe name of the single argument used to format the locale message.
argField
objectThe 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
as the key to create a Elements.Core.LocaleString using the other arguments.identifiable
.GetLocaleKey(key
)
public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, string format, string argName, object argField)
Parameters
identifiable
IIdentifiableThe IIdentifiable whose FullId to use as a prefix.
key
stringThe locale key to prefix.
format
stringAn additional format string to insert the locale message into.
argName
stringThe name of the single argument used to format the locale message.
argField
objectThe 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
as the key to create a Elements.Core.LocaleString using the other arguments.identifiable
.GetLocaleKey(key
)
public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, string format, params (string, object)[] arguments)
Parameters
identifiable
IIdentifiableThe IIdentifiable whose FullId to use as a prefix.
key
stringThe locale key to prefix.
format
stringAn 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
as the key to create a Elements.Core.LocaleString using the other arguments.identifiable
.GetLocaleKey(key
)
public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, params (string, object)[] arguments)
Parameters
identifiable
IIdentifiableThe IIdentifiable whose FullId to use as a prefix.
key
stringThe 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
IIdentifiableThe IIdentifiable whose FullId to use as a prefix.
key
stringThe locale key to prefix.
Returns
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
IIdentifiableThe IIdentifiable whose FullId to use as a prefix.
key
stringThe locale key to prefix.
Returns
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
IIdentifiableThe IIdentifiable whose FullId to use as a prefix.
key
stringThe locale key to prefix.
locale
LocaleResourceThe locale to localize the message in.
Returns
HasMessageInCurrent(LocaleString)
Checks whether this Elements.Core.LocaleString has a message in the current locale.
public static bool HasMessageInCurrent(this LocaleString localeString)
Parameters
localeString
LocaleStringThe 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
stringThe 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
LocaleStringThe 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
stringThe 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
LocaleStringThe locale string to check for a message for.
locale
LocaleResourceThe 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
stringThe locale key to check for a message for.
locale
LocaleResourceThe 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
LocaleStringThe Elements.Core.LocaleString to check.
Returns
- bool
true
if the given Elements.Core.LocaleString belongs to an identifiable; otherwise,false
.