Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/MetahookInstallerAvalonia/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,33 @@
using System;
using System.Globalization;
using System.IO;
using System.Linq;

namespace MetahookInstallerAvalonia;

public partial class App : Application
{
// Ursa only ships en-US / fr-FR / zh-CN locale resources. Map the effective
// culture onto one of those: Chinese keeps zh-CN, French keeps fr-FR, and
// everything else (including the "no lang file" fallback) uses en-US so the
// built-in control strings start out in English rather than Ursa's zh-CN default.
private static string NormalizeUrsaLocale(string? lang)
{
if (string.IsNullOrEmpty(lang))
{
return "en-US";
}
if (lang.StartsWith("zh", StringComparison.OrdinalIgnoreCase))
{
return "zh-CN";
}
if (lang.StartsWith("fr", StringComparison.OrdinalIgnoreCase))
{
return "fr-FR";
}
return "en-US";
}

public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
Expand All @@ -20,11 +42,21 @@ public override void Initialize()
public override void OnFrameworkInitializationCompleted()
{
var settingPath = Path.Combine(".", "lang");
if (File.Exists(settingPath))
string? lang = File.Exists(settingPath) ? File.ReadAllText(settingPath).Trim() : null;
if (!string.IsNullOrEmpty(lang))
{
string lang = File.ReadAllText(settingPath);
Lang.Resources.Culture = new CultureInfo(lang);
}

// Keep Ursa's built-in control strings (PopConfirm / MessageBox buttons,
// etc.) in sync with the installer language. Without this the theme keeps
// its zh-CN default and shows Chinese buttons in English mode.
var ursaTheme = Styles.OfType<Ursa.Themes.Semi.SemiTheme>().FirstOrDefault();
if (ursaTheme != null)
{
ursaTheme.Locale = new CultureInfo(NormalizeUrsaLocale(lang));
}

var themePath = Path.Combine(".", "theme");
if (File.Exists(themePath))
{
Expand Down
20 changes: 10 additions & 10 deletions src/MetahookInstallerAvalonia/Lang/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,19 @@
<value>Critical Error</value>
</data>
<data name="BuildDirectoryNotFound" xml:space="preserve">
<value>The install/output folder cannot be located next to MetahookInstaller.exe. Please extract the complete archive before running the programme.</value>
<value>The install/output folder cannot be located next to MetahookInstaller.exe. Please extract the complete archive before running the program.</value>
</data>
<data name="InvalidInstallPath" xml:space="preserve">
<value>Invalid instal target.</value>
<value>Invalid install target.</value>
</data>
<data name="FileNotFound" xml:space="preserve">
<value>Could not found {0}.</value>
<value>Could not find {0}.</value>
</data>
<data name="Warning" xml:space="preserve">
<value>Warning</value>
</data>
<data name="DeleteFailed" xml:space="preserve">
<value>Failed when deleting {0}. Error message {1}.</value>
<value>Failed to delete {0}. Error message: {1}.</value>
</data>
<data name="Success" xml:space="preserve">
<value>Success!</value>
Expand All @@ -190,13 +190,13 @@
<value>Uninstall finished.</value>
</data>
<data name="SelectFirst" xml:space="preserve">
<value>Please install mod first.</value>
<value>Please install the mod first.</value>
</data>
<data name="InstallDone" xml:space="preserve">
<value>Install Mod finished!</value>
<value>Mod installed successfully!</value>
</data>
<data name="ResetDone" xml:space="preserve">
<value>Reset finished</value>
<value>Reset finished.</value>
</data>
<data name="SaveDone" xml:space="preserve">
<value>Saved.</value>
Expand All @@ -208,13 +208,13 @@
<value>中文</value>
</data>
<data name="ConfirmTitle" xml:space="preserve">
<value>Confirmed to apply modification?</value>
<value>Apply this change?</value>
</data>
<data name="ConfirmInstall" xml:space="preserve">
<value>Installing the new file will replace the original file, and this operation cannot be reversed.</value>
<value>Installing the new files will replace the original files. This action cannot be undone.</value>
</data>
<data name="ConfirmUninstall" xml:space="preserve">
<value>Uninstalling will remove all Metahook-related files, including the metahook folder, and this action cannot be reversed.</value>
<value>Uninstalling will remove all Metahook-related files, including the metahook folder. This action cannot be undone.</value>
</data>
<data name="Cancelled" xml:space="preserve">
<value>Cancelled</value>
Expand Down
Loading