TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ Format()

string Terraria.Localization.LocalizedText.Format ( params object[] args)
inline

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.

Parameters
args
Returns

Definition at line 207 of file LocalizedText.cs.

208 {
209 string value = Value;
210 bool valueOrDefault = _hasPlurals.GetValueOrDefault();
211 bool num;
212 if (!_hasPlurals.HasValue)
213 {
217 }
218 else
219 {
221 }
222 if (num)
223 {
224 value = ApplyPluralization(value, args);
225 }
226 try
227 {
228 return string.Format(value, args);
229 }
230 catch (FormatException e)
231 {
232 throw new Exception($"The localization key:\n \"{Key}\"\nwith a value of:\n \"{value}\"\nfailed to be formatted with the inputs:\n [{string.Join(", ", args)}]", e);
233 }
234 }
string Value
Retrieves the text value. This is the actual text the user should see.
static string ApplyPluralization(string value, params object[] args)
static readonly Regex PluralizationPatternRegex

References Terraria.Localization.LocalizedText._hasPlurals, Terraria.Localization.LocalizedText.ApplyPluralization(), Terraria.Localization.LocalizedText.PluralizationPatternRegex, and Terraria.Localization.LocalizedText.Value.

Referenced by Terraria.Localization.LocalizedText.BindArgs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: