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
Remarks
It contains the Mod that it belongs to as the value, or the Resonite Game Pack as a fallback.
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
ExportFallbackLocaleFile(Mod, bool)
Exports the fallback locale data of this mod into a json file.
public static void ExportFallbackLocaleFile(this Mod mod, bool useLoadedMessages = true)
Parameters
modModThe mod to export the fallback locale data for.
useLoadedMessagesboolWhether to use the actually loaded message patterns in the FallbackLocale or the raw hard-coded ones.
Uses the loaded message patterns by default to preserve any already present custom messages.
Remarks
The file can be found at: Resonite/MonkeyLoader/LocaleExport/{mod.Id}-en.json
This method represents an in-code alternative to starting the game
and exporting the locale data through the entry in the settings.
ExportFallbackLocaleFileAsync(Mod, bool)
Asynchronously exports the fallback locale data of this mod into a json file.
public static Task ExportFallbackLocaleFileAsync(this Mod mod, bool useLoadedMessages = true)
Parameters
modModThe mod to export the fallback locale data for.
useLoadedMessagesboolWhether to use the actually loaded message patterns in the FallbackLocale or the raw hard-coded ones.
Uses the loaded message patterns by default to preserve any already present custom messages.
Returns
- Task
A task representing the asynchronous operation.
Remarks
The file can be found at: Resonite/MonkeyLoader/LocaleExport/{mod.Id}-en.json
This method represents an in-code alternative to starting the game
and exporting the locale data through the entry in the settings.
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
localeStringLocaleStringThe locale string to get the localized message of.
returnNullIfNotFoundboolWhether to return
nullif 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
nullifreturnNullIfNotFoundistrueand 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
localeStringLocaleStringThe locale string to get the localized message of.
returnNullIfNotFoundboolWhether to return
nullif 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
nullifreturnNullIfNotFoundistrueand 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
localeStringLocaleStringThe locale string to get the localized message of.
localeLocaleResourceThe locale to localize the message in.
returnNullIfNotFoundboolWhether to return
nullif 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
nullifreturnNullIfNotFoundistrueand 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
localeStringLocaleStringThe locale string to get the localized message of.
localeLocaleResourceThe locale to localize the message in.
returnNullIfNotFoundboolWhether to return
nullif 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
nullifreturnNullIfNotFoundistrueand 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
identifiableIIdentifiableThe IIdentifiable whose FullId to use as a prefix.
keystringThe 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
identifiableIIdentifiableThe IIdentifiable whose FullId to use as a prefix.
keystringThe locale key to prefix.
continuousboolWhether to assign the locale message once or continuously.
argumentsDictionary<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
identifiableIIdentifiableThe IIdentifiable whose FullId to use as a prefix.
keystringThe locale key to prefix.
formatstringAn additional format string to insert the locale message into.
continuousboolWhether to assign the locale message once or continuously.
argumentsDictionary<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
identifiableIIdentifiableThe IIdentifiable whose FullId to use as a prefix.
keystringThe locale key to prefix.
argNamestringThe name of the single argument used to format the locale message.
argFieldobjectThe 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
identifiableIIdentifiableThe IIdentifiable whose FullId to use as a prefix.
keystringThe locale key to prefix.
formatstringAn additional format string to insert the locale message into.
argNamestringThe name of the single argument used to format the locale message.
argFieldobjectThe 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
identifiableIIdentifiableThe IIdentifiable whose FullId to use as a prefix.
keystringThe locale key to prefix.
formatstringAn 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
identifiableIIdentifiableThe IIdentifiable whose FullId to use as a prefix.
keystringThe 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
identifiableIIdentifiableThe IIdentifiable whose FullId to use as a prefix.
keystringThe 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
identifiableIIdentifiableThe IIdentifiable whose FullId to use as a prefix.
keystringThe 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
identifiableIIdentifiableThe IIdentifiable whose FullId to use as a prefix.
keystringThe locale key to prefix.
localeLocaleResourceThe 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
localeStringLocaleStringThe locale string to check for a message for.
Returns
- bool
trueif 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
localeKeystringThe locale key to check for a message for.
Returns
- bool
trueif 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
localeStringLocaleStringThe locale string to check for a message for.
Returns
- bool
trueif 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
localeKeystringThe locale key to check for a message for.
Returns
- bool
trueif 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
localeStringLocaleStringThe locale string to check for a message for.
localeLocaleResourceThe locale to check for a message in.
Returns
- bool
trueif 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
localeKeystringThe locale key to check for a message for.
localeLocaleResourceThe locale to check for a message in.
Returns
- bool
trueif 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
localeStringLocaleStringThe Elements.Core.LocaleString to check.
Returns
- bool
trueif the given Elements.Core.LocaleString belongs to an identifiable; otherwise,false.