1using Microsoft.Extensions.Localization;
4using System.ComponentModel;
5using System.Globalization;
14#pragma warning disable CA2211
15 public static Type DefaultStringResource = typeof(AppResources);
16 public static EventHandler<CultureInfo>? CurrentCultureChanged;
17 public static EventHandler<FlowDirection>? FlowDirectionChanged;
18#pragma warning restore CA2211
20 public static IStringLocalizer GetStringLocalizer(Type? StringResource =
null)
22 Type[] Arguments = [StringResource ?? DefaultStringResource];
23 Type GenericType = typeof(IStringLocalizer<>).MakeGenericType(Arguments);
27 return (IStringLocalizer)
ServiceHelper.GetService(GenericType);
35 public static IStringLocalizer GetStringLocalizer<TStringResource>()
39 return ServiceHelper.GetService<IStringLocalizer<TStringResource>>();
47 public static FlowDirection FlowDirection
51 return CultureInfo.CurrentCulture.TextInfo.IsRightToLeft
52 ? FlowDirection.RightToLeft
53 : FlowDirection.LeftToRight;
57 public CultureInfo CurrentCulture
59 get => CultureInfo.CurrentCulture;
63 if (CultureInfo.CurrentCulture.Name == value.Name)
68 CultureInfo.CurrentCulture = value;
69 CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture = value;
71 CurrentCultureChanged?.Invoke(
null, value);
72 PropertyChanged?.Invoke(
this,
new PropertyChangedEventArgs(nameof(this.CurrentCulture)));
74 FlowDirectionChanged?.Invoke(
this, FlowDirection);
75 PropertyChanged?.Invoke(
this,
new PropertyChangedEventArgs(nameof(FlowDirection)));
79 public event PropertyChangedEventHandler? PropertyChanged;
Represents localization errors.