aboutsummaryrefslogtreecommitdiff
path: root/src/i18n.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/i18n.rs')
-rw-r--r--src/i18n.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/i18n.rs b/src/i18n.rs
new file mode 100644
index 0000000..1c574e0
--- /dev/null
+++ b/src/i18n.rs
@@ -0,0 +1,61 @@
+// Map, wardley map editor for linux
+// Copyright (C) 2026 Rubén Beltrán del Río
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+//! Internationalization support using gettext.
+
+use gettextrs::{bindtextdomain, setlocale, textdomain, LocaleCategory};
+
+/// The gettext domain for the application.
+pub const GETTEXT_DOMAIN: &str = "systems.tranquil.Map";
+
+/// Initializes the localization system.
+pub fn init() {
+ setlocale(LocaleCategory::LcAll, "");
+
+ // Try standard locations for locale files
+ let locale_dirs = [
+ // Development: local po directory
+ concat!(env!("CARGO_MANIFEST_DIR"), "/po"),
+ // Flatpak
+ "/app/share/locale",
+ // System-wide installation
+ "/usr/share/locale",
+ "/usr/local/share/locale",
+ ];
+
+ for dir in &locale_dirs {
+ if std::path::Path::new(dir).exists() {
+ let _ = bindtextdomain(GETTEXT_DOMAIN, *dir);
+ break;
+ }
+ }
+
+ textdomain(GETTEXT_DOMAIN).expect("Failed to set gettext domain");
+}
+
+/// Macro for translating strings at runtime.
+///
+/// Usage:
+/// ```ignore
+/// use crate::i18n::tr;
+/// let translated = tr!("Hello, world!");
+/// ```
+#[macro_export]
+macro_rules! tr {
+ ($msgid:expr) => {
+ gettextrs::gettext($msgid)
+ };
+}