Make `Localize::CANONICAL_LOCALE` a function instead of associated constant

finchie
Jul 22, 2025, 1:21 AM
5I5NR4DQA6SGUUJXCDBGATRVT2US6HMCCRFJB2YF2YG7ZZKSZHKQC

Dependencies

  • [2] RUFPE6OO Include canonical locale in list of available locales
  • [3] QM64L3XO Replace `duplicate` macro with `macro_rules!`
  • [4] K3G4HK2J Track Fluent files using `include!`
  • [5] 3NMKD6I5 Refactor `Localize` trait to use `std::io::Write`
  • [6] UN2XEIEU Migrate from `locale_select` to `env_preferences`
  • [7] 7M4UI3TW Update dependencies to latest versions
  • [8] 73C6NOJ7 Fix minimal `Localize` implementation on errors
  • [9] BFL2Y7GN Add relative timestamps using `jiff` and `icu_relativetime`
  • [10] HHJDRLLN Create `fluent_embed_runtime` crate
  • [11] NFV26FRQ Improve glob error handling
  • [12] C6W7N6N5 Implement `Localize` for `FixedDecimal` and primitive number types
  • [13] JWZT34UC Add `Localize`` trait bound for each field in the derived item
  • [14] 7JPOCQEI Add explicit error handling for macro parsing
  • [15] CFJKYXUX Remove newtype wrapper `RelativeTime` for `jiff::Timestamp`
  • [16] LU6IFZFG Remove `std::io::Write` trait bound from `Localize`
  • [17] IRW6JACS Implement `Localize` for `RelativeTime`
  • [18] 4BMW4JJO Add support for deriving items with generics
  • [19] GJMBIJOE Migrate to latest env_preferences version
  • [20] QJC4IQIT Refactor `Localize` functions to infallibly return `String`
  • [21] NEBSVXIA Apply Clippy fixes
  • [22] WWDZWJTR Implement `Localize` for string types
  • [23] CESJ4CTO Move macro-specific code into `macro_impl` module
  • [24] 7U2DXFMP Refactor `fluent_embed::Localize` to support overriding locales
  • [25] QSK7JRBA Add simple `attribute_path` function
  • [*] XGNME3WR Move `Group::derive_enum` to new `crate::parse_macro` module
  • [*] O77KA6C4 Create `fluent_embed` crate

Change contents

  • replacement in fluent_embed_derive/src/macro_impl/mod.rs at line 62
    [4.391][4.391:454](),[4.454][4.579:628](),[4.628][4.530:604](),[4.530][4.530:604](),[4.604][4.629:680]()
    let attribute: syn::LitStr = syn::parse2(attribute_stream)
    .map_err(ParseError::InvalidAttribute)?;
    let derive_input: syn::DeriveInput = syn::parse2(derive_input_stream)
    .map_err(ParseError::InvalidDeriveInput)?;
    [4.391]
    [4.682]
    let attribute: syn::LitStr =
    syn::parse2(attribute_stream).map_err(ParseError::InvalidAttribute)?;
    let derive_input: syn::DeriveInput =
    syn::parse2(derive_input_stream).map_err(ParseError::InvalidDeriveInput)?;
  • replacement in fluent_embed_derive/src/macro_impl/mod.rs at line 171
    [4.282][4.97:254](),[4.788][4.97:254](),[4.3378][4.97:254](),[4.286][4.97:254]()
    const CANONICAL_LOCALE: ::fluent_embed::icu_locale::LanguageIdentifier =
    ::fluent_embed::icu_locale::langid!(#canonical_locale);
    [4.282]
    [4.1713]
    fn canonical_locale(&self) -> ::fluent_embed::icu_locale::LanguageIdentifier {
    ::fluent_embed::icu_locale::langid!(#canonical_locale)
    }
  • replacement in fluent_embed_derive/src/macro_impl/derive.rs at line 87
    [4.1776][2.0:89]()
    quote!(vec![Self::CANONICAL_LOCALE, #(::fluent_embed::langid!(#locale_literals)),*])
    [4.1776]
    [4.1841]
    quote!(vec![self.canonical_locale(), #(::fluent_embed::langid!(#locale_literals)),*])
  • replacement in fluent_embed_derive/src/lib.rs at line 46
    [4.405][4.2462:2641](),[4.2462][4.2462:2641]()
    const CANONICAL_LOCALE: ::fluent_embed::icu_locale::LanguageIdentifier =
    ::fluent_embed::icu_locale::langid!("en-US");
    [4.405]
    [4.574]
    fn canonical_locale(&self) -> ::fluent_embed::icu_locale::LanguageIdentifier {
    ::fluent_embed::icu_locale::langid!("en-US")
    }
  • replacement in fluent_embed/src/time.rs at line 7
    [4.221][4.1721:1767]()
    use icu_locale::{LanguageIdentifier, langid};
    [4.221]
    [4.1767]
    use icu_locale::LanguageIdentifier;
  • edit in fluent_embed/src/time.rs at line 16
    [4.52][4.3849:4061](),[4.507][4.3849:4061](),[4.3849][4.3849:4061](),[4.4061][4.508:545](),[4.545][4.4115:4121](),[4.4115][4.4115:4121](),[4.4121][4.124:125](),[4.124][4.124:125]()
    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::CANONICAL_LOCALE]
    }
  • replacement in fluent_embed/src/string.rs at line 6
    [4.170][4.1933:1979]()
    use icu_locale::{LanguageIdentifier, langid};
    [4.139]
    [4.215]
    use icu_locale::LanguageIdentifier;
  • edit in fluent_embed/src/string.rs at line 11
    [3.95][3.95:170](),[3.170][4.433:434](),[4.433][4.433:434](),[4.434][3.171:390](),[3.390][4.638:639](),[4.638][4.638:639]()
    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::CANONICAL_LOCALE]
    }
  • replacement in fluent_embed/src/lib.rs at line 18
    [4.730][4.4685:4752](),[4.4685][4.4685:4752](),[4.4752][4.427:475](),[4.427][4.427:475]()
    // TODO: this should be project-wide and tracked at build time
    const CANONICAL_LOCALE: LanguageIdentifier;
    [4.730]
    [4.511]
    fn message_for_locale(&self, locale: &LanguageIdentifier) -> String;
    fn canonical_locale(&self) -> LanguageIdentifier {
    langid!("en-US")
    }
  • replacement in fluent_embed/src/lib.rs at line 24
    [4.512][4.4753:4813](),[4.4813][4.2081:2154]()
    fn available_locales(&self) -> Vec<LanguageIdentifier>;
    fn message_for_locale(&self, locale: &LanguageIdentifier) -> String;
    [4.512]
    [4.4956]
    fn available_locales(&self) -> Vec<LanguageIdentifier> {
    // TODO: keep track of all locales with Fluent data, and return only those
    vec![self.canonical_locale()]
    }
  • replacement in fluent_embed/src/lib.rs at line 45
    [4.2219][4.2219:2316]()
    env_preferences::get_locales_lossy().unwrap_or(vec![Self::CANONICAL_LOCALE.into()]);
    [4.2219]
    [4.460]
    env_preferences::get_locales_lossy().unwrap_or(vec![self.canonical_locale().into()]);
  • replacement in fluent_embed/src/lib.rs at line 54
    [4.3683][4.3683:3742]()
    Self::CANONICAL_LOCALE.to_string().as_bytes(),
    [4.3683]
    [4.3742]
    self.canonical_locale().to_string().as_bytes(),
  • replacement in fluent_embed/src/decimal.rs at line 8
    [3.846][3.846:892]()
    use icu_locale::{LanguageIdentifier, langid};
    [3.846]
    [3.892]
    use icu_locale::LanguageIdentifier;
  • edit in fluent_embed/src/decimal.rs at line 13
    [3.991][3.991:1286](),[3.1286][4.2824:2825](),[4.4237][4.2824:2825](),[4.2824][4.2824:2825]()
    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::CANONICAL_LOCALE]
    }
  • edit in fluent_embed/src/decimal.rs at line 24
    [3.1614][3.1614:1689](),[3.1689][4.3830:3831](),[4.3830][4.3830:3831](),[4.3831][3.1690:1909](),[3.1909][4.4035:4036](),[4.4035][4.4035:4036]()
    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::CANONICAL_LOCALE]
    }
  • edit in fluent_embed/src/decimal.rs at line 50
    [4.1016][4.4348:4560](),[4.4988][4.4348:4560](),[4.4348][4.4348:4560](),[4.4560][4.1017:1054](),[4.1054][4.4614:4621](),[4.4614][4.4614:4621]()
    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::CANONICAL_LOCALE]
    }