Releases: longbridge/rust-i18n
Releases · longbridge/rust-i18n
v4.0.0
What's Changed
Breaking Changes
Backendtrait signature changed to useCow<'_, str>—available_locales()now returnsVec<Cow<'_, str>>instead ofVec<&str>, andtranslate()now returnsOption<Cow<'_, str>>instead ofOption<&str>. CustomBackendimplementations must be updated accordingly. (#114)SimpleBackend::add_translations()signature changed — Now takesCow<'static, str>for locale andHashMap<Cow<'static, str>, Cow<'static, str>>for data, instead of&strand&HashMap<&str, &str>. (#133)- New required method
messages_for_localeonBackendtrait — Returns all translation messages for a given locale asOption<Vec<(Cow<'_, str>, Cow<'_, str>)>>. - Removed
once_celldependency — Replaced withstd::sync::LazyLockfrom the standard library. The re-exportrust_i18n::once_cellis no longer available. This raises the minimum supported Rust version (MSRV) to 1.80.0. (#131)
Performance Improvements
- Dramatically reduced allocations in the
i18n!macro expansion — Previously, the macro generated oneHashMapper translation pair; now it generates oneHashMapper locale. For large projects, this reduces HashMap creation from thousands to just a handful (e.g., 14,000 → 32). This also fixes stack overflow crashes on Windows for projects with many translations. (#133) - Eliminated unnecessary
Stringallocations — By usingCow<'static, str>throughout, static translation strings are no longer cloned into heap-allocatedStrings. (#114, #133)
New Features
messages_for_locale()method onBackend— Retrieve all translation key-value pairs for a specific locale, useful for inspection and debugging.try_load_locales()function — A fallible alternative toload_locales()inrust-i18n-supportthat returnsResultinstead of panicking, with detailed error messages for file lookup, parsing, and I/O failures. (#127)- Improved error messages — Parsing failures now include the specific error reason instead of a generic panic message. (#116)
Internal / Maintenance
- Replaced
once_cell::sync::Lazywithstd::sync::LazyLock(#131) - Added
Cargo.lockto version control (#120) - Improved CI workflow with concurrency groups and branch filtering
- Added release workflow
- Bumped
slabfrom 0.4.10 to 0.4.11 (#122)
Migration Guide
If you have a custom Backend implementation, update it to:
use std::borrow::Cow;
impl Backend for MyBackend {
fn available_locales(&self) -> Vec<Cow<'_, str>> { /* ... */ }
fn translate(&self, locale: &str, key: &str) -> Option<Cow<'_, str>> { /* ... */ }
fn messages_for_locale(&self, locale: &str) -> Option<Vec<(Cow<'_, str>, Cow<'_, str>)>> { /* ... */ }
}If you were using rust_i18n::once_cell, switch to std::sync::LazyLock (requires Rust 1.80+).
New Contributors
- @niclas-AH made their first contribution in #114
- @LennDG made their first contribution in #116
- @jayson-lennon made their first contribution in #127, #131
- @Multirious made their first contribution in #133
Full Changelog: v3.1.5...v4.0.0
v3.1.5
v3.1.4
What's Changed
- chore: Switch to use serde_yaml. by @huacnlee in #108
By special reason rustsec/advisory-db#2212
Full Changelog: v3.1.3...v3.1.4
v3.1.3
v3.1.2
What's Changed
- Reduce unnecessary memory copying by @yk0n9 in #89
- Fix lazy init always "en" by @yk0n9, @KKRainbow in #88
New Contributors
- @yk0n9, @KKRainbow made their first contribution in #88
Full Changelog: v3.1.1...v3.1.2
v3.1.1
What's Changed
- Introduced the
minify_keyfeature fori18n!and added support for format specifiers int!by @varphone in #73 - Update example for share I18n in entire workspace by @huacnlee in #80
- Update doc for locale file version. by @huacnlee in #82
- Update to use serde_yml (#86)
Full Changelog: v3.0.1...v3.1.1
v3.0.1
v3.0.0
What's Changed
- Add more than one fallback with priority support, eg:
i18n!("locales", fallback = ["en", "es]);by @varphone #69- Remove
RwLockfromlocale()andset_locale(). - String patterns replacement, time reduce 10% ~ 80%.
- Reduce memory copy on
t!().
- Remove
Performance improved
- t time: [100.91 ns 101.06 ns 101.24 ns]
- t_with_args time: [495.56 ns 497.88 ns 500.64 ns]
+ t time: [58.274 ns 60.222 ns 62.390 ns]
+ t_with_args time: [167.46 ns 170.94 ns 175.64 ns]Breaking Changes
rust_i18n::locale() -> String=>rust_i18n::locale() -> Arc<String>.t!() -> String=>t!() -> Cow<str>.