Skip to content

Commit

Permalink
Update to use serde_yml (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee authored Aug 9, 2024
1 parent b585131 commit 0e67913
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 17 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ license = "MIT"
name = "rust-i18n"
readme = "README.md"
repository = "https://github.com/longbridgeapp/rust-i18n"
version = "3.1.0"
version = "3.1.1"

[dependencies]
once_cell = "1.10.0"
rust-i18n-support = { path = "./crates/support", version = "3.0.1" }
rust-i18n-macro = { path = "./crates/macro", version = "3.0.0" }
rust-i18n-support = { path = "./crates/support", version = "3.1.1" }
rust-i18n-macro = { path = "./crates/macro", version = "3.1.1" }
smallvec = "1.12.0"

[dev-dependencies]
foo = { path = "examples/foo" }
criterion = "0.5"
lazy_static = "1"
serde_yaml = "0.8"
serde_yml = "0.0.11"

[build-dependencies]
globwalk = "0.8.1"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl RemoteI18n {
fn new() -> Self {
// fetch translations from remote URL
let response = reqwest::blocking::get("https://your-host.com/assets/locales.yml").unwrap();
let trs = serde_yaml::from_str::<HashMap<String, HashMap<String, String>>>(&response.text().unwrap()).unwrap();
let trs = serde_yml::from_str::<HashMap<String, HashMap<String, String>>>(&response.text().unwrap()).unwrap();
return Self {
trs
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license = "MIT"
name = "rust-i18n-cli"
readme = "../../README.md"
repository = "https://github.com/longbridgeapp/rust-i18n"
version = "3.1.0"
version = "3.1.1"

[dependencies]
anyhow = "1"
Expand Down
4 changes: 2 additions & 2 deletions crates/extract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license = "MIT"
name = "rust-i18n-extract"
readme = "../../README.md"
repository = "https://github.com/longbridgeapp/rust-i18n"
version = "3.1.0"
version = "3.1.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -18,7 +18,7 @@ regex = "1"
rust-i18n-support = { path = "../support", version = "3.0.0" }
serde = "1"
serde_json = "1"
serde_yaml = "0.8"
serde_yml = "0.0.11"
syn = { version = "2.0.18", features = ["full"] }
toml = "0.7.4"

Expand Down
2 changes: 1 addition & 1 deletion crates/extract/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn convert_text(trs: &Translations, format: &str) -> String {
match format {
"json" => serde_json::to_string_pretty(&value).unwrap(),
"yaml" | "yml" => {
let text = serde_yaml::to_string(&value).unwrap();
let text = serde_yml::to_string(&value).unwrap();
// Remove leading `---`
text.trim_start_matches("---").trim_start().to_string()
}
Expand Down
4 changes: 2 additions & 2 deletions crates/macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license = "MIT"
name = "rust-i18n-macro"
readme = "../../README.md"
repository = "https://github.com/longbridgeapp/rust-i18n"
version = "3.1.0"
version = "3.1.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -17,7 +17,7 @@ quote = "1.0.2"
rust-i18n-support = { path = "../support", version = "3.0.0" }
serde = "1"
serde_json = "1"
serde_yaml = "0.8"
serde_yml = "0.0.11"
syn = { version = "2.0.18", features = ["full", "extra-traits"] }

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions crates/support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license = "MIT"
name = "rust-i18n-support"
readme = "../../README.md"
repository = "https://github.com/longbridgeapp/rust-i18n"
version = "3.1.0"
version = "3.1.1"

[dependencies]
arc-swap = "1.6.0"
Expand All @@ -16,7 +16,7 @@ once_cell = "1.10.0"
proc-macro2 = "1.0"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_yaml = "0.8"
serde_yml = "0.0.11"
siphasher = "1.0"
toml = "0.7.4"
normpath = "1.1.1"
Expand Down
8 changes: 4 additions & 4 deletions crates/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub fn load_locales<F: Fn(&str) -> bool>(
// Parse Translations from file to support multiple formats
fn parse_file(content: &str, ext: &str, locale: &str) -> Result<Translations, String> {
let result = match ext {
"yml" | "yaml" => serde_yaml::from_str::<serde_json::Value>(content)
"yml" | "yaml" => serde_yml::from_str::<serde_json::Value>(content)
.map_err(|err| format!("Invalid YAML format, {}", err)),
"json" => serde_json::from_str::<serde_json::Value>(content)
.map_err(|err| format!("Invalid JSON format, {}", err)),
Expand Down Expand Up @@ -355,14 +355,14 @@ mod tests {

#[test]
fn test_get_version() {
let json = serde_yaml::from_str::<serde_json::Value>("_version: 2").unwrap();
let json = serde_yml::from_str::<serde_json::Value>("_version: 2").unwrap();
assert_eq!(super::get_version(&json), 2);

let json = serde_yaml::from_str::<serde_json::Value>("_version: 1").unwrap();
let json = serde_yml::from_str::<serde_json::Value>("_version: 1").unwrap();
assert_eq!(super::get_version(&json), 1);

// Default fallback to 1
let json = serde_yaml::from_str::<serde_json::Value>("foo: Foo").unwrap();
let json = serde_yml::from_str::<serde_json::Value>("foo: Foo").unwrap();
assert_eq!(super::get_version(&json), 1);
}

Expand Down

0 comments on commit 0e67913

Please sign in to comment.