RynthSuite/Plugins/RynthCore.Plugin.RynthAi/Translate/TranslateLanguages.cs
BlankenshipG 09b14d4ed1 feat(rynthai): ILT Hub, HUDs, item info, chat translation, ground loot and nav editing
- ILT Hub (overlay window, /ra hub): character progression, pets, quests,
  gear, banking, guardian, buff keepers, session rates, USD import.
- Floating HUDs: combat tracker, item count HUD, Mini Remote (/ra remote,
  /ra huds).
- Item info (Mag-style describer) on select, with its own settings window.
- Chat translation (/ra translate) for chosen channels.
- Ground loot: loose items matching the loot profile are picked up when no
  corpse is in range (CorpseOpenController).
- Nav: breadcrumb recorder, route overlay, and the route editor commands
  the engine Nav panel sends (multi-select move/duplicate/delete, reverse,
  snap to path, pauses, portals, simplify, trail -> route).
- Pets: refill-loop guard for essences the server just confirmed full;
  optional ILT Hub hooks (summon on empty, hold, yield a cosmetic pet).
- QuestTracker: quiet refreshes, Disabled / LastStatus for the hub.
- WorldObjectCache: typed items (keys, gems, comps, food) are placed in
  inventory or landscape by ownership instead of staying Unknown.
- Install-aware data folders (RynthInstallPaths) and a per-category
  diagnostics log (Diagnostics/RynthLog, diagnostics.json).
- Monster Editor: VirindiTank USD import and "Import UB damage insights"
  (ub-mob-seed.json); RynthAi loads the seed (UbMobSeedStore).

Kept as on rynth/main: combat (ammo, off-hand/shield rules), AutoStack in
InventoryManager, LegacyAdvancedSettingsUi and the version stamping. No
host API slots are used; new engine data comes from optional exports
(RynthPluginRenderOverlay, RynthPluginGetProgressionJson,
RynthPluginGetCharmsJson).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-05 16:52:13 -04:00

92 lines
3.7 KiB
C#

// TranslateLanguages.cs — Language codes offered by the chat translator (ISO 639-1 / Google style).
// Providers that use other codes (DeepL upper-case, LibreTranslate "zh") are mapped in TranslateClient.
using System;
using ImGuiNET;
namespace RynthCore.Plugin.RynthAi.Translate;
internal static class TranslateLanguages
{
/// <summary>Pseudo-code meaning "let the provider detect the source language".</summary>
public const string Auto = "auto";
/// <summary>Codes in display order; index-aligned with <see cref="Names"/>.</summary>
public static readonly string[] Codes =
{
Auto, "en", "es", "fr", "de", "it", "pt", "nl", "sv", "no", "da", "fi", "pl", "cs", "hu",
"ro", "el", "tr", "ru", "uk", "ar", "he", "hi", "th", "vi", "id", "ja", "ko", "zh-CN", "zh-TW",
};
public static readonly string[] Names =
{
"Auto-detect", "English", "Spanish", "French", "German", "Italian", "Portuguese", "Dutch", "Swedish",
"Norwegian", "Danish", "Finnish", "Polish", "Czech", "Hungarian", "Romanian", "Greek", "Turkish",
"Russian", "Ukrainian", "Arabic", "Hebrew", "Hindi", "Thai", "Vietnamese", "Indonesian", "Japanese",
"Korean", "Chinese (Simplified)", "Chinese (Traditional)",
};
public static int IndexOf(string? code)
{
if (string.IsNullOrWhiteSpace(code)) return -1;
for (int i = 0; i < Codes.Length; i++)
if (string.Equals(Codes[i], code.Trim(), StringComparison.OrdinalIgnoreCase)) return i;
return -1;
}
/// <summary>True when the code is in the list (auto only counts when <paramref name="allowAuto"/>).</summary>
public static bool IsKnown(string? code, bool allowAuto)
{
int i = IndexOf(code);
return i > 0 || (i == 0 && allowAuto);
}
/// <summary>Canonical spelling of a known code (e.g. "ZH-cn" → "zh-CN"); null when unknown.</summary>
public static string? Normalize(string? code)
{
int i = IndexOf(code);
return i < 0 ? null : Codes[i];
}
/// <summary>"Spanish (es)" for UI and chat feedback; unknown codes are shown as-is.</summary>
public static string Label(string? code)
{
int i = IndexOf(code);
return i < 0 ? (code ?? string.Empty) : i == 0 ? Names[0] : $"{Names[i]} ({Codes[i]})";
}
/// <summary>Base language of a code ("zh-CN" → "zh"), lower-case, for same-language checks.</summary>
public static string BaseOf(string? code)
{
if (string.IsNullOrWhiteSpace(code)) return string.Empty;
string c = code.Trim().ToLowerInvariant();
int dash = c.IndexOf('-');
return dash > 0 ? c.Substring(0, dash) : c;
}
/// <summary>
/// ImGui language picker. Returns true when the selection changed. Render thread only.
/// </summary>
public static bool Combo(string label, ref string code, bool allowAuto, float width = 0f)
{
bool changed = false;
if (width > 0f) ImGui.SetNextItemWidth(width);
int current = IndexOf(code);
string preview = current < 0 ? code : current == 0 ? Names[0] : Codes[current];
if (ImGui.BeginCombo(label, preview, ImGuiComboFlags.HeightLarge))
{
for (int i = allowAuto ? 0 : 1; i < Codes.Length; i++)
{
bool selected = i == current;
if (ImGui.Selectable(i == 0 ? Names[0] : $"{Codes[i]} {Names[i]}", selected))
{
code = Codes[i];
changed = true;
}
if (selected) ImGui.SetItemDefaultFocus();
}
ImGui.EndCombo();
}
if (ImGui.IsItemHovered() && current > 0) ImGui.SetTooltip(Names[current]);
return changed;
}
}