-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(i18n_codegen): Update Cargo.toml and README.md, adjust code …
…generation logic Update the Cargo.toml file to adjust documentation links and change the version number to 0.2.0. Update the README.md file to add missing contributors and adjust example code to reflect the latest changes. Refactor example_path.rs and src/lib.rs to optimize code generation logic, ensuring correct handling of file paths and attributes. Fix error handling logic in src/lib.rs to improve the accuracy of error messages. BREAKING CHANGE: This commit introduces significant refactoring and version updates that may impact dependency resolution and code generation functionality. Please ensure thorough testing before upgrading.
- Loading branch information
1 parent
b9bb3b2
commit cad9a11
Showing
8 changed files
with
131 additions
and
717 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
/target | ||
**/*.rs.bk | ||
Cargo.lock | ||
Cargo.lock |
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,50 @@ | ||
# [i18nify](https://github.com/kingzcheung/i18nify) | ||
简体中文| [English](./README.md) | ||
|
||
[i18nify](https://github.com/kingzcheung/i18nify) 是一款基于代码生成的 `Rust` 国际化库。 | ||
|
||
> 原仓库 [https://github.com/davidpdrsn/i18n_codegen](https://github.com/davidpdrsn/i18n_codegen) 是 [David Pedersen](https://github.com/davidpdrsn) 实现的。然而它有一些老旧的依赖,并且已经长达5年不维护。 | ||
通过利用代码生成,我们能够防止代码中的拼写错误、缺少插值或各语言环境之间各种错误的常见问题。 | ||
|
||
它需要一个目录(目录基于`CARGO_MANIFEST_DIR`),其中每个语言环境有一个 JSON 文件。以下是一个包含英语和汉语翻译的例子: | ||
|
||
```javascript | ||
// tests/doc_locales/en.json | ||
{ | ||
"hello_world": "Hello, World!", | ||
"greeting": "Hello {name}" | ||
} | ||
|
||
// tests/doc_locales/da.json | ||
{ | ||
"hello_world": "你好,世界!", | ||
"greeting": "你好, {name}" | ||
} | ||
``` | ||
在 `Rust` 中: | ||
```rust | ||
use demo::Internationalize; | ||
|
||
mod demo { | ||
use i18nify::I18N; | ||
#[derive(I18N)] | ||
#[i18n(folder = "tests/locales")] | ||
pub struct DocLocale; | ||
|
||
} | ||
|
||
fn main() { | ||
// 基于 Locale 枚举类型获取国际化文本 | ||
let hello = demo::Locale::En.hello(); | ||
assert_eq!("Hello, World!",hello); | ||
println!("{}",hello); | ||
|
||
// 基于 `DocLocale` 实现的`Internationalize` trait 获取国际化文本 | ||
let hello = demo::DocLocale.da().hello(); | ||
println!("{}",hello); | ||
} | ||
|
||
``` | ||
|
||
你可以在 <[文档](https://docs.rs/i18nify)> 获取更多细节。 |
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
Oops, something went wrong.