@@ -21,9 +21,7 @@ Description
2121
2222**EditorTranslationParserPlugin ** is invoked when a file is being parsed to extract strings that require translation. To define the parsing and string extraction logic, override the :ref: `_parse_file()<class_EditorTranslationParserPlugin_private_method__parse_file> ` method in script.
2323
24- Add the extracted strings to argument ``msgids `` or ``msgids_context_plural `` if context or plural is used.
25-
26- When adding to ``msgids_context_plural ``, you must add the data using the format ``["A", "B", "C"] ``, where ``A `` represents the extracted string, ``B `` represents the context, and ``C `` represents the plural version of the extracted string. If you want to add only context but not plural, put ``"" `` for the plural slot. The idea is the same if you only want to add plural but not context. See the code below for concrete examples.
24+ The return value should be an :ref: `Array<class_Array> ` of :ref: `PackedStringArray<class_PackedStringArray> `\ s, one for each extracted translatable string. Each entry should contain ``[msgid, msgctxt, msgid_plural, comment] ``, where all except ``msgid `` are optional. Empty strings will be ignored.
2725
2826The extracted strings will be written into a POT file selected by user under "POT Generation" in "Localization" tab in "Project Settings" menu.
2927
@@ -37,14 +35,17 @@ Below shows an example of a custom parser that extracts strings from a CSV file
3735 @tool
3836 extends EditorTranslationParserPlugin
3937
40- func _parse_file(path, msgids, msgids_context_plural):
38+ func _parse_file(path):
39+ var ret: Array[PackedStringArray] = []
4140 var file = FileAccess.open(path, FileAccess.READ)
4241 var text = file.get_as_text()
4342 var split_strs = text.split(",", false)
4443 for s in split_strs:
45- msgids.append(s )
44+ msgids.append(PackedStringArray([s]) )
4645 #print("Extracted string: " + s)
4746
47+ return ret
48+
4849 func _get_recognized_extensions():
4950 return ["csv"]
5051
@@ -55,16 +56,18 @@ Below shows an example of a custom parser that extracts strings from a CSV file
5556 [Tool]
5657 public partial class CustomParser : EditorTranslationParserPlugin
5758 {
58- public override void _ParseFile(string path, Godot.Collections.Array<string> msgids, Godot.Collections.Array<Godot.Collections.Array> msgidsContextPlural )
59+ public override Godot.Collections.Array<string[]> _ParseFile(string path )
5960 {
61+ Godot.Collections.Array<string[]> ret;
6062 using var file = FileAccess.Open(path, FileAccess.ModeFlags.Read);
6163 string text = file.GetAsText();
6264 string[] splitStrs = text.Split(",", allowEmpty: false);
6365 foreach (string s in splitStrs)
6466 {
65- msgids .Add(s );
67+ ret .Add([s] );
6668 //GD.Print($"Extracted string: {s}");
6769 }
70+ return ret;
6871 }
6972
7073 public override string[] _GetRecognizedExtensions()
@@ -75,28 +78,28 @@ Below shows an example of a custom parser that extracts strings from a CSV file
7578
7679
7780
78- To add a translatable string associated with context or plural, add it to `` msgids_context_plural `` :
81+ To add a translatable string associated with a context, plural, or comment :
7982
8083
8184.. tabs ::
8285
8386 .. code-tab :: gdscript
8487
85- # This will add a message with msgid "Test 1", msgctxt "context", and msgid_plural "test 1 plurals".
86- msgids_context_plural .append(["Test 1", "context", "test 1 plurals"] )
88+ # This will add a message with msgid "Test 1", msgctxt "context", msgid_plural "test 1 plurals", and comment "test 1 comment ".
89+ ret .append(PackedStringArray( ["Test 1", "context", "test 1 plurals", "test 1 comment"]) )
8790 # This will add a message with msgid "A test without context" and msgid_plural "plurals".
88- msgids_context_plural .append(["A test without context", "", "plurals"])
91+ ret .append(PackedStringArray( ["A test without context", "", "plurals"]) )
8992 # This will add a message with msgid "Only with context" and msgctxt "a friendly context".
90- msgids_context_plural .append(["Only with context", "a friendly context", ""] )
93+ ret .append(PackedStringArray( ["Only with context", "a friendly context"]) )
9194
9295 .. code-tab :: csharp
9396
94- // This will add a message with msgid "Test 1", msgctxt "context", and msgid_plural "test 1 plurals".
95- msgidsContextPlural .Add(["Test 1", "context", "test 1 Plurals "]);
97+ // This will add a message with msgid "Test 1", msgctxt "context", msgid_plural "test 1 plurals", and comment "test 1 comment ".
98+ ret .Add(["Test 1", "context", "test 1 plurals", "test 1 comment "]);
9699 // This will add a message with msgid "A test without context" and msgid_plural "plurals".
97- msgidsContextPlural .Add(["A test without context", "", "plurals"]);
100+ ret .Add(["A test without context", "", "plurals"]);
98101 // This will add a message with msgid "Only with context" and msgctxt "a friendly context".
99- msgidsContextPlural .Add(["Only with context", "a friendly context", " "]);
102+ ret .Add(["Only with context", "a friendly context"]);
100103
101104
102105
@@ -107,7 +110,7 @@ To add a translatable string associated with context or plural, add it to ``msgi
107110
108111 .. code-tab :: gdscript
109112
110- func _parse_file(path, msgids, msgids_context_plural ):
113+ func _parse_file(path):
111114 var res = ResourceLoader.load(path, "Script")
112115 var text = res.source_code
113116 # Parsing logic.
@@ -117,7 +120,7 @@ To add a translatable string associated with context or plural, add it to ``msgi
117120
118121 .. code-tab :: csharp
119122
120- public override void _ParseFile(string path, Godot.Collections.Array<string> msgids, Godot.Collections.Array<Godot.Collections.Array> msgidsContextPlural )
123+ public override Godot.Collections.Array<string[]> _ParseFile(string path )
121124 {
122125 var res = ResourceLoader.Load<Script>(path, "Script");
123126 string text = res.SourceCode;
@@ -141,13 +144,11 @@ Methods
141144.. table ::
142145 :widths: auto
143146
144- +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
145- | |void | | :ref: `_get_comments<class_EditorTranslationParserPlugin_private_method__get_comments> `\ (\ msgids_comment\: :ref: `Array<class_Array> `\[ :ref: `String<class_String> `\] , msgids_context_plural_comment\: :ref: `Array<class_Array> `\[ :ref: `String<class_String> `\]\ ) |virtual | |
146- +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
147- | :ref: `PackedStringArray<class_PackedStringArray> ` | :ref: `_get_recognized_extensions<class_EditorTranslationParserPlugin_private_method__get_recognized_extensions> `\ (\ ) |virtual | |const | |
148- +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
149- | |void | | :ref: `_parse_file<class_EditorTranslationParserPlugin_private_method__parse_file> `\ (\ path\: :ref: `String<class_String> `, msgids\: :ref: `Array<class_Array> `\[ :ref: `String<class_String> `\] , msgids_context_plural\: :ref: `Array<class_Array> `\[ :ref: `Array<class_Array> `\]\ ) |virtual | |
150- +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
147+ +--------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------+
148+ | :ref: `PackedStringArray<class_PackedStringArray> ` | :ref: `_get_recognized_extensions<class_EditorTranslationParserPlugin_private_method__get_recognized_extensions> `\ (\ ) |virtual | |const | |
149+ +--------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------+
150+ | :ref: `Array<class_Array> `\[ :ref: `PackedStringArray<class_PackedStringArray> `\] | :ref: `_parse_file<class_EditorTranslationParserPlugin_private_method__parse_file> `\ (\ path\: :ref: `String<class_String> `\ ) |virtual | |
151+ +--------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------+
151152
152153.. rst-class :: classref-section-separator
153154
@@ -158,18 +159,6 @@ Methods
158159Method Descriptions
159160-------------------
160161
161- .. _class_EditorTranslationParserPlugin_private_method__get_comments :
162-
163- .. rst-class :: classref-method
164-
165- |void | **_get_comments **\ (\ msgids_comment\: :ref: `Array<class_Array> `\[ :ref: `String<class_String> `\] , msgids_context_plural_comment\: :ref: `Array<class_Array> `\[ :ref: `String<class_String> `\]\ ) |virtual | :ref: `🔗<class_EditorTranslationParserPlugin_private_method__get_comments> `
166-
167- If overridden, called after :ref: `_parse_file()<class_EditorTranslationParserPlugin_private_method__parse_file> ` to get comments for the parsed entries. This method should fill the arrays with the same number of elements and in the same order as :ref: `_parse_file()<class_EditorTranslationParserPlugin_private_method__parse_file> `.
168-
169- .. rst-class :: classref-item-separator
170-
171- ----
172-
173162.. _class_EditorTranslationParserPlugin_private_method__get_recognized_extensions :
174163
175164.. rst-class :: classref-method
@@ -186,7 +175,7 @@ Gets the list of file extensions to associate with this parser, e.g. ``["csv"]``
186175
187176.. rst-class :: classref-method
188177
189- | void | ** _parse_file ** \ ( \ path \: : ref: `String<class_String> `, msgids \: :ref: ` Array<class_Array> `\[ :ref: `String<class_String > `\] , msgids_context_plural \ : :ref: `Array<class_Array> ` \[ :ref: ` Array<class_Array> ` \] \ ) |virtual | :ref: `🔗<class_EditorTranslationParserPlugin_private_method__parse_file> `
178+ : ref: `Array<class_Array> `\[ :ref: `PackedStringArray<class_PackedStringArray > `\] ** _parse_file ** \ ( \ path \ : :ref: `String<class_String> ` \ ) |virtual | :ref: `🔗<class_EditorTranslationParserPlugin_private_method__parse_file> `
190179
191180Override this method to define a custom parsing logic to extract the translatable strings.
192181
0 commit comments