- add: language

This commit is contained in:
2025-06-23 16:39:30 +03:00
parent 02e1a14571
commit 0a2fe55c7f
23 changed files with 246 additions and 81 deletions

View File

@@ -23,10 +23,10 @@ public partial class MainViewModel : ViewModelBase
{
private readonly List<ListItemTemplate> _templates =
[
new ListItemTemplate(typeof(AccountInfoViewModel), "user", "Account"),
new ListItemTemplate(typeof(ServerOverviewModel), "file", "Servers"),
new ListItemTemplate(typeof(ContentBrowserViewModel), "folder", "Content"),
new ListItemTemplate(typeof(ConfigurationViewModel), "settings", "Settings")
new ListItemTemplate(typeof(AccountInfoViewModel), "user", "tab-account"),
new ListItemTemplate(typeof(ServerOverviewModel), "file", "tab-servers"),
new ListItemTemplate(typeof(ContentBrowserViewModel), "folder", "tab-content"),
new ListItemTemplate(typeof(ConfigurationViewModel), "settings", "tab-settings")
];
private readonly List<PopupViewModelBase> _viewQueue = new();
@@ -41,6 +41,7 @@ public partial class MainViewModel : ViewModelBase
[ObservableProperty] private bool _popup;
[ObservableProperty] private ListItemTemplate? _selectedListItem;
[GenerateProperty] private LocalisationService LocalisationService { get; }
[GenerateProperty] private DebugService DebugService { get; } = default!;
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
[GenerateProperty] private ContentService ContentService { get; } = default!;
@@ -53,7 +54,11 @@ public partial class MainViewModel : ViewModelBase
protected override void InitialiseInDesignMode()
{
Items = new ObservableCollection<ListItemTemplate>(_templates);
Items = new ObservableCollection<ListItemTemplate>(_templates.Select(a=>
{
return new ListItemTemplate(a.ModelType, a.IconKey, LocalisationService.GetString(a.Label));
}
));
RequirePage<AccountInfoViewModel>();
}
@@ -76,7 +81,7 @@ public partial class MainViewModel : ViewModelBase
if (!VCRuntimeDllChecker.AreVCRuntimeDllsPresent())
{
OnPopupRequired("VC runtime dlls are not present on this computer. Install VC runtime dlls.");
OnPopupRequired(LocalisationService.GetString("vcruntime-check-error"));
Helper.OpenBrowser("https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170");
}
}
@@ -87,7 +92,7 @@ public partial class MainViewModel : ViewModelBase
return;
var loadingHandler = ViewHelperService.GetViewModel<LoadingContextViewModel>();
loadingHandler.LoadingName = "Migration task, please wait...";
loadingHandler.LoadingName = LocalisationService.GetString("migration-label-task");
loadingHandler.IsCancellable = false;
if (!ContentService.CheckMigration(loadingHandler))

View File

