Class MessageFormatLocalizerExtensions
- Namespace
- RentADeveloper.ResXLocalization.MessageFormat
- Assembly
- ResXLocalization.MessageFormat.dll
Installs ICU MessageFormat as the formatter of an ILocalizer, for messages whose shape
depends on their arguments, such as {Count, plural, one {# file deleted} other {# files deleted}}.
public static class MessageFormatLocalizerExtensions
- Inheritance
-
MessageFormatLocalizerExtensions
- Inherited Members
Methods
UseMessageFormat(ILocalizer, MessageFormatter?)
Replaces the MessageFormatter of localizer with the ICU
MessageFormat formatter, for every lookup in code and in XAML. Call it once, at startup:
Localizer.Current.UseMessageFormat();
public static void UseMessageFormat(this ILocalizer localizer, MessageFormatter? messageFormatter = null)
Parameters
localizerILocalizerThe localizer whose formatter to replace, usually Current.
messageFormatterMessageFormatterThe Jeffijoe.MessageFormat.MessageFormatter of the MessageFormat library that formats every message, or null (the default) for a new one with the library's defaults. A non-null instance is used as given, with its custom formatters, pluralizers and
CustomValueFormatter, and is shared by every culture and every thread: configure it completely before the call, and do not modify it afterwards. ItsCultureproperty has no effect, because every lookup passes its own culture.
Remarks
After the call, every resolved resource value is parsed as an ICU message, also for a lookup without
arguments: Localizer.Current.Get("Key"), the ILocalizer indexer, and
{l:Localize Key} of the ResXLocalization.Avalonia and ResXLocalization.WPF packages. Every
resource value must therefore follow ICU syntax, including texts without arguments: It''s ready
renders It's ready, '{literal}' renders {literal}, and a value that references a
variable the lookup does not supply returns the failure text and raises
LookupFailed.
Named arguments are built with MessageArguments, for example
Localizer.Current.Get(AppStringsKeys.FilesDeleted, MessageArguments.FromTuples(("Count", 5))), and
declared in XAML as <l:Argument Name="Count" Value="{Binding DeletedCount}" />. Every
argument is also reachable under its position: {0}, {1} and so on.
The method works with any ILocalizer implementation, because it only assigns MessageFormatter. An exception thrown by the setter of a custom implementation, or by a PropertyChanged handler during the assignment, propagates.
See ICU MessageFormat.
Exceptions
- ArgumentNullException
localizeris null.