Implement `Localize` for `std::path` and `camino`

finchie
Aug 13, 2025, 2:51 AM
AS7RDZT74V3SSWFSJYEGHT64QCEOFEZ46GUPF4ZAKEHTHBBNG7KQC

Dependencies

  • [2] RUCC2HKZ Rename from `fluent_embed` to `l10n_embed`
  • [3] USKESL6X Add examples for using common types in `l10n_embed`
  • [*] HHJDRLLN Create `fluent_embed_runtime` crate
  • [*] C6W7N6N5 Implement `Localize` for `FixedDecimal` and primitive number types
  • [*] WWDZWJTR Implement `Localize` for string types
  • [*] AE3AZFVK Add `Styled<L: Localize>` struct to support localizing colors
  • [*] 7M4UI3TW Update dependencies to latest versions
  • [*] UKFEFT6L Create basic `Output` proc-macro

Change contents

  • file addition: path.rs (----------)
    [5.49]
    use std::path::{Path, PathBuf};
    use crate::Localize;
    use camino::{Utf8Path, Utf8PathBuf};
    use icu_locale::Locale;
    macro_rules! impl_std_path {
    ($path_type:ty) => {
    impl Localize for $path_type {
    fn localize_for(&self, _locale: &Locale) -> String {
    self.to_string_lossy().to_string()
    }
    }
    };
    }
    macro_rules! impl_camino_path {
    ($path_type:ty) => {
    impl Localize for $path_type {
    fn localize_for(&self, _locale: &Locale) -> String {
    self.to_string()
    }
    }
    };
    }
    impl_std_path!(PathBuf);
    impl_std_path!(Path);
    impl_camino_path!(Utf8PathBuf);
    impl_camino_path!(Utf8Path);
  • edit in l10n_embed/src/lib.rs at line 2
    [6.2501]
    [7.859]
    pub mod path;
  • file addition: path.rs (----------)
    [3.20]
    //! Example showing how to localize paths
    use camino::Utf8PathBuf;
    use icu_locale::{Locale, locale};
    use l10n_embed::Localize;
    const DEFAULT_LOCALE: Locale = locale!("en-US");
    fn main() -> Result<(), std::io::Error> {
    // Create some paths
    let current_directory = std::env::current_dir()?;
    let current_directory_utf8 = Utf8PathBuf::from_path_buf(current_directory.clone()).unwrap();
    // Localize these paths, which just prints the path as a string (lossily if using std::path)
    println!(
    "Current directory: {}",
    current_directory.localize_for(&DEFAULT_LOCALE)
    );
    println!(
    "Current directory (UTF-8): {}",
    current_directory_utf8.localize_for(&DEFAULT_LOCALE)
    );
    Ok(())
    }
  • edit in l10n_embed/Cargo.toml at line 19
    [8.1337]
    [9.5209]
    camino.workspace = true
  • edit in Cargo.lock at line 736
    [2.2981]
    [2.3001]
    "camino",