@@ -330,7 +330,88 @@ def should_compile_file(self, gui, file: str, selected_files: list[str], python_
330330
331331 def apply_i18n (self , gui , tr : dict ) -> None :
332332 """Apply internationalization translations to the engine UI."""
333- pass
333+ try :
334+ from Core .engines_loader .registry import resolve_language_code
335+
336+ # Resolve language code
337+ code = resolve_language_code (gui , tr )
338+
339+ # Load engine-local translations
340+ lang_data = self ._load_language_file (code )
341+
342+ # Apply translations to UI elements if they exist
343+ if hasattr (self , "_opt_onefile" ) and "onefile_checkbox" in lang_data :
344+ self ._opt_onefile .setText (lang_data ["onefile_checkbox" ])
345+ if hasattr (self , "_opt_windowed" ) and "windowed_checkbox" in lang_data :
346+ self ._opt_windowed .setText (lang_data ["windowed_checkbox" ])
347+ if hasattr (self , "_opt_noconfirm" ) and "noconfirm_checkbox" in lang_data :
348+ self ._opt_noconfirm .setText (lang_data ["noconfirm_checkbox" ])
349+ if hasattr (self , "_opt_clean" ) and "clean_checkbox" in lang_data :
350+ self ._opt_clean .setText (lang_data ["clean_checkbox" ])
351+ if hasattr (self , "_opt_noupx" ) and "noupx_checkbox" in lang_data :
352+ self ._opt_noupx .setText (lang_data ["noupx_checkbox" ])
353+ if hasattr (self , "_opt_main_only" ) and "main_only_checkbox" in lang_data :
354+ self ._opt_main_only .setText (lang_data ["main_only_checkbox" ])
355+ if hasattr (self , "_btn_select_icon" ) and "icon_button" in lang_data :
356+ self ._btn_select_icon .setText (lang_data ["icon_button" ])
357+ if hasattr (self , "_opt_debug" ) and "debug_checkbox" in lang_data :
358+ self ._opt_debug .setText (lang_data ["debug_checkbox" ])
359+ if hasattr (self , "_pyinstaller_add_data" ) and "add_data_button" in lang_data :
360+ self ._pyinstaller_add_data .setText (lang_data ["add_data_button" ])
361+ if hasattr (self , "_output_dir_input" ) and "output_placeholder" in lang_data :
362+ self ._output_dir_input .setPlaceholderText (lang_data ["output_placeholder" ])
363+ except Exception :
364+ pass
365+
366+ def _load_language_file (self , code : str ) -> dict :
367+ """Load language file for the given code."""
368+ try :
369+ import importlib .resources as ilr
370+ import json
371+
372+ pkg = __package__
373+ lang_data = {}
374+
375+ # Try exact code first
376+ try :
377+ with ilr .as_file (
378+ ilr .files (pkg ).joinpath ("languages" , f"{ code } .json" )
379+ ) as p :
380+ if os .path .isfile (str (p )):
381+ with open (str (p ), encoding = "utf-8" ) as f :
382+ lang_data = json .load (f ) or {}
383+ return lang_data
384+ except Exception :
385+ pass
386+
387+ # Fallback to base language (e.g., "fr" from "fr-CA")
388+ if "-" in code :
389+ base = code .split ("-" , 1 )[0 ]
390+ try :
391+ with ilr .as_file (
392+ ilr .files (pkg ).joinpath ("languages" , f"{ base } .json" )
393+ ) as p :
394+ if os .path .isfile (str (p )):
395+ with open (str (p ), encoding = "utf-8" ) as f :
396+ lang_data = json .load (f ) or {}
397+ return lang_data
398+ except Exception :
399+ pass
400+
401+ # Final fallback to English
402+ try :
403+ with ilr .as_file (
404+ ilr .files (pkg ).joinpath ("languages" , "en.json" )
405+ ) as p :
406+ if os .path .isfile (str (p )):
407+ with open (str (p ), encoding = "utf-8" ) as f :
408+ lang_data = json .load (f ) or {}
409+ except Exception :
410+ pass
411+
412+ return lang_data
413+ except Exception :
414+ return {}
334415
335416 def add_data (self ) -> None :
336417 """Add data files or directories to be included with PyInstaller."""
0 commit comments