@@ -38,6 +38,7 @@ public partial class AccountInfoViewModel : ViewModelBase
[ObservableProperty] private bool _doRetryAuth;
private bool _isProfilesEmpty;
[GenerateProperty] private LocalisationService LocalisationService { get; }
[GenerateProperty] private PopupMessageService PopupMessageService { get; } = default!;
[GenerateProperty] private ConfigurationService ConfigurationService { get; } = default!;
[GenerateProperty] private DebugService DebugService { get; }
@@ -79,7 +80,7 @@ public partial class AccountInfoViewModel : ViewModelBase
public void DoAuth(string? code = null)
{
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
message.InfoText = "Auth think, please wait...";
message.InfoText = LocalisationService.GetString("auth-processing");
message.IsInfoClosable = false;
PopupMessageService.Popup(message);
@@ -102,7 +103,7 @@ public partial class AccountInfoViewModel : ViewModelBase
}
catch (Exception ex)
{
var unexpectedError = new Exception("An unexpected error occurred during authentication.", ex);
var unexpectedError = new Exception(LocalisationService.GetString("auth-error"), ex);
_logger.Error(unexpectedError);
PopupMessageService.Popup(unexpectedError);
}
@@ -112,7 +113,7 @@ public partial class AccountInfoViewModel : ViewModelBase
if (!IsLogged)
{
PopupMessageService.Popup(new Exception("No one of auth server is available.", exception));
PopupMessageService.Popup(exception ?? new Exception(LocalisationService.GetString("auth-error")));
}
});
}
@@ -156,7 +157,7 @@ public partial class AccountInfoViewModel : ViewModelBase
_logger.Log("TFA required");
break;
case AuthenticateDenyCode.InvalidCredentials:
PopupError("Invalid Credentials! Please, try another password or login!", e);
PopupError(LocalisationService.GetString("auth-invalid-credentials"), e);
break;
default:
throw;
@@ -168,17 +169,17 @@ public partial class AccountInfoViewModel : ViewModelBase
switch (e.HttpRequestError)
{
case HttpRequestError.ConnectionError:
PopupError("Failed to connect to the authentication server.", e);
PopupError(LocalisationService.GetString("auth-connection-error"), e);
DoRetryAuth = true;
break;
case HttpRequestError.NameResolutionError:
PopupError("Unable to resolve the server address.", e);
PopupError(LocalisationService.GetString("auth-name-resolution-error"), e);
DoRetryAuth = true;
break;
default:
var authError = new Exception("An error occurred during authentication.", e);
var authError = new Exception(LocalisationService.GetString("auth-error"), e);
_logger.Error(authError);
PopupMessageService.Popup(authError);
break;
@@ -223,10 +224,10 @@ public partial class AccountInfoViewModel : ViewModelBase
Accounts.Add(alpm);
}
private async Task ReadAuthConfig()
private void ReadAuthConfig()
{
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
message.InfoText = "Read configuration file, please wait...";
message.InfoText = LocalisationService.GetString("auth-config-read");
message.IsInfoClosable = false;
PopupMessageService.Popup(message);
foreach (var profile in
@@ -247,7 +248,7 @@ public partial class AccountInfoViewModel : ViewModelBase
public async void DoCurrentAuth()
{
var message = ViewHelperService.GetViewModel<InfoPopupViewModel>();
message.InfoText = "Trying to auth with saved data...";
message.InfoText = LocalisationService.GetString("auth-try-auth-config");
message.IsInfoClosable = false;
PopupMessageService.Popup(message);
@@ -261,7 +262,7 @@ public partial class AccountInfoViewModel : ViewModelBase
}
catch (Exception ex)
{
var unexpectedError = new Exception("An unexpected error occurred during authentication.", ex);
var unexpectedError = new Exception(LocalisationService.GetString("auth-error"), ex);
_logger.Error(unexpectedError);
PopupMessageService.Popup(unexpectedError);
return;
@@ -290,7 +291,7 @@ public partial class AccountInfoViewModel : ViewModelBase
private void PopupError(string message, Exception e)
{
message = "An error occurred during authentication: " + message;
message = LocalisationService.GetString("auth-error-occured") + message;
_logger.Error(new Exception(message, e));
var messageView = ViewHelperService.GetViewModel<InfoPopupViewModel>();

View File

@@ -200,7 +200,10 @@ public sealed class ArrayUnitConfigControl : Border, IConfigControl
{
private readonly List<IConfigControl> _itemControls = [];
private readonly StackPanel _itemsPanel = new StackPanel() { Orientation = Orientation.Vertical };
private readonly Button _addButton = new Button() { Content = "Add Item", Classes = { "ConfigBorder" }};
private readonly Button _addButton = new Button() { Content = new Label()
{
Content = "Add Item"
}, Classes = { "ConfigBorder" }};
private readonly int _oldCount;
private readonly Type _elementType;
private readonly StackPanel _panel = new();
@@ -232,7 +235,7 @@ public sealed class ArrayUnitConfigControl : Border, IConfigControl
{
var itemPanel = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 2 };
var control = ConfigControlHelper.GetConfigControl(_itemControls.Count.ToString(), value);
var removeButton = new Button { Content = "Remove", Classes = { "ConfigBorder" }};
var removeButton = new Button { Content = new Label(){ Content = "Remove" }, Classes = { "ConfigBorder" }};
removeButton.Click += (_, _) =>
{

View File

@@ -1,6 +1,7 @@
using System;
using CommunityToolkit.Mvvm.ComponentModel;
using Nebula.Launcher.ServerListProviders;
using Nebula.Launcher.Services;
using Nebula.Launcher.ViewModels.Pages;
using Nebula.Launcher.Views.Pages;
using Nebula.Shared.Services;
@@ -30,7 +31,7 @@ public partial class AddFavoriteViewModel : PopupViewModelBase
[GenerateProperty] private ServerOverviewModel ServerOverviewModel { get; }
[GenerateProperty] private DebugService DebugService { get; }
[GenerateProperty] private FavoriteServerListProvider FavoriteServerListProvider { get; }
public override string Title => "Add to favorite";
public override string Title => LocalisationService.GetString("popup-add-favorite");
public override bool IsClosable => true;
[ObservableProperty] private string _ipInput;

View File

@@ -1,4 +1,5 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Nebula.Launcher.Services;
using Nebula.Launcher.Views.Popup;
using Nebula.Shared.Services;
@@ -10,7 +11,7 @@ public sealed partial class EditServerNameViewModel : PopupViewModelBase
{
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
[GenerateProperty] public ConfigurationService ConfigurationService { get; }
public override string Title => "Edit server name";
public override string Title => LocalisationService.GetString("popup-edit-name");
public override bool IsClosable => true;
[ObservableProperty] private string _ipInput;

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.ObjectModel;
using Nebula.Launcher.Services;
using Nebula.Launcher.Views.Popup;
using Nebula.Shared.Services;
@@ -10,7 +11,7 @@ namespace Nebula.Launcher.ViewModels.Popup;
public sealed partial class ExceptionListViewModel : PopupViewModelBase
{
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
public override string Title => "Exception was thrown";
public override string Title => LocalisationService.GetString("popup-exception");
public override bool IsClosable => true;
public ObservableCollection<Exception> Errors { get; } = new();

View File

@@ -1,4 +1,5 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Nebula.Launcher.Services;
using Nebula.Launcher.Views.Popup;
using Nebula.Shared.Services;
@@ -12,7 +13,7 @@ public partial class InfoPopupViewModel : PopupViewModelBase
[ObservableProperty] private string _infoText = "Test";
public override string Title => "Info";
public override string Title => LocalisationService.GetString("popup-information");
public bool IsInfoClosable { get; set; } = true;
public override bool IsClosable => IsInfoClosable;

View File

@@ -1,4 +1,5 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Nebula.Launcher.Services;
using Nebula.Launcher.Views.Popup;
using Nebula.Shared.Models;
using Nebula.Shared.Services;
@@ -16,7 +17,7 @@ public sealed partial class LoadingContextViewModel : PopupViewModelBase, ILoadi
[ObservableProperty] private int _resolvedJobs;
public string LoadingName { get; set; } = "Loading...";
public string LoadingName { get; set; } = LocalisationService.GetString("popup-loading");
public bool IsCancellable { get; set; } = true;
public override bool IsClosable => false;

View File

@@ -1,4 +1,5 @@
using System;
using Nebula.Launcher.Services;
using Nebula.Launcher.Views.Popup;
using Nebula.Shared.Services;
@@ -24,6 +25,6 @@ public partial class TfaViewModel : PopupViewModelBase
}
[GenerateProperty] public override PopupMessageService PopupMessageService { get; }
public override string Title => "2fa";
public override string Title => LocalisationService.GetString("popup-twofa");
public override bool IsClosable => true;
}