Skip to content

Releases: longbridge/rust-i18n

v3.1.2

20 Aug 11:52
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v3.1.1...v3.1.2

v3.1.1

09 Aug 03:30
Compare
Choose a tag to compare

What's Changed

  • Introduced the minify_key feature for i18n! and added support for format specifiers in t! 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

23 Jan 01:46
Compare
Choose a tag to compare

What's Changed

  • Use arc_swap to implement AtomicStr for thread-safe. by @Kijewski in #72

New Contributors

Full Changelog: v3.0.0...v3.0.1

v3.0.0

19 Jan 07:45
Compare
Choose a tag to compare

What's Changed

  • Add more than one fallback with priority support, eg: i18n!("locales", fallback = ["en", "es]); by @varphone #69
    • Remove RwLock from locale() and set_locale().
    • String patterns replacement, time reduce 10% ~ 80%.
    • Reduce memory copy on t!().

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>.

v2.3.1

15 Jan 07:33
Compare
Choose a tag to compare

What's Changed

Fallback example:

  1. zh-CN or zh-HK or zh-SG
  2. zh

New Contributors

Full Changelog: v2.3.0...v2.3.1

v2.3.0

14 Nov 02:59
Compare
Choose a tag to compare

What's Changed

  • Split cargo i18n to separate crate by @urkle in #66
$ cargo install rust-i18n-cli

Full Changelog: v2.2.1...v2.3.0

v2.2.1

28 Aug 08:25
Compare
Choose a tag to compare
  • Fix rust-i18n-macro dependency #55

v2.2.0

28 Aug 07:09
Compare
Choose a tag to compare

What's Changed

  • Add to support translated text with multiple locales in one file. by @huacnlee in #50
  • Add _version for locale file for special the file format.
    • _version: 1 - Split each language into difference files (default).
    • _version: 2 - All language in same file.
  • Update cargo i18n command for output _version: 2 format.

Example

Write a app.yml

_version: 2
hello:
  en: "Hello"
  zh-CN: "你好"
  world:
    en: "Hello World"
    zh-CN: "你好世界"
welcome.message:
  en: "Welcome"
  zh-CN: "欢迎"

Screenshot

rust-i18n-example

Other Changes

  • Do not use . in macro output if locale string is empty. by @ajantti in #51
  • Some more fixes and improvements. by @ajantti in #53
  • Add a test for checking if tests are run single-threadedly. by @ajantti in #54
  • Improve generator output to remove leading --- in YAML file.

New Contributors

Full Changelog: v2.1.0...v2.2.0

v2.1.0

26 Jul 02:21
Compare
Choose a tag to compare

What's Changed

  • Bump syn from 1.0.82 to 2.0.18 by @sunli829 in #42
  • Rewrite SimpleBackend translations struct to avoid memory allocation of the key string. by @huacnlee in #41
  • Update toml in the main rust-i18n crate to match that of the rust-i18n-support crate by @urkle in #43
  • Improve current_locale get performance by use RwLock.

New Contributors

Full Changelog: v2.0.0...v2.1.0

v2.0.0

20 Jun 03:22
Compare
Choose a tag to compare

What's New

  • Add multiple formats *.{yml,yaml,json, toml} #38
  • Add Backend trait for allows us to customize the difference translations storage.
  • Rewrite code to generate for use backend as code result to allows extending backend.
  • Add public API i18n() method, this is Backend instance.

Breaking Changes

  • available_locales method has removed, use rust_i18n::available_locales!() instead.
  • Refactor crate rust_i18n_support internal APIs, private some methods.

How to extend backend

Write a struct that implements the Backend trait, and then implement the methods in the trait.

use rust_i18n::Backend;

pub struct MyBackend {
    trs: HashMap<String, HashMap<String, String>>,
}

impl MyBackend {
    fn new() -> Self {
        let trs = HashMap::new();
        trs.insert("en".to_string(), {
            let mut trs = HashMap::new();
            trs.insert("hello".to_string(), "Hello MyBackend".to_string());
            trs.insert("welcome".to_string(), "Welcome to use MyBackend".to_string());
            trs
        });
        
        return Self {
            trs
        };
    }
}

impl Backend for MyBackend {
    fn available_locales(&self) -> Vec<String> {
        todo!()
    }

    fn translate(&self, locale: &str, key: &str) -> Option<String> {
        // Write your own lookup logic here.
        // For example load from database
        return self.trs.get(locale)?.get(key).cloned();
    }
}

Now replace the default backend with your own backend.

rust_i18n::i18n!(fallback = "en", backend = MyBackend::new());

fn main() {
    t!("hello");
    // "Hello MyBackend"
    t!("welcome");
    // "Welcome to use MyBackend"
}

This also will load local translates from ./locales path, but your own MyBackend will priority than it.