Skip to content

Commit bfd36d6

Browse files
committed
fix(core): preserve xcstrings isCommentAutoGenerated on edit set
1 parent 787484c commit bfd36d6

2 files changed

Lines changed: 61 additions & 1 deletion

File tree

langcodec-cli/tests/edit_cli_tests.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,57 @@ fn test_edit_set_xcstrings_with_lang_preserves_other_languages() {
451451
"Au revoir"
452452
);
453453
}
454+
455+
#[test]
456+
fn test_edit_set_xcstrings_preserves_is_comment_auto_generated() {
457+
let temp_dir = TempDir::new().unwrap();
458+
let input_file = temp_dir.path().join("Localizable.xcstrings");
459+
let initial = r#"{
460+
"sourceLanguage": "en",
461+
"version": "1.0",
462+
"strings": {
463+
"hello": {
464+
"localizations": {
465+
"en": {
466+
"stringUnit": {
467+
"state": "translated",
468+
"value": "Hello"
469+
}
470+
}
471+
},
472+
"isCommentAutoGenerated": true
473+
}
474+
}
475+
}
476+
"#;
477+
fs::write(&input_file, initial).unwrap();
478+
479+
let out = langcodec_cmd()
480+
.args([
481+
"edit",
482+
"set",
483+
"-i",
484+
input_file.to_str().unwrap(),
485+
"--lang",
486+
"en",
487+
"-k",
488+
"hello",
489+
"-v",
490+
"Hello Updated",
491+
])
492+
.output()
493+
.unwrap();
494+
assert!(
495+
out.status.success(),
496+
"stderr: {}",
497+
String::from_utf8_lossy(&out.stderr)
498+
);
499+
500+
let content = fs::read_to_string(&input_file).unwrap();
501+
let payload: serde_json::Value = serde_json::from_str(&content).unwrap();
502+
503+
assert_eq!(
504+
payload["strings"]["hello"]["isCommentAutoGenerated"],
505+
serde_json::Value::Bool(true)
506+
);
507+
}

langcodec/src/formats/xcstrings.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ impl TryFrom<Format> for Vec<Resource> {
128128
if let Some(extraction_state) = &item.extraction_state {
129129
custom.insert("extraction_state".to_string(), extraction_state.to_string());
130130
}
131+
if let Some(is_comment_auto_generated) = item.is_comment_auto_generated {
132+
custom.insert(
133+
"is_comment_auto_generated".to_string(),
134+
is_comment_auto_generated.to_string(),
135+
);
136+
}
131137

132138
if item.localizations.is_empty() {
133139
if item.should_translate.unwrap_or(true) {
@@ -177,7 +183,7 @@ impl TryFrom<Format> for Vec<Resource> {
177183
value: translation,
178184
comment: item.comment.clone(),
179185
status: localization.state(),
180-
custom: custom.clone(), // No custom data in xcstrings
186+
custom: custom.clone(),
181187
});
182188
}
183189
}

0 commit comments

Comments
 (0)