From 45f222b4a077eb78615360cc2d49365267b12e5c Mon Sep 17 00:00:00 2001 From: Halit Can Date: Wed, 15 Jul 2026 17:48:54 +0300 Subject: [PATCH] feat(iced): add internationalization support --- hcie-iced-app/crates/hcie-iced-gui/src/app.rs | 4 + .../crates/hcie-iced-gui/src/i18n.rs | 86 +++++++++++++++++++ .../crates/hcie-iced-gui/src/main.rs | 1 + 3 files changed, 91 insertions(+) create mode 100644 hcie-iced-app/crates/hcie-iced-gui/src/i18n.rs diff --git a/hcie-iced-app/crates/hcie-iced-gui/src/app.rs b/hcie-iced-app/crates/hcie-iced-gui/src/app.rs index ce97a4b..81dc67a 100644 --- a/hcie-iced-app/crates/hcie-iced-gui/src/app.rs +++ b/hcie-iced-app/crates/hcie-iced-gui/src/app.rs @@ -14,6 +14,7 @@ use crate::ai_chat::{self, AiChatState, ChatMessage, SYSTEM_PROMPT}; use crate::dialogs; +use crate::i18n; use crate::dock::state::{DockState, PaneType}; use crate::io::tablet::TabletState; use crate::panels; @@ -191,6 +192,8 @@ pub struct HcieIcedApp { pub dock_profile_rename_buf: String, /// Whether the dock profile dialog is visible. pub show_dock_profile_dialog: bool, + /// Current UI language for internationalization. + pub language: i18n::Language, } /// A recently opened file entry. @@ -745,6 +748,7 @@ impl HcieIcedApp { dock_profile_rename_idx: None, dock_profile_rename_buf: String::new(), show_dock_profile_dialog: false, + language: i18n::Language::default(), }; // Apply saved settings to tool state diff --git a/hcie-iced-app/crates/hcie-iced-gui/src/i18n.rs b/hcie-iced-app/crates/hcie-iced-gui/src/i18n.rs new file mode 100644 index 0000000..52e08be --- /dev/null +++ b/hcie-iced-app/crates/hcie-iced-gui/src/i18n.rs @@ -0,0 +1,86 @@ +//! Internationalization (i18n) support for the HCIE Iced GUI. +//! +//! Provides translation keys for UI strings with English and Turkish locales. +//! The `t()` function returns a `&'static str` for the given language and key, +//! enabling zero-cost string lookups at render time. + +use serde::{Deserialize, Serialize}; + +/// Supported UI languages. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)] +pub enum Language { + #[default] + English, + Turkish, +} + +/// Translation keys for menu items and common UI strings. +#[allow(dead_code)] +pub enum TranslationKey { + File, + Edit, + Image, + Layer, + Filter, + Select, + View, + Window, + Help, + Tools, + New, + Open, + Save, + Export, + Quit, + Undo, + Redo, + Settings, +} + +/// Returns the translated string for the given language and key. +/// +/// Uses match arms to return `&'static str` — no allocations at call site. +pub fn t(lang: Language, key: TranslationKey) -> &'static str { + match lang { + Language::Turkish => match key { + TranslationKey::File => "Dosya", + TranslationKey::Edit => "Düzen", + TranslationKey::Image => "Görüntü", + TranslationKey::Layer => "Katman", + TranslationKey::Filter => "Filtre", + TranslationKey::Select => "Seç", + TranslationKey::View => "Görünüm", + TranslationKey::Window => "Pencere", + TranslationKey::Help => "Yardım", + TranslationKey::Tools => "Araçlar", + TranslationKey::New => "Yeni...", + TranslationKey::Open => "Aç...", + TranslationKey::Save => "Kaydet", + TranslationKey::Export => "Dışa Aktar...", + TranslationKey::Quit => "Çıkış", + TranslationKey::Undo => "Geri Al", + TranslationKey::Redo => "İleri Al", + TranslationKey::Settings => "Ayarlar", + }, + Language::English => match key { + TranslationKey::File => "File", + TranslationKey::Edit => "Edit", + TranslationKey::Image => "Image", + TranslationKey::Layer => "Layer", + TranslationKey::Filter => "Filter", + TranslationKey::Select => "Select", + TranslationKey::View => "View", + TranslationKey::Window => "Window", + TranslationKey::Help => "Help", + TranslationKey::Tools => "Tools", + TranslationKey::New => "New...", + TranslationKey::Open => "Open...", + TranslationKey::Save => "Save", + TranslationKey::Export => "Export...", + TranslationKey::Quit => "Quit", + TranslationKey::Undo => "Undo", + TranslationKey::Redo => "Redo", + TranslationKey::Settings => "Settings", + }, + } +} diff --git a/hcie-iced-app/crates/hcie-iced-gui/src/main.rs b/hcie-iced-app/crates/hcie-iced-gui/src/main.rs index 219f43c..4be9d1a 100644 --- a/hcie-iced-app/crates/hcie-iced-gui/src/main.rs +++ b/hcie-iced-app/crates/hcie-iced-gui/src/main.rs @@ -10,6 +10,7 @@ mod canvas; mod color_picker; mod dialogs; mod dock; +mod i18n; mod io; mod panels; mod script;