// 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; /// /// 本地化映射设置 /// public class LocalizationMap { private const string DefaultFrameworkLanguage = "eng"; private const string DefaultGodotLocale = "en"; /// /// 用户语言 -> Godot locale 映射表。 /// public Dictionary LanguageMap { get; set; } = new(StringComparer.Ordinal) { { "简体中文", "zh_CN" }, { "English", "en" } }; /// /// 用户语言 -> GFramework 本地化语言码映射表。 /// public Dictionary FrameworkLanguageMap { get; set; } = new(StringComparer.Ordinal) { { "简体中文", "zhs" }, { "English", "eng" } }; /// /// 解析用户保存的语言值对应的 Godot locale。 /// /// 设置系统中保存的语言值。 /// 对应的 Godot locale;未知值时回退为英文。 public string ResolveGodotLocale(string? storedLanguage) { if (string.IsNullOrWhiteSpace(storedLanguage)) { return DefaultGodotLocale; } return LanguageMap.GetValueOrDefault(storedLanguage, DefaultGodotLocale); } /// /// 解析用户保存的语言值对应的框架语言码。 /// /// 设置系统中保存的语言值。 /// 对应的框架语言码;未知值时回退为英文。 public string ResolveFrameworkLanguage(string? storedLanguage) { if (string.IsNullOrWhiteSpace(storedLanguage)) { return DefaultFrameworkLanguage; } return FrameworkLanguageMap.GetValueOrDefault(storedLanguage, DefaultFrameworkLanguage); } }