mirror of
https://gitcode.com/gh_mirrors/se/Semi.Avalonia
synced 2026-04-22 09:26:35 +08:00
feat: add simple locale switch.
This commit is contained in:
@@ -25,6 +25,8 @@ public partial class MainViewModel : ObservableObject
|
||||
public string DocumentationUrl => "https://docs.irihi.tech/semi";
|
||||
public string RepoUrl => "https://github.com/irihitech/Semi.Avalonia";
|
||||
public IReadOnlyList<MenuItemViewModel> MenuItems { get; }
|
||||
|
||||
public IReadOnlyList<MenuItemViewModel> LocaleItems { get; }
|
||||
|
||||
public MainViewModel()
|
||||
{
|
||||
@@ -62,6 +64,52 @@ public partial class MainViewModel : ObservableObject
|
||||
]
|
||||
}
|
||||
];
|
||||
LocaleItems =
|
||||
[
|
||||
new MenuItemViewModel
|
||||
{
|
||||
Header = "Locale",
|
||||
Items =
|
||||
[
|
||||
new MenuItemViewModel
|
||||
{
|
||||
Header = "简体中文",
|
||||
Command = SelectLocaleCommand,
|
||||
CommandParameter = new System.Globalization.CultureInfo("zh-cn")
|
||||
},
|
||||
new MenuItemViewModel
|
||||
{
|
||||
Header = "English",
|
||||
Command = SelectLocaleCommand,
|
||||
CommandParameter = new System.Globalization.CultureInfo("en-us")
|
||||
},
|
||||
new MenuItemViewModel
|
||||
{
|
||||
Header = "日本語",
|
||||
Command = SelectLocaleCommand,
|
||||
CommandParameter = new System.Globalization.CultureInfo("ja-jp")
|
||||
},
|
||||
new MenuItemViewModel
|
||||
{
|
||||
Header = "Українська",
|
||||
Command = SelectLocaleCommand,
|
||||
CommandParameter = new System.Globalization.CultureInfo("uk-ua")
|
||||
},
|
||||
new MenuItemViewModel
|
||||
{
|
||||
Header = "Русский",
|
||||
Command = SelectLocaleCommand,
|
||||
CommandParameter = new System.Globalization.CultureInfo("ru-ru")
|
||||
},
|
||||
new MenuItemViewModel
|
||||
{
|
||||
Header = "繁體中文",
|
||||
Command = SelectLocaleCommand,
|
||||
CommandParameter = new System.Globalization.CultureInfo("zh-tw")
|
||||
},
|
||||
]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
@@ -82,6 +130,16 @@ public partial class MainViewModel : ObservableObject
|
||||
app.RequestedThemeVariant = obj as ThemeVariant;
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void SelectLocale(object? obj)
|
||||
{
|
||||
var app = Application.Current;
|
||||
if (app is not null)
|
||||
{
|
||||
SemiTheme.OverrideLocaleResources(app, obj as System.Globalization.CultureInfo);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private static async Task OpenUrl(string url)
|
||||
|
||||
Reference in New Issue
Block a user