- add: Localisation - start
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
|
||||
0
Nebula.Launcher/Assets/lang/en-US.ftl
Normal file
0
Nebula.Launcher/Assets/lang/en-US.ftl
Normal file
0
Nebula.Launcher/Assets/lang/ru-RU.ftl
Normal file
0
Nebula.Launcher/Assets/lang/ru-RU.ftl
Normal file
@@ -17,4 +17,6 @@ public static class LauncherConVar
|
||||
public static readonly ConVar<string[]> AuthServers = ConVarBuilder.Build<string[]>("launcher.authServers", [
|
||||
"https://auth.spacestation14.com/"
|
||||
]);
|
||||
|
||||
public static readonly ConVar<string> CurrentLang = ConVarBuilder.Build<string>("launcher.language", "en-US");
|
||||
}
|
||||
@@ -26,6 +26,7 @@
|
||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.1"/>
|
||||
<PackageReference Include="Fluent.Net" Version="1.0.63" />
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0"/>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0"/>
|
||||
<PackageReference Include="libsodium" Version="1.0.20"/>
|
||||
|
||||
45
Nebula.Launcher/Services/LocalisationService.cs
Normal file
45
Nebula.Launcher/Services/LocalisationService.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using Avalonia.Platform;
|
||||
using Fluent.Net;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Launcher.Services;
|
||||
|
||||
[ConstructGenerator, ServiceRegister]
|
||||
public partial class LocalisationService
|
||||
{
|
||||
[GenerateProperty] private ConfigurationService ConfigurationService { get; }
|
||||
|
||||
private CultureInfo _currentCultureInfo = CultureInfo.CurrentCulture;
|
||||
private MessageContext _currentMessageContext;
|
||||
|
||||
private void Initialise()
|
||||
{
|
||||
// LoadLanguage(CultureInfo.GetCultureInfo(ConfigurationService.GetConfigValue(LauncherConVar.CurrentLang)!));
|
||||
}
|
||||
|
||||
public void LoadLanguage(CultureInfo cultureInfo)
|
||||
{
|
||||
_currentCultureInfo = cultureInfo;
|
||||
using var fs = AssetLoader.Open(new Uri($@"Assets/lang/{_currentCultureInfo.EnglishName}.ftl"));
|
||||
using var sr = new StreamReader(fs);
|
||||
|
||||
var options = new MessageContextOptions { UseIsolating = false };
|
||||
var mc = new MessageContext(cultureInfo.EnglishName, options);
|
||||
var errors = mc.AddMessages(sr);
|
||||
foreach (var error in errors)
|
||||
{
|
||||
Console.WriteLine(error);
|
||||
}
|
||||
|
||||
_currentMessageContext = mc;
|
||||
}
|
||||
|
||||
private void InitialiseInDesignMode()
|
||||
{
|
||||
Initialise();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user