Skip to content

Commit d3c5141

Browse files
committed
Merge pull request #111298 from Onebit5/fix-filedialog-translation-parser
Fix GDScript translation parser for FileDialog.add_filter() two-parameter format
2 parents 4ad11b6 + d223b0c commit d3c5141

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

modules/gdscript/editor/gdscript_translation_parser_plugin.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,14 @@ void GDScriptEditorTranslationParserPlugin::_assess_call(const GDScriptParser::C
383383
_add_id(p_call->arguments[1]->reduced_value, p_call->arguments[1]->start_line);
384384
}
385385
} else if (function_name == fd_add_filter) {
386-
// Extract the 'JPE Images' in this example - get_node("FileDialog").add_filter("*.jpg; JPE Images").
387-
if (!p_call->arguments.is_empty()) {
386+
if (p_call->arguments.size() == 1) {
387+
// The first parameter may contain a description, like `"*.jpg; JPEG Images"`.
388388
_extract_fd_filter_string(p_call->arguments[0], p_call->arguments[0]->start_line);
389+
} else if (p_call->arguments.size() >= 2) {
390+
// The second optional parameter can be a description.
391+
if (_is_constant_string(p_call->arguments[1])) {
392+
_add_id(p_call->arguments[1]->reduced_value, p_call->arguments[1]->start_line);
393+
}
389394
}
390395
} else if (function_name == fd_set_filter) {
391396
// Extract from `get_node("FileDialog").set_filters(<filter array>)`.
@@ -396,11 +401,16 @@ void GDScriptEditorTranslationParserPlugin::_assess_call(const GDScriptParser::C
396401
}
397402

398403
void GDScriptEditorTranslationParserPlugin::_extract_fd_filter_string(const GDScriptParser::ExpressionNode *p_expression, int p_line) {
399-
// Extract the name in "extension ; name".
404+
// Extract the description from `"filter; Description"` format.
405+
// The description part is optional, so we skip if it's missing or empty.
400406
if (_is_constant_string(p_expression)) {
401-
PackedStringArray arr = p_expression->reduced_value.operator String().split(";", true);
402-
ERR_FAIL_COND_MSG(arr.size() != 2, "Argument for setting FileDialog has bad format.");
403-
_add_id(arr[1].strip_edges(), p_line);
407+
const PackedStringArray arr = p_expression->reduced_value.operator String().split(";", true, 1);
408+
if (arr.size() >= 2) {
409+
const String description = arr[1].strip_edges();
410+
if (!description.is_empty()) {
411+
_add_id(description, p_line);
412+
}
413+
}
404414
}
405415
}
406416

0 commit comments

Comments
 (0)