Skip to main content

ferrix_app/
i18n.rs

1/* i18n.rs
2 *
3 * Copyright 2025 Michail Krasnov <mskrasnov07@ya.ru>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: GPL-3.0-or-later
19 */
20
21//! Internationalization support
22
23use i18n_embed::{
24    DesktopLanguageRequester,
25    fluent::{FluentLanguageLoader, fluent_language_loader},
26};
27use lazy_static::lazy_static;
28use rust_embed::RustEmbed;
29
30#[derive(RustEmbed)]
31#[folder = "./i18n"]
32struct Locales;
33
34fn read() -> FluentLanguageLoader {
35    let ldr: FluentLanguageLoader = fluent_language_loader!();
36    let req_langs = DesktopLanguageRequester::requested_languages();
37    i18n_embed::select(&ldr, &Locales, &req_langs).unwrap();
38
39    ldr
40}
41
42lazy_static! {
43    pub static ref LANG_LDR: FluentLanguageLoader = read();
44}
45
46#[macro_export]
47macro_rules! fl {
48    ($message_id:literal) => {{
49        i18n_embed_fl::fl!($crate::i18n::LANG_LDR, $message_id)
50    }};
51
52    ($message_id:literal, $($args:expr),*) => {{
53        i18n_embed_fl::fl!($crate::i18n::LANG_LDR, $message_id, $($args), *)
54    }};
55}