Interface IMessageFormatter
- Namespace
- RentADeveloper.ResXLocalization
- Assembly
- ResXLocalization.Core.dll
Turns a resolved resource value and the arguments of its lookup - possibly none - into the final string. Assign an implementation to MessageFormatter to replace the default StringFormatMessageFormatter.
public interface IMessageFormatter
Remarks
The localizer calls Format(string, MessageArguments, CultureInfo) for every lookup that resolves a resource value, whether or not the lookup has arguments, so a formatter is the one hook every translated text passes through. It is never called for a key no resource file contains, and never for a null or empty key.
An implementation signals a malformed pattern or unusable arguments by throwing. The localizer catches the exception, raises LookupFailed and returns the failure text. Because every lookup calls the formatter, a formatter that throws for values without arguments turns plain texts into the failure text too.
Methods
Format(string, MessageArguments, CultureInfo)
Formats a resolved resource value with the arguments of its lookup.
string Format(string pattern, MessageArguments arguments, CultureInfo culture)
Parameters
patternstringThe resolved resource value.
argumentsMessageArgumentsThe arguments of the lookup; never null. Read each argument's position from Position; an argument's index in the enumeration is not guaranteed to be the same as its position. They are empty (Count is 0) when the lookup had no arguments: a call to
ILocalizer.Getwithout arguments (or with Empty), a lookup through the ILocalizer indexer (Localizer.Current["Key"]), or a XAML lookup through the{l:Localize}markup extension of the ResXLocalization.Avalonia and ResXLocalization.WPF packages without arguments. The default formatter then returnspatternunchanged, and an implementation should do the same unless it deliberately handles values without arguments: formatting them would turn{{x}}into{x}and make every plain text containing{0}or a literal{fail.cultureCultureInfoThe localizer's CurrentCulture at the time of the lookup.
Returns
- string
The final string.