@@ -969,65 +969,11 @@ def _browse_icon():
969969 def apply_i18n (self , gui , tr : dict [str , str ]) -> None :
970970 """Apply engine-local i18n from ENGINES/cx_freeze/languages/*.json independent of app languages."""
971971 try :
972- # Resolve language code preference
973- code = None
974- try :
975- if isinstance (tr , dict ):
976- meta = tr .get ("_meta" , {})
977- code = meta .get ("code" ) if isinstance (meta , dict ) else None
978- except Exception :
979- code = None
980- if not code :
981- try :
982- # Try GUI preferences
983- pref = getattr (
984- gui , "language_pref" , getattr (gui , "language" , "System" )
985- )
986- if isinstance (pref , str ) and pref != "System" :
987- code = pref
988- except Exception :
989- pass
990- # Fallback
991- if not code :
992- code = "en"
993- # Normalize codes and build robust fallback candidates
994- raw = str (code )
995- low = raw .lower ().replace ("_" , "-" )
996- aliases = {
997- "en-us" : "en" ,
998- "en_gb" : "en" ,
999- "en-uk" : "en" ,
1000- "fr-fr" : "fr" ,
1001- "fr_ca" : "fr" ,
1002- "fr-ca" : "fr" ,
1003- "pt-br" : "pt-BR" ,
1004- "pt_br" : "pt-BR" ,
1005- "zh" : "zh-CN" ,
1006- "zh_cn" : "zh-CN" ,
1007- "zh-cn" : "zh-CN" ,
1008- }
1009- mapped = aliases .get (low , raw )
1010- # Candidate order: mapped -> base (before '-') -> exact lower -> exact raw -> 'en'
1011- candidates = []
1012- if mapped not in candidates :
1013- candidates .append (mapped )
1014- base = None
1015- try :
1016- if "-" in mapped :
1017- base = mapped .split ("-" , 1 )[0 ]
1018- elif "_" in mapped :
1019- base = mapped .split ("_" , 1 )[0 ]
1020- except Exception :
1021- base = None
1022- if base and base not in candidates :
1023- candidates .append (base )
1024- if low not in candidates :
1025- candidates .append (low )
1026- if raw not in candidates :
1027- candidates .append (raw )
1028- if "en" not in candidates :
1029- candidates .append ("en" )
1030- # Load engine-local JSON using the first existing candidate
972+ from Core .engines_loader .registry import resolve_language_code
973+
974+ code = resolve_language_code (gui , tr )
975+
976+ # Load engine-local JSON using the resolved code
1031977 import importlib .resources as ilr
1032978 import json as _json
1033979
@@ -1048,6 +994,18 @@ def _load_lang(c: str) -> bool:
1048994 pass
1049995 return False
1050996
997+ # Build candidates from resolved code
998+ candidates = [code ]
999+ try :
1000+ if "-" in code :
1001+ base = code .split ("-" , 1 )[0 ]
1002+ if base not in candidates :
1003+ candidates .append (base )
1004+ except Exception :
1005+ pass
1006+ if "en" not in candidates :
1007+ candidates .append ("en" )
1008+
10511009 for cand in candidates :
10521010 if _load_lang (cand ):
10531011 break
0 commit comments