@@ -16,31 +16,31 @@ static func import_dialogue_text_translation(file_type: ParleyImportModal.FileTy
1616 return [ERR_INVALID_DATA if file_result == OK else file_result , message ]
1717
1818 var index : int = 0
19- var key : StringName = ParleyUtils .translation .get_csv_key_name ()
19+ var key_name : StringName = ParleyUtils .translation .get_csv_key_name ()
2020 var locale : StringName = ParleyUtils .translation .get_locale ()
21- var headers : PackedStringArray = PackedStringArray ([key , locale ])
21+ var headers : PackedStringArray = PackedStringArray ([key_name , locale ])
2222 const key_index : int = 0
23- var translation_index : int = 1
23+ var project_locale_column_index : int = headers . find ( locale )
2424 var lines_map : Dictionary [String , String ] = {}
2525 while ! file .eof_reached ():
2626 var line : PackedStringArray = file .get_csv_line ()
2727 if line .size () >= 2 and line [0 ] != "" :
2828 if index == 0 :
2929 headers = line
30- var found_translation_index : int = headers .find (locale )
30+ project_locale_column_index = headers .find (locale )
3131 # We assume that key index is always 0
32- if found_translation_index > key_index :
32+ if project_locale_column_index > key_index :
3333 pass
3434 else :
3535 var message : String = "Unable to import: cannot find valid translation index: (headers:%s , line:%s , locale:%s )" % [headers , line , locale ]
3636 push_error (ParleyUtils .log .error_msg (message ))
3737 file .close ()
3838 return [ERR_INVALID_DATA , message ]
39- elif line .size () >= translation_index :
40- var translation_field : String = line [translation_index ]
39+ elif project_locale_column_index >= 0 and project_locale_column_index < line .size ():
40+ var translation_field : String = line [project_locale_column_index ]
4141 lines_map [line [key_index ]] = translation_field
4242 else :
43- var message : String = "Unable to import: cannot find valid translation field: (headers:%s , line:%s , locale:%s )" % [headers , line , locale ]
43+ var message : String = "Unable to import: cannot find valid translation field matching the project locale : (headers:%s , line:%s , locale:%s )" % [headers , line , locale ]
4444 push_error (ParleyUtils .log .error_msg (message ))
4545 file .close ()
4646 return [ERR_INVALID_DATA , message ]
@@ -49,10 +49,17 @@ static func import_dialogue_text_translation(file_type: ParleyImportModal.FileTy
4949
5050 var updated : bool = false
5151 for node_ast : ParleyNodeAst in dialogue_sequence_ast .nodes :
52+ if not [ParleyDialogueSequenceAst .Type .DIALOGUE , ParleyDialogueSequenceAst .Type .DIALOGUE_OPTION ].has (node_ast .type ):
53+ continue
54+
5255 var field : StringName = & "text"
5356 var text_translation_key : String = ParleyUtils .translation .get_msg_ctx (node_ast , field )
54- var updated_text : String = lines_map .get (text_translation_key , "" )
55- if text_translation_key and updated_text and is_instance_of (updated_text , TYPE_STRING ):
57+ var text : String = node_ast .get ("text" ) if node_ast .get ("text" ) else ""
58+ var key : String = text_translation_key if text_translation_key else text
59+ var updated_text : String = lines_map .get (key , "" )
60+ if updated_text and is_instance_of (updated_text , TYPE_STRING ) and text != updated_text :
61+ if not text_translation_key :
62+ ParleyUtils .translation .set_msg_ctx (node_ast , field , key )
5663 node_ast .set (field , updated_text )
5764 updated = true
5865
0 commit comments