// 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 { /// Pseudo-code meaning "let the provider detect the source language". public const string Auto = "auto"; /// Codes in display order; index-aligned with . 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; } /// True when the code is in the list (auto only counts when ). public static bool IsKnown(string? code, bool allowAuto) { int i = IndexOf(code); return i > 0 || (i == 0 && allowAuto); } /// Canonical spelling of a known code (e.g. "ZH-cn" → "zh-CN"); null when unknown. public static string? Normalize(string? code) { int i = IndexOf(code); return i < 0 ? null : Codes[i]; } /// "Spanish (es)" for UI and chat feedback; unknown codes are shown as-is. public static string Label(string? code) { int i = IndexOf(code); return i < 0 ? (code ?? string.Empty) : i == 0 ? Names[0] : $"{Names[i]} ({Codes[i]})"; } /// Base language of a code ("zh-CN" → "zh"), lower-case, for same-language checks. 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; } /// /// ImGui language picker. Returns true when the selection changed. Render thread only. /// 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; } }