Skip to content

Commit dbc68b9

Browse files
committed
Refactor code for #73, private some method.
- Renamed `mikey` to `minify_key`. - Removed unused `vakey`. - Removed `t!((key, msg))` support, this need to think about it. - Hidden (mark `#[doc(hidden)]) some private method, even it pub, it only provided for rust_i18n itself.
1 parent 37bb5de commit dbc68b9

File tree

22 files changed

+155
-267
lines changed

22 files changed

+155
-267
lines changed

README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ i18n!("locales", minify_key = true);
6565
i18n!("locales",
6666
minify_key = true,
6767
minify_key_len = 12,
68-
minify_key_prefix = "T.",
68+
minify_key_prefix = "t_",
6969
minify_key_thresh = 64
7070
);
7171
// Now, if the message length exceeds 64, the `t!` macro will automatically generate
72-
// a 12-byte short hashed key with a "T." prefix for it, if not, it will use the original.
72+
// a 12-byte short hashed key with a "t_" prefix for it, if not, it will use the original.
7373
7474
// Configuration using the `[package.metadata.i18n]` section in `Cargo.toml`,
7575
// Useful for the `cargo i18n` command line tool.
76-
i18n!(metadata = true);
76+
i18n!();
7777
```
7878

7979
Or you can import by use directly:
@@ -116,11 +116,11 @@ You can also split the each language into difference files, and you can choise (
116116

117117
```yml
118118
_version: 1
119-
hello: "Hello world"
120-
messages.hello: "Hello, %{name}"
119+
hello: 'Hello world'
120+
messages.hello: 'Hello, %{name}'
121121

122122
# Generate short hashed keys using `minify_key=true, minify_key_thresh=10`
123-
4Cct6Q289b12SkvF47dXIx: "Hello, %{name}"
123+
4Cct6Q289b12SkvF47dXIx: 'Hello, %{name}'
124124
```
125125
126126
Or use JSON or TOML format, just rename the file to `en.json` or `en.toml`, and the content is like this:

benches/minify_key.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn bench_t(c: &mut Criterion) {
1414

1515
c.bench_function("t_with_locale", |b| b.iter(|| t!("hello", locale = "en")));
1616

17-
c.bench_function("tr_with_threads", |b| {
17+
c.bench_function("t_with_threads", |b| {
1818
let exit_loop = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
1919
let mut handles = Vec::new();
2020
for _ in 0..4 {
@@ -32,7 +32,7 @@ pub fn bench_t(c: &mut Criterion) {
3232
}
3333
});
3434

35-
c.bench_function("tr_with_args", |b| {
35+
c.bench_function("t_with_args", |b| {
3636
b.iter(|| {
3737
t!(
3838
"Hello, %{name}. Your message is: %{msg}",
@@ -42,7 +42,7 @@ pub fn bench_t(c: &mut Criterion) {
4242
})
4343
});
4444

45-
c.bench_function("tr_with_args (str)", |b| {
45+
c.bench_function("t_with_args (str)", |b| {
4646
b.iter(|| {
4747
t!(
4848
"Hello, %{name}. Your message is: %{msg}",
@@ -52,7 +52,7 @@ pub fn bench_t(c: &mut Criterion) {
5252
})
5353
});
5454

55-
c.bench_function("tr_with_args (many)", |b| {
55+
c.bench_function("t_with_args (many)", |b| {
5656
b.iter(|| {
5757
t!(
5858
r#"Hello %{name} %{surname}, your account id is %{id}, email address is %{email}.

crates/cli/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn translate_value_parser(s: &str) -> Result<(String, String), std::io::Error> {
6363
}
6464
}
6565

66-
/// Add translations to the localize file for tr!
66+
/// Add translations to the localize file for t!
6767
fn add_translations(
6868
list: &[(String, String)],
6969
results: &mut HashMap<String, Message>,

crates/extract/src/generator.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn generate<'a, P: AsRef<Path>>(
2828
eprintln!("Writing to {}\n", filename);
2929

3030
let text = convert_text(&trs, format);
31-
write_file(&output_path, &filename, &text)?;
31+
write_file(&output_path, filename, &text)?;
3232

3333
// Finally, return error for let CI fail
3434
let err = std::io::Error::new(std::io::ErrorKind::Other, "");
@@ -98,7 +98,7 @@ fn generate_result<'a, P: AsRef<Path>>(
9898
};
9999

100100
trs.entry(key.clone())
101-
.or_insert_with(HashMap::new)
101+
.or_default()
102102
.insert(locale.to_string(), value.to_string());
103103
}
104104
}
@@ -145,7 +145,7 @@ mod tests {
145145
"_version": 2
146146
}
147147
"#;
148-
assert_eq_json(&result, &expect);
148+
assert_eq_json(&result, expect);
149149

150150
trs.insert("hello".to_string(), {
151151
let mut map = HashMap::new();
@@ -164,7 +164,7 @@ mod tests {
164164
}
165165
}
166166
"#;
167-
assert_eq_json(&result, &expect);
167+
assert_eq_json(&result, expect);
168168

169169
let format = "yaml";
170170
let result = convert_text(&trs, format);

0 commit comments

Comments
 (0)