50 lines
1.8 KiB
C#
50 lines
1.8 KiB
C#
using System.Text.Json;
|
|
using Ananta.Server.Configuration;
|
|
|
|
namespace Ananta.Server.ClientData.Client4229938;
|
|
|
|
/// <summary>
|
|
/// Chinese → English name mapping for the debug panel spawn lists. The tables are generated
|
|
/// by VaultTool/build_translation.py (word segmentation + single-char fallback) over the
|
|
/// AgentConfig / UrbanDiversityPOIActionConfig name columns; unknown names fall back to the
|
|
/// original string.
|
|
/// </summary>
|
|
internal static class NameTranslator
|
|
{
|
|
private static readonly Lazy<Dictionary<string, string>> Agents = new(() => Load("agent_names_en.json"));
|
|
private static readonly Lazy<Dictionary<string, string>> PoiActions = new(() => Load("poi_actions_en.json"));
|
|
|
|
public static string Agent(string? name)
|
|
=> Translate(Agents.Value, name);
|
|
|
|
public static string PoiAction(string? name)
|
|
=> Translate(PoiActions.Value, name);
|
|
|
|
private static string Translate(Dictionary<string, string> table, string? name)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(name))
|
|
return name ?? string.Empty;
|
|
return table.TryGetValue(name, out var en) && !string.IsNullOrWhiteSpace(en) ? en : name;
|
|
}
|
|
|
|
private static Dictionary<string, string> Load(string file)
|
|
{
|
|
try
|
|
{
|
|
var root = PrivateServerConfigStore.ResolveProjectPath(PrivateServerConfigStore.Current.Paths.ClientConfigs);
|
|
var path = Path.Combine(root, file);
|
|
if (!File.Exists(path))
|
|
return [];
|
|
using var doc = JsonDocument.Parse(File.ReadAllText(path));
|
|
var dict = new Dictionary<string, string>();
|
|
foreach (var p in doc.RootElement.EnumerateObject())
|
|
dict[p.Name] = p.Value.GetString() ?? string.Empty;
|
|
return dict;
|
|
}
|
|
catch
|
|
{
|
|
return [];
|
|
}
|
|
}
|
|
}
|