Create `fluent_embed_runtime` crate

finchie
Jul 12, 2024, 5:12 AM
HHJDRLLNN36UNIA7STAXEEVBCEMPJNB7SJQOS3TJLLYN4AEZ4MHQC

Dependencies

  • [2] QFPQZR4K Refactor `fluent_embed`
  • [3] O77KA6C4 Create `fluent_embed` crate
  • [4] VZYZRAO4 Move `output-macros` crate into workspace
  • [5] BANMRGRO Switch `wax` to temporary fork
  • [6] V5S5K33A Add basic error handling for invalid paths in proc_macro attribute
  • [7] SHNZZSZG Create `cli_macros` shim crate
  • [8] XGNME3WR Move `Group::derive_enum` to new `crate::parse_macro` module
  • [9] WBI5HFOB Add simple wrapper for `libc::settext()` to query system locale
  • [10] VNSHGQYN Support using glob paths in `localize` macro
  • [11] F5LG7WEN Emit compilation errors from Fluent source code
  • [12] NO3PDO7P Refactor `fluent_embed` to support structs
  • [13] 4MRF5E76 Generate simple locale matching code in `localize()`
  • [14] YNEOCYMG Create `locale-select` crate
  • [15] P6FW2GGO Remove unnecessary parameters in generated `localize()` function
  • [*] KDUI7LHJ
  • [*] 5TEX4MNU Split `fluent_embed` into `group` and `parse` modules
  • [*] XEEXWJLG Add simple end-to-end test for selectors
  • [*] UKFEFT6L Create basic `Output` proc-macro
  • [*] JZXXFWQK Add tests for `locale_select` backends on unix

