mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 00:39:00 +08:00
- 清理 GFramework.Core 与 GFramework.Cqrs 中的大量低风险 Meziantou 警告 - 修复 GFramework.Godot 运行时中的 ConfigureAwait、StringComparison 与参数校验告警 - 调整 Core SourceGenerators 中的字符串比较、文件命名与局部长方法问题 - 拆分部分配置与缓存辅助类型文件以消除 file/type mismatch 告警 - 更新 warning reduction 跟踪与执行记录,保留下一批结构性告警的恢复点
72 lines
2.4 KiB
C#
72 lines
2.4 KiB
C#
// Copyright (c) 2026 GeWuYou
|
||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||
// you may not use this file except in compliance with the License.
|
||
// You may obtain a copy of the License at
|
||
//
|
||
// http://www.apache.org/licenses/LICENSE-2.0
|
||
//
|
||
// Unless required by applicable law or agreed to in writing, software
|
||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
// See the License for the specific language governing permissions and
|
||
// limitations under the License.
|
||
|
||
namespace GFramework.Godot.Setting.Data;
|
||
|
||
/// <summary>
|
||
/// 本地化映射设置
|
||
/// </summary>
|
||
public class LocalizationMap
|
||
{
|
||
private const string DefaultFrameworkLanguage = "eng";
|
||
private const string DefaultGodotLocale = "en";
|
||
|
||
/// <summary>
|
||
/// 用户语言 -> Godot locale 映射表。
|
||
/// </summary>
|
||
public Dictionary<string, string> LanguageMap { get; set; } = new(StringComparer.Ordinal)
|
||
{
|
||
{ "简体中文", "zh_CN" },
|
||
{ "English", "en" }
|
||
};
|
||
|
||
/// <summary>
|
||
/// 用户语言 -> GFramework 本地化语言码映射表。
|
||
/// </summary>
|
||
public Dictionary<string, string> FrameworkLanguageMap { get; set; } = new(StringComparer.Ordinal)
|
||
{
|
||
{ "简体中文", "zhs" },
|
||
{ "English", "eng" }
|
||
};
|
||
|
||
/// <summary>
|
||
/// 解析用户保存的语言值对应的 Godot locale。
|
||
/// </summary>
|
||
/// <param name="storedLanguage">设置系统中保存的语言值。</param>
|
||
/// <returns>对应的 Godot locale;未知值时回退为英文。</returns>
|
||
public string ResolveGodotLocale(string? storedLanguage)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(storedLanguage))
|
||
{
|
||
return DefaultGodotLocale;
|
||
}
|
||
|
||
return LanguageMap.GetValueOrDefault(storedLanguage, DefaultGodotLocale);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 解析用户保存的语言值对应的框架语言码。
|
||
/// </summary>
|
||
/// <param name="storedLanguage">设置系统中保存的语言值。</param>
|
||
/// <returns>对应的框架语言码;未知值时回退为英文。</returns>
|
||
public string ResolveFrameworkLanguage(string? storedLanguage)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(storedLanguage))
|
||
{
|
||
return DefaultFrameworkLanguage;
|
||
}
|
||
|
||
return FrameworkLanguageMap.GetValueOrDefault(storedLanguage, DefaultFrameworkLanguage);
|
||
}
|
||
}
|