noctua/src/i18n.rs
wfx 9399a008c4 refactor: improve code quality and consistency
Comprehensive code audit addressing naming consistency, dead code removal,
and documentation improvements across the entire codebase.

- Rename panel_pages.rs → pages_panel.rs for consistent naming
- Unify view functions: all panels now use view() convention
- Rename header_start/end() → start/end() for brevity
- Update all imports and references

- Remove Rotation::from_degrees() (only 4 fixed states needed)
- Remove TransformState::identity() and is_identity() (Default suffices)
- Remove duplicate convenience methods from RasterDocument, VectorDocument,
  PortableDocument (rotate_cw/ccw, flip_horizontal/vertical)
- Remove unused imports and constants (ROTATION_STEP, FULL_ROTATION)

- Rename constants: PDF_RENDER_SCALE → PDF_RENDER_QUALITY,
  PDF_THUMBNAIL_SCALE → PDF_THUMBNAIL_SIZE
- Add comprehensive trait documentation explaining type erasure pattern
- Document why large enum variants are acceptable
- Add #[allow(dead_code)] with explanations for trait API types
- Improve all constant and config comments

- Collapse nested if statements using Rust 2024 let-chains
- Replace single-arm match with if-let
- Introduce StateChangeCallback<Message> type alias
- Apply clippy auto-fixes for better code style
2026-01-19 19:42:54 +01:00

55 lines
1.6 KiB
Rust

// SPDX-License-Identifier: GPL-3.0-or-later
// src/i18n.rs
//
// Internationalization (i18n) support.
use i18n_embed::{
DefaultLocalizer, LanguageLoader, Localizer,
fluent::{FluentLanguageLoader, fluent_language_loader},
unic_langid::LanguageIdentifier,
};
use rust_embed::RustEmbed;
use std::sync::LazyLock;
/// Applies the requested language(s) to requested translations from the `fl!()` macro.
pub fn init(requested_languages: &[LanguageIdentifier]) {
if let Err(why) = localizer().select(requested_languages) {
println!("error while loading fluent localizations: {why}");
}
}
// Get the `Localizer` to be used for localizing this library.
#[must_use]
pub fn localizer() -> Box<dyn Localizer> {
Box::from(DefaultLocalizer::new(&*LANGUAGE_LOADER, &Localizations))
}
#[derive(RustEmbed)]
#[folder = "i18n/"]
struct Localizations;
pub static LANGUAGE_LOADER: LazyLock<FluentLanguageLoader> = LazyLock::new(|| {
let loader: FluentLanguageLoader = fluent_language_loader!();
loader
.load_fallback_language(&Localizations)
.expect("Error while loading fallback language");
loader
});
/// Request a localized string by ID from the i18n/ directory.
#[macro_export]
macro_rules! fl {
($message_id:literal) => {{
i18n_embed_fl::fl!($crate::i18n::LANGUAGE_LOADER, $message_id)
}};
($message_id:literal, $($name:ident: $value:expr),*) => {{
let mut args = std::collections::HashMap::new();
$(
args.insert(stringify!($name), $value.to_string());
)*
i18n_embed_fl::fl!($crate::i18n::LANGUAGE_LOADER, $message_id, args)
}};
}