-
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
Changes from 5 commits
ba3af46
903c3d1
99ff77b
53b53b1
e7e7563
2184045
479c72c
fdfc1ff
24468c3
2c0af63
f5a8322
ee5cd8c
310dfc3
22740f1
834ec0a
85b33e7
1827611
658c680
20ba421
0449d7b
8f431d0
be10786
ff3ebd9
3a8111b
4d78704
1be4d47
2a9abe1
1fa8630
1b19e83
6cfbef7
ee998bd
f8d816a
8b325d3
a11224f
0b606cc
f33d24d
2a9e8cf
8762c15
17d931d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
use anyhow::Error; | ||
use clap::{Args, Parser}; | ||
use rust_i18n_extract::attrs::I18nAttrs; | ||
use rust_i18n_support::MinifyKey; | ||
|
||
use std::{collections::HashMap, path::Path}; | ||
|
||
use rust_i18n_extract::extractor::Message; | ||
use rust_i18n_extract::{extractor, generator, iter}; | ||
mod config; | ||
use rust_i18n_support::{I18nConfig, MinifyKey}; | ||
use std::{collections::HashMap, path::Path}; | ||
|
||
#[derive(Parser)] | ||
#[command(name = "cargo")] | ||
|
@@ -71,14 +67,16 @@ fn translate_value_parser(s: &str) -> Result<(String, String), std::io::Error> { | |
fn add_translations( | ||
list: &[(String, String)], | ||
results: &mut HashMap<String, Message>, | ||
attrs: &I18nAttrs, | ||
cfg: &I18nConfig, | ||
) { | ||
let I18nAttrs { | ||
let I18nConfig { | ||
minify_key, | ||
minify_key_len, | ||
minify_key_prefix, | ||
minify_key_thresh, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 你先不要暴露 另外我倒是觉得这么多参数,不如让 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这几个参数没有暴露给最终用户,但是生成本地化文件时是需要的,不然没法和代码里的配置相一致。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 用函数给用户定制的话有几个问题:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 那就留着 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不过长度有没有必要提供,我觉得可以想好以后,给一个方案,这里参数稍微一改动,原来的国际化就对不上了(并且人工对也很难对应上) |
||
} = attrs; | ||
.. | ||
} = cfg; | ||
|
||
for item in list { | ||
let index = results.len(); | ||
let key = if *minify_key { | ||
|
@@ -105,14 +103,14 @@ fn main() -> Result<(), Error> { | |
|
||
let source_path = args.source.expect("Missing source path"); | ||
|
||
let cfg = config::load(std::path::Path::new(&source_path))?; | ||
let cfg = I18nConfig::load(std::path::Path::new(&source_path))?; | ||
|
||
iter::iter_crate(&source_path, |path, source| { | ||
extractor::extract(&mut results, path, source, cfg.attrs.clone()) | ||
extractor::extract(&mut results, path, source, cfg.clone()) | ||
})?; | ||
|
||
if let Some(list) = args.translate { | ||
add_translations(&list, &mut results, &cfg.attrs); | ||
add_translations(&list, &mut results, &cfg); | ||
} | ||
|
||
let mut messages: Vec<_> = results.iter().collect(); | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
pub mod attrs; | ||
pub mod extractor; | ||
pub mod generator; | ||
pub mod iter; |
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
不用传