// 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 . //! Internationalization support using gettext. use crate::info; use gettextrs::{LocaleCategory, bindtextdomain, setlocale, textdomain}; /// 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(info::GETTEXT_DOMAIN, *dir); break; } } textdomain(info::GETTEXT_DOMAIN).ok(); } /// 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) }; }