Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Jan 31, 2024
1 parent dbc68b9 commit 33f5fca
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ Load macro and init translations in `lib.rs` or `main.rs`:
extern crate rust_i18n;
// Init translations for current crate.
// This will load Configuration using the `[package.metadata.i18n]` section in `Cargo.toml` if exists.
// Or you can pass arguments by `i18n!` to override it.
i18n!("locales");
// Or just use `i18n!`, default locales path is: "locales" in current crate.
//
i18n!();
// Config fallback missing translations to "en" locale.
// Use `fallback` option to set fallback locale.
//
Expand All @@ -71,8 +69,7 @@ i18n!("locales",
// Now, if the message length exceeds 64, the `t!` macro will automatically generate
// a 12-byte short hashed key with a "t_" prefix for it, if not, it will use the original.
// Configuration using the `[package.metadata.i18n]` section in `Cargo.toml`,
// Useful for the `cargo i18n` command line tool.
// If no any argument, use config from Cargo.toml or default.
i18n!();
```

Expand Down Expand Up @@ -118,9 +115,7 @@ You can also split the each language into difference files, and you can choise (
_version: 1
hello: 'Hello world'
messages.hello: 'Hello, %{name}'

# Generate short hashed keys using `minify_key=true, minify_key_thresh=10`
4Cct6Q289b12SkvF47dXIx: 'Hello, %{name}'
t_4Cct6Q289b12SkvF47dXIx: 'Hello, %{name}'
```
Or use JSON or TOML format, just rename the file to `en.json` or `en.toml`, and the content is like this:
Expand All @@ -130,17 +125,13 @@ Or use JSON or TOML format, just rename the file to `en.json` or `en.toml`, and
"_version": 1,
"hello": "Hello world",
"messages.hello": "Hello, %{name}",
// Generate short hashed keys using `minify_key=true, minify_key_thresh=10`
"4Cct6Q289b12SkvF47dXIx": "Hello, %{name}"
"t_4Cct6Q289b12SkvF47dXIx": "Hello, %{name}"
}
```

```toml
hello = "Hello world"

# Generate short hashed keys using `minify_key=true, minify_key_thresh=10`
4Cct6Q289b12SkvF47dXIx = "Hello, %{name}"
t_4Cct6Q289b12SkvF47dXIx = "Hello, %{name}"
[messages]
hello = "Hello, %{name}"
Expand Down Expand Up @@ -179,9 +170,8 @@ hello:
messages.hello:
en: Hello, %{name}
zh-CN: 你好,%{name}

# Generate short hashed keys using `minify_key=true, minify_key_thresh=10`
4Cct6Q289b12SkvF47dXIx:
t_4Cct6Q289b12SkvF47dXIx:
en: Hello, %{name}
zh-CN: 你好,%{name}
```
Expand Down

0 comments on commit 33f5fca

Please sign in to comment.