From ac4617f5cfe73be3ebfe9223cfc574b9b7b38dd1 Mon Sep 17 00:00:00 2001 From: lincube Date: Tue, 17 Mar 2026 14:57:41 +0800 Subject: [PATCH] 0.6.4 --- LanMountainDesktop/App.axaml.cs | 2 ++ LanMountainDesktop/Localization/zh-CN.json | 4 +-- .../Services/LocalizationService.cs | 25 +++++++++++++++++-- .../Settings/SettingsWindowService.cs | 2 ++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/LanMountainDesktop/App.axaml.cs b/LanMountainDesktop/App.axaml.cs index 779ea45..4f3e62d 100644 --- a/LanMountainDesktop/App.axaml.cs +++ b/LanMountainDesktop/App.axaml.cs @@ -510,6 +510,8 @@ public partial class App : Application if (languageChanged) { + // 清除本地化缓存,强制重新加载语言文件 + _localizationService.ClearCache(); ApplyCurrentCultureFromSettings(); if (_trayIcons is not null) { diff --git a/LanMountainDesktop/Localization/zh-CN.json b/LanMountainDesktop/Localization/zh-CN.json index 811a6b5..085c7c1 100644 --- a/LanMountainDesktop/Localization/zh-CN.json +++ b/LanMountainDesktop/Localization/zh-CN.json @@ -892,6 +892,6 @@ "single_instance.notice.title": "应用已经运行", "single_instance.notice.description": "应用已经运行,无需多次点击打开。", "single_instance.notice.button": "确定", - "market.status.install_success_restart_format": "✓ 插件"{0}"安装成功!请重启应用以激活它。", - "market.dialog.restart_message_format": "插件"{0}"已成功安装。\n\n要使用此插件,您需要立即重启应用。\n\n是否立即重启?" + "market.status.install_success_restart_format": "✓ 插件'{0}'安装成功!请重启应用以激活它。", + "market.dialog.restart_message_format": "插件'{0}'已成功安装。\n\n要使用此插件,您需要立即重启应用。\n\n是否立即重启?" } diff --git a/LanMountainDesktop/Services/LocalizationService.cs b/LanMountainDesktop/Services/LocalizationService.cs index f46e7b7..239cab7 100644 --- a/LanMountainDesktop/Services/LocalizationService.cs +++ b/LanMountainDesktop/Services/LocalizationService.cs @@ -17,6 +17,23 @@ public sealed class LocalizationService private readonly Dictionary> _cache = new(StringComparer.OrdinalIgnoreCase); + /// + /// 清除指定语言代码的缓存,强制下次重新加载。 + /// 在语言切换时调用此方法以确保加载最新的语言文件。 + /// + public void ClearCache(string? languageCode = null) + { + if (string.IsNullOrWhiteSpace(languageCode)) + { + _cache.Clear(); + } + else + { + var normalizedCode = NormalizeLanguageCode(languageCode); + _cache.Remove(normalizedCode); + } + } + public string NormalizeLanguageCode(string? languageCode) { return string.Equals(languageCode, "en-US", StringComparison.OrdinalIgnoreCase) @@ -53,7 +70,7 @@ public sealed class LocalizationService { json = json.TrimStart('\uFEFF'); var data = JsonSerializer.Deserialize>(json, JsonOptions); - if (data is not null) + if (data is not null && data.Count > 0) { result = new Dictionary(data, StringComparer.OrdinalIgnoreCase); } @@ -64,7 +81,11 @@ public sealed class LocalizationService // Keep empty table for resilience. } - _cache[languageCode] = result; + // 只有当语言表非空时才缓存,这样如果加载失败可以下次重试 + if (result.Count > 0) + { + _cache[languageCode] = result; + } return result; } diff --git a/LanMountainDesktop/Services/Settings/SettingsWindowService.cs b/LanMountainDesktop/Services/Settings/SettingsWindowService.cs index f476e2b..271433e 100644 --- a/LanMountainDesktop/Services/Settings/SettingsWindowService.cs +++ b/LanMountainDesktop/Services/Settings/SettingsWindowService.cs @@ -294,6 +294,8 @@ internal sealed class SettingsWindowService : ISettingsWindowService if (languageChanged) { var regionState = _settingsFacade.Region.Get(); + // 清除本地化缓存,强制重新加载语言文件 + _localizationService.ClearCache(); _viewModel.RefreshLanguage(regionState.LanguageCode); _pageRegistry.Rebuild(); _window.ReloadPages(_viewModel.CurrentPageId);