mirror of
https://gitcode.com/gh_mirrors/se/Semi.Avalonia
synced 2026-03-03 00:00:55 +08:00
feat: add helper method to set locale resources.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using Avalonia.Styling;
|
||||
@@ -60,4 +61,22 @@ public class SemiTheme : Styles
|
||||
}
|
||||
return _localeToResource[new CultureInfo("zh-cn")];
|
||||
}
|
||||
|
||||
public static void OverrideLocaleResources(Application application, CultureInfo culture)
|
||||
{
|
||||
if (!_localeToResource.TryGetValue(culture, out var resources)) return;
|
||||
foreach (var kv in resources)
|
||||
{
|
||||
application.Resources[kv.Key] = kv.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void OverrideLocaleResources(StyledElement element, CultureInfo culture)
|
||||
{
|
||||
if (!_localeToResource.TryGetValue(culture, out var resources)) return;
|
||||
foreach (var kv in resources)
|
||||
{
|
||||
element.Resources[kv.Key] = kv.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user