1010
1111from  .const  import  CLI_2_DOCKER_IMAGE , CORE_PROJECT_ID , INTEGRATIONS_DIR 
1212from  .error  import  ExitApp 
13- from  .util  import  get_lokalise_token , load_json_from_path 
13+ from  .util  import  (
14+     flatten_translations ,
15+     get_lokalise_token ,
16+     load_json_from_path ,
17+     substitute_references ,
18+ )
1419
1520DOWNLOAD_DIR  =  Path ("build/translations-download" ).absolute ()
1621
1722
18- def  run_download_docker ():
23+ def  run_download_docker ()  ->   None :
1924    """Run the Docker image to download the translations.""" 
2025    print ("Running Docker to download latest translations." )
2126    result  =  subprocess .run (
@@ -39,6 +44,7 @@ def run_download_docker():
3944            "--replace-breaks=false" ,
4045            "--filter-data" ,
4146            "nonfuzzy" ,
47+             "--disable-references" ,
4248            "--export-empty-as" ,
4349            "skip" ,
4450            "--format" ,
@@ -76,9 +82,12 @@ def filter_translations(translations: dict[str, Any], strings: dict[str, Any]) -
7682                continue 
7783
7884
79- def  save_language_translations (lang , translations ) :
85+ def  save_language_translations (lang :  str , translations :  dict [ str ,  Any ])  ->   None :
8086    """Save translations for a single language.""" 
8187    components  =  translations .get ("component" , {})
88+ 
89+     flattened_translations  =  flatten_translations (translations )
90+ 
8291    for  component , component_translations  in  components .items ():
8392        # Remove legacy platform translations 
8493        component_translations .pop ("platform" , None )
@@ -104,26 +113,30 @@ def save_language_translations(lang, translations):
104113        path  =  component_path  /  "translations"  /  f"{ lang }  
105114        path .parent .mkdir (parents = True , exist_ok = True )
106115
116+         component_translations  =  substitute_references (
117+             component_translations , flattened_translations , fail_on_missing = False 
118+         )
119+ 
107120        filter_translations (component_translations , strings )
108121
109122        save_json (path , component_translations )
110123
111124
112- def  save_integrations_translations ():
125+ def  save_integrations_translations ()  ->   None :
113126    """Save integrations translations.""" 
114127    for  lang_file  in  DOWNLOAD_DIR .glob ("*.json" ):
115128        lang  =  lang_file .stem 
116129        translations  =  load_json_from_path (lang_file )
117130        save_language_translations (lang , translations )
118131
119132
120- def  delete_old_translations ():
133+ def  delete_old_translations ()  ->   None :
121134    """Delete old translations.""" 
122135    for  fil  in  INTEGRATIONS_DIR .glob ("*/translations/*" ):
123136        fil .unlink ()
124137
125138
126- def  run ():
139+ def  run ()  ->   None :
127140    """Run the script.""" 
128141    DOWNLOAD_DIR .mkdir (parents = True , exist_ok = True )
129142
0 commit comments