1using Microsoft.Extensions.Localization;
4using System.ComponentModel;
5using System.Globalization;
15#pragma warning disable CA2211
16 public static Type DefaultStringResource = typeof(
AppResources);
17 public static EventHandler<CultureInfo>? CurrentCultureChanged;
18 public static EventHandler<FlowDirection>? FlowDirectionChanged;
19#pragma warning restore CA2211
21 public static IStringLocalizer GetStringLocalizer(Type? StringResource =
null)
23 Type[] Arguments = [StringResource ?? DefaultStringResource];
24 Type GenericType = typeof(IStringLocalizer<>).MakeGenericType(Arguments);
28 return (IStringLocalizer)
ServiceHelper.GetService(GenericType);
36 public static IStringLocalizer GetStringLocalizer<TStringResource>()
40 return ServiceHelper.GetService<IStringLocalizer<TStringResource>>();
48 public static FlowDirection FlowDirection
52 return CultureInfo.CurrentCulture.TextInfo.IsRightToLeft
53 ? FlowDirection.RightToLeft
54 : FlowDirection.LeftToRight;
58 public CultureInfo CurrentCulture
60 get => CultureInfo.CurrentCulture;
64 if (CultureInfo.CurrentCulture.Name == value.Name)
69 CultureInfo.CurrentCulture = value;
70 CultureInfo.CurrentUICulture = value;
71 CultureInfo.DefaultThreadCurrentCulture = value;
72 CultureInfo.DefaultThreadCurrentUICulture = value;
74 AppResources.Culture = value;
76 CurrentCultureChanged.Raise(
null, value);
77 PropertyChanged?.Invoke(
this,
new PropertyChangedEventArgs(nameof(this.CurrentCulture)));
79 FlowDirectionChanged.Raise(
this, FlowDirection);
80 PropertyChanged?.Invoke(
this,
new PropertyChangedEventArgs(nameof(FlowDirection)));
84 public event PropertyChangedEventHandler? PropertyChanged;
Represents localization errors.
A strongly-typed resource class, for looking up localized strings, etc.