-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduced the minify_key
feature for i18n!
and added support for format specifiers in t!
#73
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
ba3af46
Rename key! to vakey!
varphone 903c3d1
Add crate::_rust_i18n_try_translate() to returns None on untranslated
varphone 99ff77b
Add CowStr<'a> and TrKey for new tr!
varphone 53b53b1
Add new `tr!` macro to get translations with string literals supports
varphone e7e7563
Add `tr!` support to `rust-i18n-extract` and `rust-i18n-cli`
varphone 2184045
Update benchmark and tests for tr!
varphone 479c72c
Add new application example for `tr!`
varphone fdfc1ff
Update README.md for `tr!`
varphone 24468c3
Update to new rust-i18n::locale() with breaking changes
varphone 2c0af63
Add concurrent testing for tr!
varphone f5a8322
Add tr_with_args (many-dynamic) and format! (many) benchmarks
varphone ee5cd8c
examples/app-tr: Cleanup
varphone 310dfc3
Update SEO keywords to improve visibility of our package on crates.io
varphone 22740f1
Add colonsAdd colon assignment syntax for tr!, similar to struct fiel…
varphone 834ec0a
Add new option --tr for rust-i18n-cli to support manual add translati…
varphone 85b33e7
Rename feature `log_tr_dyn` to `log-tr-dyn`
varphone 1827611
Change tr! missing log level to warn
varphone 658c680
Refactor Tr
varphone 20ba421
examples/app-tr: Add log-tr-dyn demos
varphone 0449d7b
Improve the help documentation for the `--tr` option in `rust-i18n-cli`
varphone 8f431d0
Add specifiers support to tr! and remove colons assignment style
varphone be10786
Add CowStr::as_str()
varphone ff3ebd9
Rename TrKey to MinifyKey
varphone 3a8111b
Add `minify_key` supports to `in18n!` and `tr!`
varphone 4d78704
Add `minify_key` supports to `t!`
varphone 1be4d47
Add `minify_key` supports to `rust-i18n-cli`
varphone 2a9abe1
Add `minify_key` benchmark and testing
varphone 1fa8630
Add new example: app-minify-key
varphone 1b19e83
Add new example: app-egui
varphone 6cfbef7
Move rust-i18n-cli argument `SOURCE` to last
varphone ee998bd
Cleanup clippy warnings
varphone f8d816a
Update README.md
varphone 8b325d3
Rename feature `log-missing` to `log-miss-tr`
varphone a11224f
Cargo.toml: apply toml format
varphone 0b606cc
Move `I18nConfig` from `rust-i18n-cli` to `rust-i18n-support`
varphone f33d24d
Display the file path when loading a locale file fails
varphone 2a9e8cf
Add `fallback` option to I18nConfig
varphone 8762c15
Add `metadata` supports to `in18n!`
varphone 17d931d
Remove unexpected files
varphone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use rust_i18n::t; | ||
|
||
rust_i18n::i18n!("./tests/locales", minify_key = true, minify_key_len = 12); | ||
|
||
pub fn bench_t(c: &mut Criterion) { | ||
c.bench_function("t", |b| b.iter(|| t!("hello"))); | ||
|
||
c.bench_function("t_lorem_ipsum", |b| b.iter(|| t!( | ||
r#"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque sed nisi leo. Donec commodo in ex at aliquam. Nunc in aliquam arcu. Fusce mollis metus orci, ut sagittis erat lobortis sed. Morbi quis arcu ultrices turpis finibus tincidunt non in purus. Donec gravida condimentum sapien. Duis iaculis fermentum congue. Quisque blandit libero a lacus auctor vestibulum. Nunc efficitur sollicitudin nisi, sit amet tristique lectus mollis non. Praesent sit amet erat volutpat, pharetra orci eget, rutrum felis. Sed elit augue, imperdiet eu facilisis vel, finibus vel urna. Duis quis neque metus. | ||
|
||
Mauris suscipit bibendum mattis. Vestibulum eu augue diam. Morbi dapibus tempus viverra. Sed aliquam turpis eget justo ornare maximus vitae et tortor. Donec semper neque sit amet sapien congue scelerisque. Maecenas bibendum imperdiet dolor interdum facilisis. Integer non diam tempus, pharetra ex at, euismod diam. Ut enim turpis, sagittis in iaculis ut, finibus et sem. Suspendisse a felis euismod neque euismod placerat. Praesent ipsum libero, porta vel egestas quis, aliquet vitae lorem. Nullam vel pharetra erat, sit amet sodales leo."# | ||
))); | ||
|
||
c.bench_function("t_with_locale", |b| b.iter(|| t!("hello", locale = "en"))); | ||
|
||
c.bench_function("tr_with_threads", |b| { | ||
let exit_loop = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false)); | ||
let mut handles = Vec::new(); | ||
for _ in 0..4 { | ||
let exit_loop = exit_loop.clone(); | ||
handles.push(std::thread::spawn(move || { | ||
while !exit_loop.load(std::sync::atomic::Ordering::SeqCst) { | ||
criterion::black_box(t!("hello")); | ||
} | ||
})); | ||
} | ||
b.iter(|| t!("hello")); | ||
exit_loop.store(true, std::sync::atomic::Ordering::SeqCst); | ||
for handle in handles { | ||
handle.join().unwrap(); | ||
} | ||
}); | ||
|
||
c.bench_function("tr_with_args", |b| { | ||
b.iter(|| { | ||
t!( | ||
"Hello, %{name}. Your message is: %{msg}", | ||
name = "Jason", | ||
msg = "Bla bla" | ||
) | ||
}) | ||
}); | ||
|
||
c.bench_function("tr_with_args (str)", |b| { | ||
b.iter(|| { | ||
t!( | ||
"Hello, %{name}. Your message is: %{msg}", | ||
"name" = "Jason", | ||
"msg" = "Bla bla" | ||
) | ||
}) | ||
}); | ||
|
||
c.bench_function("tr_with_args (many)", |b| { | ||
b.iter(|| { | ||
t!( | ||
r#"Hello %{name} %{surname}, your account id is %{id}, email address is %{email}. | ||
You live in %{city} %{zip}. | ||
Your website is %{website}."#, | ||
id = 123, | ||
name = "Marion", | ||
surname = "Christiansen", | ||
email = "[email protected]", | ||
city = "Litteltown", | ||
zip = 8408, | ||
website = "https://snoopy-napkin.name" | ||
) | ||
}) | ||
}); | ||
|
||
c.bench_function("t_with_args (many-dynamic)", |b| { | ||
let msg = r#"Hello %{name} %{surname}, your account id is %{id}, email address is %{email}. | ||
You live in %{city} %{zip}. | ||
Your website is %{website}."# | ||
.to_string(); | ||
b.iter(|| { | ||
t!( | ||
&msg, | ||
id = 123, | ||
name = "Marion", | ||
surname = "Christiansen", | ||
email = "[email protected]", | ||
city = "Litteltown", | ||
zip = 8408, | ||
website = "https://snoopy-napkin.name" | ||
) | ||
}) | ||
}); | ||
|
||
c.bench_function("format! (many)", |b| { | ||
b.iter(|| { | ||
format!( | ||
r#"Hello {name} %{surname}, your account id is {id}, email address is {email}. | ||
You live in {city} {zip}. | ||
Your website is {website}."#, | ||
id = 123, | ||
name = "Marion", | ||
surname = "Christiansen", | ||
email = "[email protected]", | ||
city = "Litteltown", | ||
zip = 8408, | ||
website = "https://snoopy-napkin.name" | ||
); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, bench_t); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
从
[package.metadata.i18n]
读取配置这个我老早就想做了。不过我觉得这个可以不用增加参数,默认就会读配置,按优先级处理,
i18n!
如果有参数,会覆盖配置。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里改一下,让 metadata 默认就是
true
不用传