Skip to content

Commit e6a7f1f

Browse files
committed
feat(xcstrings): add empty translation entries for untranslated items
When an item has no localizations but should be translated, this change ensures an empty translation entry is added for each language. This helps maintain consistency in the resource map and supports workflows where untranslated items need explicit placeholders.
1 parent 5821d8a commit e6a7f1f

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

langcodec/src/formats/xcstrings.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,36 @@ impl TryFrom<Format> for Vec<Resource> {
129129
custom.insert("extraction_state".to_string(), extraction_state.to_string());
130130
}
131131

132+
if item.localizations.is_empty() {
133+
if item.should_translate.unwrap_or(true) {
134+
// If the item is empty and should be translated, add a new entry for each language
135+
//
136+
// This method requires that all languages are already present in the resource map, in
137+
// other words, the translated items must be presented above the untranslated items.
138+
let lang_codes = resource_map.keys().cloned().collect::<Vec<_>>();
139+
for lang_code in lang_codes {
140+
resource_map
141+
.entry(lang_code.clone())
142+
.or_insert(Resource {
143+
metadata: Metadata {
144+
language: lang_code.clone(),
145+
domain: String::default(),
146+
custom: custom_meta.clone(),
147+
},
148+
entries: Vec::new(),
149+
})
150+
.add_entry(Entry {
151+
id: id.clone(),
152+
value: Translation::Singular("".to_string()),
153+
comment: item.comment.clone(),
154+
status: EntryStatus::Translated,
155+
custom: custom.clone(),
156+
});
157+
}
158+
}
159+
continue;
160+
}
161+
132162
for (lang_code, localization) in item.localizations {
133163
if let Some(translation) = localization.to_translation() {
134164
let lang_code = lang_code.to_string();

0 commit comments

Comments
 (0)