Skip to content

Commit 6c6d77f

Browse files
committed
feat(debug): enhance JSON output by replacing escaped newlines
- Updated the `run_debug_command` function to replace escaped newline characters (`\\n`) with actual newlines (`\n`) in the resource entries. - This change improves the readability of the JSON output, making it more user-friendly and easier to work with for developers.
1 parent fa4905b commit 6c6d77f

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

langcodec-cli/src/debug.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::formats::parse_custom_format;
22
use crate::transformers::custom_format_to_resource;
33

4-
use langcodec::Codec;
4+
use langcodec::{Codec, Plural, Translation};
55
use std::fs::File;
66
use std::io::{self, Write};
77

@@ -40,6 +40,24 @@ pub fn run_debug_command(input: String, lang: Option<String>, output: Option<Str
4040
eprintln!("✅ Resources validated successfully");
4141
}
4242

43+
// Replace \\n with \n in the resources
44+
for resource in &mut codec.resources {
45+
for entry in &mut resource.entries {
46+
entry.value = match &entry.value {
47+
Translation::Singular(v) => Translation::Singular(v.replace("\\n", "\n")),
48+
Translation::Plural(p) => Translation::Plural(Plural {
49+
id: p.id.clone(),
50+
forms: p
51+
.forms
52+
.clone()
53+
.into_iter()
54+
.map(|(k, v)| (k, v.replace("\\n", "\n")))
55+
.collect(),
56+
}),
57+
};
58+
}
59+
}
60+
4361
// Convert to JSON
4462
eprintln!("Converting to JSON...");
4563
let json = serde_json::to_string_pretty(&*codec.resources).unwrap_or_else(|e| {

0 commit comments

Comments
 (0)