tModLoader v2024.05
A mod to make and play Terraria mods
Language Class Reference

Contains methods to access or retrieve localization values. The Localization Guideteaches more about localization. More...

Static Public Member Functions

static bool Exists (string key)
 Checks if a LocalizedText with the provided key has been registered or not. This can be used to avoid retrieving dummy values from GetText(string) and GetTextValue(string) and instead load a fallback value or do other logic. If the key should be created if it doesn't exist, GetOrRegister(string, Func<string>) can be used instead.

Note that modded keys will be registered during mod loading and ModLoader.Mod.SetupContent is the earliest point where all keys should be registered with values loaded for the current language. More...
 
static LocalizedText[] FindAll (LanguageSearchFilter filter)
 Finds all LocalizedText that satisfy the filter parameter. Typically used with Lang.CreateDialogFilter(string) or Lang.CreateDialogFilter(string, object) as the filter argument to find all LocalizedText that have a specific key prefix and satisfy provided conditions. More...
 
static LocalizedText[] FindAll (Regex regex)
 
static int GetCategorySize (string key)
 
static LocalizedText GetOrRegister (string key, Func< string > makeDefaultValue=null)
 Returns a LocalizedText for a given key.
If no existing localization exists for the key, it will be defined so it can be exported to a matching mod localization file. More...
 
static LocalizedText GetOrRegister (Terraria.ModLoader.Mod mod, string key, Func< string > makeDefaultValue=null)
 
static LocalizedText GetText (string key)
 Retrieves a LocalizedText object for a specified localization key. The actual text value can be retrieved from LocalizedText by accessing the LocalizedText.Value property or by using the GetTextValue(string) method directly.

Using LocalizedText instead of string is preferred when the value is stored. If the user switches languages or if resource packs or mods change text, the LocalizedText will automatically receive the new value. In turn, mods using those LocalizedText will also start displaying the updated values.

More...
 
static string GetTextValue (string key)
 Retrieves the text value for a specified localization key. The text returned will be for the currently selected language. More...
 
static string GetTextValue (string key, object arg0)
 
static string GetTextValue (string key, object arg0, object arg1)
 
static string GetTextValue (string key, object arg0, object arg1, object arg2)
 
static string GetTextValue (string key, params object[] args)
 
static string GetTextValueWith (string key, object obj)
 
static LocalizedText RandomFromCategory (string categoryName, UnifiedRandom random=null)
 
static LocalizedText SelectRandom (LanguageSearchFilter filter, UnifiedRandom random=null)
 Selects a single random LocalizedText that satisfies the filter parameter. Typically used with Lang.CreateDialogFilter(string) or Lang.CreateDialogFilter(string, object) as the filter argument to find a random LocalizedText that has a specific key prefix and satisfies the provided conditions. More...
 

Properties

static GameCulture ActiveCulture [get]
 The language the game is currently using.
 

Detailed Description

Contains methods to access or retrieve localization values. The Localization Guide

teaches more about localization.

Member Function Documentation

◆ Exists()

static bool Language.Exists ( string  key)
static

Checks if a LocalizedText with the provided key has been registered or not. This can be used to avoid retrieving dummy values from GetText(string) and GetTextValue(string) and instead load a fallback value or do other logic. If the key should be created if it doesn't exist, GetOrRegister(string, Func<string>) can be used instead.

Note that modded keys will be registered during mod loading and ModLoader.Mod.SetupContent is the earliest point where all keys should be registered with values loaded for the current language.

Parameters
key
Returns

◆ FindAll()

static LocalizedText[] Language.FindAll ( LanguageSearchFilter  filter)
static

Finds all LocalizedText that satisfy the filter parameter. Typically used with Lang.CreateDialogFilter(string) or Lang.CreateDialogFilter(string, object) as the filter argument to find all LocalizedText that have a specific key prefix and satisfy provided conditions.

Parameters
filter
Returns

◆ GetOrRegister()

static LocalizedText Language.GetOrRegister ( string  key,
Func< string >  makeDefaultValue = null 
)
static

Returns a LocalizedText for a given key.
If no existing localization exists for the key, it will be defined so it can be exported to a matching mod localization file.

Parameters
keyThe localization key
makeDefaultValueA factory method for creating the default value, used to update localization files with missing entries
Returns

◆ GetText()

static LocalizedText Language.GetText ( string  key)
static

Retrieves a LocalizedText object for a specified localization key. The actual text value can be retrieved from LocalizedText by accessing the LocalizedText.Value property or by using the GetTextValue(string) method directly.

Using LocalizedText instead of string is preferred when the value is stored. If the user switches languages or if resource packs or mods change text, the LocalizedText will automatically receive the new value. In turn, mods using those LocalizedText will also start displaying the updated values.

Parameters
key
Returns

◆ GetTextValue()

static string Language.GetTextValue ( string  key)
static

Retrieves the text value for a specified localization key. The text returned will be for the currently selected language.

Parameters
key
Returns

◆ SelectRandom()

static LocalizedText Language.SelectRandom ( LanguageSearchFilter  filter,
UnifiedRandom  random = null 
)
static

Selects a single random LocalizedText that satisfies the filter parameter. Typically used with Lang.CreateDialogFilter(string) or Lang.CreateDialogFilter(string, object) as the filter argument to find a random LocalizedText that has a specific key prefix and satisfies the provided conditions.

Parameters
filter
random
Returns