ILocalizationFormatter
Namespace: Bogoware.Localization
Formats ILocalizable instances and arbitrary values into culture-aware human-readable strings using FQDN-keyed template registries.
public interface ILocalizationFormatterAttributes NullableContextAttribute
Remarks:
The formatter applies the following resolution chain in order:
-
- Self-provider — if the value implements ILocalizationProvider, its
Localizemethod is called directly.
- Self-provider — if the value implements ILocalizationProvider, its
-
- DI provider — an ILocalizationProvider<T> resolved from the service provider for the runtime type.
-
- Registry template — an ILocalizationRegistry template keyed by
Type.FullName, with{PropertyName}placeholders.
- Registry template — an ILocalizationRegistry template keyed by
-
- Fallback — a generated string in the form
TypeName(Prop=val).
- Fallback — a generated string in the form
For the generic ILocalizationFormatter.Format(ILocalizable, CultureInfo) overload, non-ILocalizable types skip steps 1 and 3,
falling back to ToString() if no DI provider is registered.
Methods
Format(ILocalizable, CultureInfo)
Formats an ILocalizable using the full resolution chain: self-provider, DI provider, registry template, fallback.
string Format(ILocalizable value, CultureInfo culture)Parameters
value ILocalizable
The localizable instance to format.
culture CultureInfo
The target culture. When , defaults to CultureInfo.CurrentUICulture.
Returns
String
A culture-aware human-readable string.
Format<T>(T, CultureInfo)
Formats an arbitrary value. If it implements ILocalizable,
delegates to ILocalizationFormatter.Format(ILocalizable, CultureInfo).
Otherwise tries the DI provider, then ToString() fallback.
string Format<T>(T value, CultureInfo culture)Type Parameters
T
The type of value to format.
Parameters
value T
The value to format.
culture CultureInfo
The target culture. When , defaults to CultureInfo.CurrentUICulture.
Returns
String
A culture-aware human-readable string.