-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from urkle/feat-split-carg-i18n-to-separate-crate
Feat split carg i18n to separate crate
- Loading branch information
Showing
17 changed files
with
174 additions
and
119 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 |
---|---|---|
|
@@ -3,7 +3,7 @@ authors = ["Jason Lee <[email protected]>"] | |
build = "build.rs" | ||
categories = ["localization", "internationalization"] | ||
description = "Rust I18n is use Rust codegen for load YAML file storage translations on compile time, and give you a t! macro for simply get translation texts." | ||
edition = "2018" | ||
edition = "2021" | ||
exclude = ["crates", "tests"] | ||
keywords = ["i18n", "yml", "localization", "internationalization"] | ||
license = "MIT" | ||
|
@@ -13,25 +13,15 @@ repository = "https://github.com/longbridgeapp/rust-i18n" | |
version = "2.2.1" | ||
|
||
[dependencies] | ||
anyhow = {version = "1", optional = true} | ||
clap = {version = "2.32", optional = true} | ||
itertools = {version = "0.10.3", optional = true} | ||
once_cell = "1.10.0" | ||
quote = {version = "1", optional = true} | ||
rust-i18n-extract = {path = "./crates/extract", version = "2.1.0", optional = true} | ||
rust-i18n-support = {path = "./crates/support", version = "2.1.0"} | ||
rust-i18n-macro = {path = "./crates/macro", version = "2.1.0"} | ||
serde = "1" | ||
serde_derive = "1" | ||
toml = "0.7.4" | ||
|
||
[dev-dependencies] | ||
foo = {path = "examples/foo"} | ||
criterion = "0.5" | ||
lazy_static = "1" | ||
|
||
[features] | ||
default = ["rust-i18n-extract", "clap", "anyhow", "quote", "itertools"] | ||
serde_yaml = "0.8" | ||
|
||
[build-dependencies] | ||
globwalk = "0.8.1" | ||
|
@@ -41,13 +31,9 @@ regex = "1" | |
name = "app" | ||
test = true | ||
|
||
[[bin]] | ||
name = "cargo-i18n" | ||
path = "src/main.rs" | ||
required-features = ["default"] | ||
|
||
[workspace] | ||
members = [ | ||
"crates/cli", | ||
"crates/extract", | ||
"crates/support", | ||
"crates/macro", | ||
|
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,21 @@ | ||
[package] | ||
description = "cargo-i18n tool for the rust-i18n crate." | ||
edition = "2021" | ||
license = "MIT" | ||
name = "rust-i18n-cli" | ||
readme = "../../README.md" | ||
repository = "https://github.com/longbridgeapp/rust-i18n" | ||
version = "2.1.0" | ||
|
||
[dependencies] | ||
anyhow = "1" | ||
clap = { version = "4.1.14", features = ["derive"] } | ||
itertools = "0.11.0" | ||
rust-i18n-support = { path = "../support", version = "2.1.0" } | ||
rust-i18n-extract = { path = "../extract", version = "2.1.0" } | ||
serde = { version = "1", features = ["derive"] } | ||
toml = "0.7.4" | ||
|
||
[[bin]] | ||
name = "cargo-i18n" | ||
path = "src/main.rs" |
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,62 @@ | ||
use anyhow::Error; | ||
use clap::{Args, Parser}; | ||
|
||
use std::{collections::HashMap, path::Path}; | ||
|
||
use rust_i18n_extract::{extractor, generator, iter}; | ||
mod config; | ||
|
||
#[derive(Parser)] | ||
#[command(name = "cargo")] | ||
#[command(bin_name = "cargo")] | ||
enum CargoCli { | ||
I18n(I18nArgs), | ||
} | ||
|
||
#[derive(Args)] | ||
#[command(author, version)] | ||
// #[command(propagate_version = true)] | ||
/// Rust I18n command to help you extract all untranslated texts from source code. | ||
/// | ||
/// It will iterate all Rust files in the source directory and extract all untranslated texts | ||
/// that used `t!` macro. | ||
/// Then it will generate a YAML file and merge with the existing translations. | ||
/// | ||
/// https://github.com/longbridgeapp/rust-i18n | ||
struct I18nArgs { | ||
/// Extract all untranslated I18n texts from source code | ||
#[arg(default_value = "./")] | ||
source: Option<String>, | ||
} | ||
|
||
fn main() -> Result<(), Error> { | ||
let CargoCli::I18n(args) = CargoCli::parse(); | ||
|
||
let mut results = HashMap::new(); | ||
|
||
let source_path = args.source.expect("Missing source path"); | ||
|
||
let cfg = config::load(std::path::Path::new(&source_path))?; | ||
|
||
iter::iter_crate(&source_path, |path, source| { | ||
extractor::extract(&mut results, path, source) | ||
})?; | ||
|
||
let mut messages: Vec<_> = results.values().collect(); | ||
messages.sort_by_key(|m| m.index); | ||
|
||
let mut has_error = false; | ||
|
||
let output_path = Path::new(&source_path).join(&cfg.load_path); | ||
|
||
let result = generator::generate(&output_path, &cfg.available_locales, messages.clone()); | ||
if result.is_err() { | ||
has_error = true; | ||
} | ||
|
||
if has_error { | ||
std::process::exit(1); | ||
} | ||
|
||
Ok(()) | ||
} |
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
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
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
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.