@@ -184,19 +184,25 @@ def reconcile_changed_sources(stringsdata_dir:)
184184 reconciled . count
185185 end
186186
187- # Current English value per key, by syncing the extraction into a throwaway empty catalog (every key is
188- # 'new', so its English is populated straight from source — which is what `sync` won't do for keys that
189- # already exist in the real catalog) .
190- def current_english_values ( stringsdata_dir )
187+ # Syncs the extracted .stringsdata into a fresh throwaway catalog and returns it parsed. A fresh
188+ # catalog means every key is 'new', so its English value is populated straight from source — which
189+ # is what `sync` won't do for keys that already exist in a persistent catalog.
190+ def synced_throwaway_catalog ( stringsdata_dir : )
191191 Dir . mktmpdir do |tmp |
192192 fresh = File . join ( tmp , 'Localizable.xcstrings' )
193193 File . write ( fresh , "#{ JSON . pretty_generate ( 'sourceLanguage' => 'en' , 'strings' => { } , 'version' => '1.0' ) } \n " )
194194 stringsdata = stringsdata_files ( stringsdata_dir )
195+ UI . user_error! ( 'xcstringstool produced no .stringsdata' ) if stringsdata . empty?
195196 sh ( 'xcrun' , 'xcstringstool' , 'sync' , fresh , *stringsdata . flat_map { |f | [ '--stringsdata' , f ] } )
196- english_values ( JSON . parse ( File . read ( fresh ) ) )
197+ JSON . parse ( File . read ( fresh ) )
197198 end
198199 end
199200
201+ # Current English value per key, from a throwaway-catalog sync of the extraction.
202+ def current_english_values ( stringsdata_dir )
203+ english_values ( synced_throwaway_catalog ( stringsdata_dir : stringsdata_dir ) )
204+ end
205+
200206 # { key => English value } for every catalog entry that has one (skips key-as-source entries).
201207 def english_values ( catalog )
202208 catalog [ 'strings' ] . each_with_object ( { } ) do |( key , entry ) , acc |
@@ -237,21 +243,13 @@ def report_catalog(path, extracted_count:, reconciled_count:)
237243 PluralStrings . serialize_legacy_strings ( entries . sort . to_h ) # sorted for stable output
238244 end
239245
240- # { key => { value:, comment: } } from a scoped extraction, via a throwaway catalog (like
241- # current_english_values). Entries without an explicit English value are interpolation-only
246+ # { key => { value:, comment: } } from a scoped extraction, via `synced_throwaway_catalog`.
247+ # Entries without an explicit English value are interpolation-only
242248 # resources (e.g. DisplayRepresentation(title: "\(name)")) — not translatable text — and are skipped.
243249 def app_intents_entries ( stringsdata_dir :)
244- Dir . mktmpdir do |tmp |
245- fresh = File . join ( tmp , 'Localizable.xcstrings' )
246- File . write ( fresh , "#{ JSON . pretty_generate ( 'sourceLanguage' => 'en' , 'strings' => { } , 'version' => '1.0' ) } \n " )
247- stringsdata = stringsdata_files ( stringsdata_dir )
248- UI . user_error! ( 'xcstringstool produced no .stringsdata for the App Intents sources' ) if stringsdata . empty?
249- sh ( 'xcrun' , 'xcstringstool' , 'sync' , fresh , *stringsdata . flat_map { |f | [ '--stringsdata' , f ] } )
250-
251- JSON . parse ( File . read ( fresh ) ) [ 'strings' ] . each_with_object ( { } ) do |( key , entry ) , acc |
252- value = entry . dig ( 'localizations' , 'en' , 'stringUnit' , 'value' )
253- acc [ key ] = { value : positionalize_untyped_arguments ( value ) , comment : entry [ 'comment' ] } unless value . nil?
254- end
250+ synced_throwaway_catalog ( stringsdata_dir : stringsdata_dir ) [ 'strings' ] . each_with_object ( { } ) do |( key , entry ) , acc |
251+ value = entry . dig ( 'localizations' , 'en' , 'stringUnit' , 'value' )
252+ acc [ key ] = { value : positionalize_untyped_arguments ( value ) , comment : entry [ 'comment' ] } unless value . nil?
255253 end
256254 end
257255
0 commit comments