Implement `Localize` for string types

finchie
Aug 27, 2024, 7:15 AM
WWDZWJTRJWSLVFMQFHS7JMDPK5VNDIQ6IHSMES7BVKYHZY6WRYKAC

Dependencies

  • [2] C6W7N6N5 Implement `Localize` for `FixedDecimal` and primitive number types
  • [*] HHJDRLLN Create `fluent_embed_runtime` crate
  • [*] BFL2Y7GN Add relative timestamps using `jiff` and `icu_relativetime`

Change contents

  • file addition: string.rs (----------)
    [4.49]
    //! Implementations of `Localize` for various string types
    use crate::Localize;
    use std::borrow::Cow;
    use duplicate::duplicate_item;
    use icu_locid::{langid, LanguageIdentifier};
    #[duplicate_item(
    type_name;
    [String];
    [&str];
    [Box<str>];
    [Cow<'_, str>];
    )]
    impl<W: std::io::Write> Localize<W> for type_name {
    const CANONICAL_LOCALE: LanguageIdentifier = langid!("en-US");
    fn available_locales(&self) -> Vec<LanguageIdentifier> {
    // TODO: keep track of all locales with Fluent data, and return only those
    vec![<Self as Localize<W>>::CANONICAL_LOCALE]
    }
    fn message_for_locale(
    &self,
    writer: &mut W,
    _locale: &LanguageIdentifier,
    ) -> Result<(), crate::LocalizationError> {
    writer.write_all(self.as_bytes())?;
    Ok(())
    }
    }
  • edit in fluent_embed/src/lib.rs at line 15
    [2.2501]
    [5.4362]
    pub mod string;