mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-20 23:54:26 +08:00
0.6.4
This commit is contained in:
@@ -510,6 +510,8 @@ public partial class App : Application
|
||||
|
||||
if (languageChanged)
|
||||
{
|
||||
// 清除本地化缓存,强制重新加载语言文件
|
||||
_localizationService.ClearCache();
|
||||
ApplyCurrentCultureFromSettings();
|
||||
if (_trayIcons is not null)
|
||||
{
|
||||
|
||||
@@ -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是否立即重启?"
|
||||
}
|
||||
|
||||
@@ -17,6 +17,23 @@ public sealed class LocalizationService
|
||||
private readonly Dictionary<string, Dictionary<string, string>> _cache =
|
||||
new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>
|
||||
/// 清除指定语言代码的缓存,强制下次重新加载。
|
||||
/// 在语言切换时调用此方法以确保加载最新的语言文件。
|
||||
/// </summary>
|
||||
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<Dictionary<string, string>>(json, JsonOptions);
|
||||
if (data is not null)
|
||||
if (data is not null && data.Count > 0)
|
||||
{
|
||||
result = new Dictionary<string, string>(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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user