@@ -118,10 +118,10 @@ def po2file(
118118 resulting_entries = []
119119 extract_fuzzy = CONFIG .extract_fuzzy
120120
121- for file_trans in trans_map [occurrence_path ]:
122- file_index = file_trans ["file_index" ]
123- po_index = file_trans ["po_index" ]
124- entry = po [po_index ]
121+ for file_trans in trans_map [occurrence_path ]:
122+ file_index = file_trans ["file_index" ]
123+ po_index = file_trans ["po_index" ]
124+ entry = po [po_index ]
125125
126126 if entry .msgstr == "" or ("fuzzy" in entry .flags and not extract_fuzzy ): # if not translated, keep msgid
127127 value = entry .msgid
@@ -135,13 +135,14 @@ def po2file(
135135 # context
136136 context = entry .msgctxt
137137
138- # female strings
139- female = None
140- if entry .msgid in female_map :
141- fe_entry = female_map [entry .msgid ]
142- if fe_entry .msgstr == "" or "fuzzy" in fe_entry .flags and not extract_fuzzy :
143- female = fe_entry .msgid
144- else :
138+ # female strings
139+ female = None
140+ female_occurrence = (occurrence_path , str (file_index ))
141+ if female_occurrence in female_map :
142+ fe_entry = female_map [female_occurrence ]
143+ if fe_entry .msgstr == "" or "fuzzy" in fe_entry .flags and not extract_fuzzy :
144+ female = fe_entry .msgid
145+ else :
145146 female = fe_entry .msgstr
146147
147148 resulting_entries .append ({"index" : file_index , "value" : value , "female" : female , "context" : context })
@@ -287,40 +288,42 @@ class FemaleUpdate:
287288
288289
289290@dataclass (frozen = True )
290- class NewFemaleEntry :
291- """A new female PO entry to append."""
292-
293- msgid : str
294- msgstr : str
295-
296-
297- def _compute_female_update (
298- e : polib .POEntry ,
299- female_value : str ,
300- female_map : dict [str , polib .POEntry ],
301- overwrite : bool ,
302- same : bool ,
303- ) -> FemaleUpdate | NewFemaleEntry | None :
304- """Decide what to do with a female translation value."""
305- if e .msgid in female_map :
306- fe = female_map [e .msgid ]
307- if not fe or fe .msgstr == female_value :
308- return None
309- logger .info (f"female translation change: ORIG: { e .msgid } | OLD: { fe .msgstr } | NEW: { female_value } " )
291+ class NewFemaleEntry :
292+ """A new female PO entry to append."""
293+
294+ msgid : str
295+ msgstr : str
296+ occurrence : tuple [str , str ]
297+
298+
299+ def _compute_female_update (
300+ e : polib .POEntry ,
301+ female_value : str ,
302+ female_map : dict [tuple [str , str ], polib .POEntry ],
303+ occurrence : tuple [str , str ],
304+ overwrite : bool ,
305+ same : bool ,
306+ ) -> FemaleUpdate | NewFemaleEntry | None :
307+ """Decide what to do with a female translation value."""
308+ if occurrence in female_map :
309+ fe = female_map [occurrence ]
310+ if not fe or fe .msgstr == female_value :
311+ return None
312+ logger .info (f"female translation change: ORIG: { e .msgid } | OLD: { fe .msgstr } | NEW: { female_value } " )
310313 if not overwrite :
311314 logger .debug ("Female translation already exists, overwrite disabled, skipping" )
312315 return None
313316 if e .msgid == female_value :
314317 if same :
315318 logger .info (f"source and female translation are the same, using regardless: { e .msgid } " )
316319 else :
317- logger .info (f"source and female translation are the same for { e .occurrences } , skipping" )
318- return None
319- return FemaleUpdate (entry = fe , new_msgstr = female_value , clear_fuzzy = "fuzzy" in fe .flags )
320- elif e .msgstr != female_value :
321- logger .info (f"new female translation detected: ORIG: { e .msgid } | MALE: { e .msgstr } | FEMALE: { female_value } " )
322- return NewFemaleEntry (msgid = e .msgid , msgstr = female_value )
323- return None
320+ logger .info (f"source and female translation are the same for { e .occurrences } , skipping" )
321+ return None
322+ return FemaleUpdate (entry = fe , new_msgstr = female_value , clear_fuzzy = "fuzzy" in fe .flags )
323+ elif e .msgstr != female_value :
324+ logger .info (f"new female translation detected: ORIG: { e .msgid } | MALE: { e .msgstr } | FEMALE: { female_value } " )
325+ return NewFemaleEntry (msgid = e .msgid , msgstr = female_value , occurrence = occurrence )
326+ return None
324327
325328
326329def _compute_entry_update (
@@ -364,13 +367,13 @@ def _compute_entry_update(
364367
365368
366369def compute_msgstr_updates (
367- trans_entries : list ,
368- occurrence_path : str ,
369- entries_dict : OrderedDict ,
370- female_map : dict [str , polib .POEntry ],
371- overwrite : bool ,
372- same : bool ,
373- extract_fuzzy : bool ,
370+ trans_entries : list ,
371+ occurrence_path : str ,
372+ entries_dict : OrderedDict ,
373+ female_map : dict [tuple [ str , str ] , polib .POEntry ],
374+ overwrite : bool ,
375+ same : bool ,
376+ extract_fuzzy : bool ,
374377) -> tuple [list [EntryUpdate ], list [FemaleUpdate ], list [NewFemaleEntry ]]:
375378 """Pure decision logic: compute what updates to apply without mutating anything."""
376379 entry_updates : list [EntryUpdate ] = []
@@ -385,13 +388,14 @@ def compute_msgstr_updates(
385388 if (occurrence_path , t .index ) not in entries_dict :
386389 continue
387390
388- e : polib .POEntry = entries_dict [(occurrence_path , t .index )]
389-
390- if t .female :
391- result = _compute_female_update (e , t .female , female_map , overwrite , same )
392- if isinstance (result , FemaleUpdate ):
393- female_updates .append (result )
394- elif isinstance (result , NewFemaleEntry ):
391+ e : polib .POEntry = entries_dict [(occurrence_path , t .index )]
392+ occurrence = (occurrence_path , t .index )
393+
394+ if t .female :
395+ result = _compute_female_update (e , t .female , female_map , occurrence , overwrite , same )
396+ if isinstance (result , FemaleUpdate ):
397+ female_updates .append (result )
398+ elif isinstance (result , NewFemaleEntry ):
395399 new_females .append (result )
396400
397401 update = _compute_entry_update (e , t .value , t .context , overwrite , same , extract_fuzzy )
@@ -424,8 +428,8 @@ def apply_msgstr_updates(
424428 fu .entry .flags .remove ("fuzzy" )
425429 fu .entry .previous_msgid = None
426430
427- for nf in new_females :
428- po .append (polib .POEntry (msgid = nf .msgid , msgstr = nf .msgstr , msgctxt = CONTEXT_FEMALE ))
431+ for nf in new_females :
432+ po .append (polib .POEntry (msgid = nf .msgid , msgstr = nf .msgstr , msgctxt = CONTEXT_FEMALE , occurrences = [ nf . occurrence ] ))
429433
430434
431435def file2msgstr (
0 commit comments