TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches
Terraria.Localization.LocalizedText Class Reference

Contains the localization value corresponding to a key for the current game language. Automatically updates as language, mods, and resource packs change. The Localization Guideteaches more about localization. More...

+ Collaboration diagram for Terraria.Localization.LocalizedText:

Public Member Functions

string FormatWith (object obj)
 Creates a string from this LocalizedText populated with data from the provided obj parameter. The properties of the provided object are substituted by name into the placeholders of the original text. For example, when used with M:Terraria.Lang.CreateDialogSubstitutionObject(Terraria.NPC), the text "{Nurse}" will be replaced with the first name of the Nurse in the world. Modded substitutions are not currently supported.

When used in conjunction with M:Terraria.Localization.Language.SelectRandom(Terraria.Localization.LanguageSearchFilter,Terraria.Utilities.UnifiedRandom) and M:Terraria.Lang.CreateDialogFilter(System.String,System.Object), simple boolean conditions expressed in each LocalizedText can be used to filter a collection of LocalizedText.

M:Terraria.Localization.LocalizedText.Format(System.Object[]) is more commonly used to format LocalizedText placeholders. That method replaces placeholders such as "{0}", "{1}", etc with the string representation of the corresponding objects provided.
 
bool CanFormatWith (object obj)
 Checks if the conditions embedded in this LocalizedText are satisfied by the obj argument. For example when used with M:Terraria.Lang.CreateDialogSubstitutionObject(Terraria.NPC) as the obj argument, "{?Rain}" at the start of a LocalizedText value will cause false to be returned if it is not raining. "{?!Rain}" would do the opposite. If all conditions are satisfied, true is returned.
The method is typically used indirectly by using M:Terraria.Lang.CreateDialogFilter(System.String,System.Object).
 
NetworkText ToNetworkText ()
 Convert this T:Terraria.Localization.LocalizedText to a T:Terraria.Localization.NetworkText for use in various network code applications. Non-chat messages sent to other players should be sent as T:Terraria.Localization.NetworkText to facilitate localization.
 
NetworkText ToNetworkText (params object[] substitutions)
 
override string ToString ()
 
string Format (params object[] args)
 Creates a string from this LocalizedText populated with data from the provided args arguments. Formats the string in the same manner as string.Format. Placeholders such as "{0}", "{1}", etc will be replaced with the string representation of the corresponding objects provided.
Additionally, pluralization is supported as well. The Contributing Localization Guideteaches more about placeholders and plural support.
 
LocalizedText WithFormatArgs (params object[] args)
 Creates a new LocalizedText with the supplied arguments formatted into the value (via M:System.String.Format(System.String,System.Object[]))
Will automatically update to re-format the string with cached args when language changes.

The resulting LocalizedText should be stored statically. Should not be used to create 'throwaway' LocalizedText instances.
Use M:Terraria.Localization.LocalizedText.Format(System.Object[]) instead for repeated on-demand formatting with different args.
The Localization Guideteaches more about using placeholders in localization.
 

Static Public Member Functions

static operator string (LocalizedText text)
 
static int CardinalPluralRule (GameCulture culture, int count)
 
static string ApplyPluralization (string value, params object[] args)
 

Public Attributes

readonly string Key
 

Static Public Attributes

static readonly LocalizedText Empty = new LocalizedText("", "")
 
static readonly Regex PluralizationPatternRegex = new Regex("{\\^(\\d+):([^\\r\\n]+?)}", RegexOptions.Compiled)
 

Package Functions

 LocalizedText (string key, string text)
 
void SetValue (string text)
 
void BindArgs (object[] args)
 

Properties

string Value [get, private set]
 Retrieves the text value. This is the actual text the user should see.
 
object[] BoundArgs [get, private set]
 Returns the args used with M:Terraria.Localization.LocalizedText.WithFormatArgs(System.Object[]) to create this text, if any.
 

Private Attributes

string _value
 
bool? _hasPlurals
 

Static Private Attributes

static Regex _substitutionRegex = new Regex("{(\\?(?:!)?)?([a-zA-Z][\\w\\.]*)}", RegexOptions.Compiled)
 

Detailed Description

Contains the localization value corresponding to a key for the current game language. Automatically updates as language, mods, and resource packs change. The Localization Guide

teaches more about localization.

Definition at line 10 of file LocalizedText.cs.


The documentation for this class was generated from the following file: