55
66from __future__ import annotations
77
8- import os
9- from collections import OrderedDict
10- from dataclasses import dataclass
11- from typing import TYPE_CHECKING
8+ import os
9+ from collections import OrderedDict
10+ from dataclasses import dataclass
11+ from pathlib import Path
12+ from typing import TYPE_CHECKING
1213
1314if TYPE_CHECKING :
1415 from msg2po .indexed_po import IndexedPO
@@ -184,14 +185,18 @@ def po2file(
184185 # what's out path?
185186 female_file = get_female_filepath (output_file , dst_dir , same )
186187
187- # If need to create the file
188- if same : # if female translation is the same?
189- if female_file is None : # don't need to copy, automatic fallback
190- logger .debug (f"Female strings are same, not copying - sfall will fallback to male { occurrence_path } " )
191- return
192- else :
193- logger .debug (f"Female strings are same, copying to { female_file } " )
194- copycreate (output_file , female_file )
188+ # If need to create the file
189+ if same : # if female translation is the same?
190+ if female_file is None : # don't need to copy, automatic fallback
191+ stale_female = get_stale_female_filepath (output_file )
192+ if stale_female is not None and Path (stale_female ).exists ():
193+ logger .debug (f"Female strings are same, deleting stale female file { stale_female } " )
194+ Path (stale_female ).unlink ()
195+ logger .debug (f"Female strings are same, not copying - sfall will fallback to male { occurrence_path } " )
196+ return
197+ else :
198+ logger .debug (f"Female strings are same, copying to { female_file } " )
199+ copycreate (output_file , female_file )
195200 else : # if it's different, extract separately
196201 if female_file is None :
197202 logger .warning (
@@ -205,7 +210,7 @@ def po2file(
205210 file2 .writelines (lines_female )
206211
207212
208- def get_female_filepath (path : str , dst_dir : str , same : bool = True ) -> str | None :
213+ def get_female_filepath (path : str , dst_dir : str , same : bool = True ) -> str | None :
209214 """Determine female file path based on format and sfall conventions."""
210215 # default: just add _female suffix
211216 female_path : str | None = path .replace (dst_dir + os .sep , dst_dir + CONFIG .female_dir_suffix + os .sep )
@@ -214,8 +219,17 @@ def get_female_filepath(path: str, dst_dir: str, same: bool = True) -> str | Non
214219 if "cuts" in path .split (os .sep ): # cuts dont' fallback
215220 female_path = path .replace (os .sep + "cuts" + os .sep , os .sep + "cuts_female" + os .sep )
216221 if "dialog" in path .split (os .sep ) and not same : # dialog, female translation differs
217- female_path = path .replace (os .sep + "dialog" + os .sep , os .sep + "dialog_female" + os .sep )
218- return female_path
222+ female_path = path .replace (os .sep + "dialog" + os .sep , os .sep + "dialog_female" + os .sep )
223+ return female_path
224+
225+
226+ def get_stale_female_filepath (path : str ) -> str | None :
227+ """Return the stale dialog_female path to remove when sfall falls back to male."""
228+ if CONFIG .extract_format != "sfall" :
229+ return None
230+ if "dialog" not in path .split (os .sep ):
231+ return None
232+ return path .replace (os .sep + "dialog" + os .sep , os .sep + "dialog_female" + os .sep )
219233
220234
221235def get_line_format (e , ext : str ):
0 commit comments