@@ -161,6 +161,30 @@ impl TryFrom<Format> for Vec<Resource> {
161161 custom : custom. clone ( ) ,
162162 } ) ;
163163 }
164+ } else {
165+ // Preserve non-translatable metadata-only entries by attaching an empty
166+ // do-not-translate entry to source language.
167+ let source_language = custom_meta
168+ . get ( "source_language" )
169+ . cloned ( )
170+ . unwrap_or_else ( || "en" . to_string ( ) ) ;
171+ resource_map
172+ . entry ( source_language. clone ( ) )
173+ . or_insert ( Resource {
174+ metadata : Metadata {
175+ language : source_language,
176+ domain : String :: default ( ) ,
177+ custom : custom_meta. clone ( ) ,
178+ } ,
179+ entries : Vec :: new ( ) ,
180+ } )
181+ . add_entry ( Entry {
182+ id : id. clone ( ) ,
183+ value : Translation :: Empty ,
184+ comment : item. comment . clone ( ) ,
185+ status : EntryStatus :: DoNotTranslate ,
186+ custom : custom. clone ( ) ,
187+ } ) ;
164188 }
165189 continue ;
166190 }
@@ -552,4 +576,53 @@ mod tests {
552576 assert_eq ! ( empty_entry. comment. as_deref( ) , Some ( "Missing translation" ) ) ;
553577 }
554578 }
579+
580+ #[ test]
581+ fn test_non_translatable_item_without_localizations_is_preserved ( ) {
582+ let mut strings = HashMap :: new ( ) ;
583+ strings. insert (
584+ "game_title" . to_string ( ) ,
585+ Item {
586+ localizations : {
587+ let mut localizations = HashMap :: new ( ) ;
588+ localizations. insert (
589+ "en" . to_string ( ) ,
590+ Localization :: from ( StringUnit :: new ( EntryStatus :: Translated , "Game" ) ) ,
591+ ) ;
592+ localizations
593+ } ,
594+ comment : None ,
595+ extraction_state : None ,
596+ should_translate : Some ( true ) ,
597+ is_comment_auto_generated : None ,
598+ } ,
599+ ) ;
600+ strings. insert (
601+ "Carrom" . to_string ( ) ,
602+ Item {
603+ localizations : HashMap :: new ( ) ,
604+ comment : Some ( "The text label for the Carrom game button." . to_string ( ) ) ,
605+ extraction_state : None ,
606+ should_translate : Some ( false ) ,
607+ is_comment_auto_generated : Some ( true ) ,
608+ } ,
609+ ) ;
610+ let format = Format {
611+ source_language : "en" . to_string ( ) ,
612+ version : "1.0" . to_string ( ) ,
613+ strings,
614+ } ;
615+
616+ let resources = Vec :: < Resource > :: try_from ( format) . expect ( "resources from xcstrings" ) ;
617+ let roundtrip = Format :: try_from ( resources) . expect ( "xcstrings from resources" ) ;
618+ let carrom = roundtrip. strings . get ( "Carrom" ) . expect ( "Carrom item exists" ) ;
619+
620+ assert ! ( carrom. localizations. is_empty( ) ) ;
621+ assert_eq ! (
622+ carrom. comment. as_deref( ) ,
623+ Some ( "The text label for the Carrom game button." )
624+ ) ;
625+ assert_eq ! ( carrom. should_translate, Some ( false ) ) ;
626+ assert_eq ! ( carrom. is_comment_auto_generated, Some ( true ) ) ;
627+ }
555628}
0 commit comments