Change contents

  • file addition: fluent_embed_runtime (d--r------)
    [17.1]
  • file addition: src (d--r------)
    [0.32]
  • file addition: lib.rs (----------)
    [0.49]
    use icu_provider::DataLocale;
    // Public re-exports of dependencies required at runtime, so macro-generated code
    // can find all the dependencies it expects as long as this crate exists
    pub use icu_locid::{self, langid, LanguageIdentifier};
    pub use icu_plurals::{self, PluralRuleType, PluralRules};
    pub use locale_select;
    pub trait Localize {
    const CANONICAL_LOCALE: LanguageIdentifier;
    fn localize(&self) -> String;
    }
    /// Select which locale to use, falling back to the canonical locale if nothing matches
    pub fn select_locale(
    available_locales: &[LanguageIdentifier],
    canonical_locale: &LanguageIdentifier,
    ) -> LanguageIdentifier {
    locale_select::match_locales(available_locales, canonical_locale)
    }
    pub fn plural_rules(
    locale: &LanguageIdentifier,
    rule_type: PluralRuleType,
    ) -> Result<PluralRules, icu_plurals::Error> {
    let data_locale = DataLocale::from(locale);
    PluralRules::try_new(&data_locale, rule_type)
    }
  • file addition: Cargo.toml (----------)
    [0.32]
    [package]
    name = "fluent_embed_runtime"
    version = "0.1.0"
    edition = "2021"
    [lints]
    workspace = true
    [dependencies]
    icu_locid = "1.4.0"
    icu_plurals = "1.4.0"
    icu_provider = "1.4.0"
    locale_select = { path = "../locale_select" }
  • edit in fluent_embed/src/lib.rs at line 80
    [2.774]
    [3.5596]
    let canonical_locale = group.canonical_locale().id.clone().to_string();
  • edit in fluent_embed/src/lib.rs at line 91
    [3.5915]
    [3.384]
  • replacement in fluent_embed/src/lib.rs at line 93
    [3.400][3.5928:6021](),[3.5928][3.5928:6021]()
    impl #ident {
    // TODO: most of this shouldn't be generated on every call
    [3.400]
    [3.6021]
    impl ::fluent_embed_runtime::Localize for #ident {
    const CANONICAL_LOCALE: ::fluent_embed_runtime::icu_locid::LanguageIdentifier =
    ::fluent_embed_runtime::icu_locid::langid!(#canonical_locale);
  • replacement in fluent_embed/src/fluent/ast.rs at line 27
    [2.7178][2.7178:7266]()
    parse_quote!(::icu_plurals::PluralCategory::#ident)
    [2.7178]
    [2.7266]
    parse_quote!(::fluent_embed_runtime::icu_plurals::PluralCategory::#ident)
  • edit in fluent_embed/src/derive.rs at line 26
    [3.251][3.193:261](),[2.9529][3.193:261](),[3.193][3.193:261]()
    let canonical_locale = group.canonical_locale().id.to_string();
  • replacement in fluent_embed/src/derive.rs at line 39
    [3.510][3.608:654](),[3.1368][3.608:654](),[3.654][3.654:902]()
    // Find the appropriate locale to use
    let additional_locales = [#(::icu_locid::langid!(#additional_locales)),*];
    let canonical_locale = ::icu_locid::langid!(#canonical_locale);
    let locale = ::locale_select::match_locales(&additional_locales, &canonical_locale);
    [3.510]
    [3.625]
    // Create a list of available locales to choose from
    let available_locales = [
    // The canonical locale will always be available
    Self::CANONICAL_LOCALE,
    // Any additional locales that contain this message
    #(::fluent_embed_runtime::langid!(#additional_locales)),*
    ];
    let locale = ::fluent_embed_runtime::select_locale(&available_locales, &Self::CANONICAL_LOCALE);
  • replacement in fluent_embed/src/derive.rs at line 49
    [3.993][3.993:1180]()
    let plural_rule_type = ::icu_plurals::PluralRuleType::Cardinal;
    let plural_rules = ::icu_plurals::PluralRules::try_new(&locale.clone().into(), plural_rule_type).unwrap();
    [3.993]
    [3.712]
    // TODO: only generate this when needed in message
    const plural_rule_type: ::fluent_embed_runtime::PluralRuleType =
    ::fluent_embed_runtime::PluralRuleType::Cardinal;
    let plural_rules = ::fluent_embed_runtime::plural_rules(&locale, plural_rule_type).unwrap();
  • edit in fluent_embed/src/derive.rs at line 54
    [3.713]
    [3.1181]
    // Handle any additional locales
  • edit in fluent_embed/src/derive.rs at line 56
    [3.1275]
    [3.1275]
    // Fall back to the canonical locale, if no other valid locale was matched
  • edit in cli_macros/tests/selectors.rs at line 4
    [19.269]
    [19.340]
    use fluent_embed_runtime::Localize;
  • replacement in cli_macros/Cargo.toml at line 22
    [3.991][3.991:1033](),[3.1033][3.1544:1590]()
    icu_locid = "1.4.0"
    icu_plurals = "1.4.0"
    locale_select = { path = "../locale_select" }
    [3.991]
    fluent_embed_runtime = { path = "../fluent_embed_runtime" }
  • replacement in Cargo.toml at line 2
    [3.210][3.5581:5656]()
    members = ["fluent_embed", "output-macros", "cli_macros", "locale_select"]
    [3.210]
    [3.238]
    members = ["fluent_embed", "output-macros", "cli_macros", "locale_select", "fluent_embed_runtime"]
  • replacement in Cargo.lock at line 82
    [3.1178][3.1178:1208](),[3.1208][3.0:18]()
    "icu_locid",
    "icu_plurals",
    "locale_select",
    [3.1178]
    [3.14657]
    "fluent_embed_runtime",
  • edit in Cargo.lock at line 182
    [3.1960]
    [21.378]
    ]
    [[package]]
    name = "fluent_embed_runtime"
    version = "0.1.0"
    dependencies = [
    "icu_locid",
    "icu_plurals",
    "icu_provider",
    "locale_select",
  • replacement in Cargo.lock at line 637
    [3.4371][3.4371:4390]()
    version = "1.13.1"
    [3.4371]
    [3.4390]
    version = "1.13.2"
  • replacement in Cargo.lock at line 639
    [3.4455][3.4455:4533]()
    checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7"
    [3.4455]
    [3.4533]
    checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"