summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorSkyJJ <jjchai01@hotmail.com>2020-07-03 20:24:54 +0200
committerSkyJJ <jjchai01@hotmail.com>2020-07-05 12:14:56 +0200
commitcae6f0bda282c8e831cbae5d45cfaa4e841ff3bf (patch)
tree3d3db4190712ddf25b8e7f606aeae23a28e3a5a9 /doc
parent0287508dcdf51c7349b41aabb7679061a5147fdf (diff)
Change translation parser plugin API to parse_file()
Diffstat (limited to 'doc')
-rw-r--r--doc/classes/EditorTranslationParserPlugin.xml25
1 files changed, 21 insertions, 4 deletions
diff --git a/doc/classes/EditorTranslationParserPlugin.xml b/doc/classes/EditorTranslationParserPlugin.xml
index 73098efd99..a40ef45916 100644
--- a/doc/classes/EditorTranslationParserPlugin.xml
+++ b/doc/classes/EditorTranslationParserPlugin.xml
@@ -4,22 +4,39 @@
Plugin for adding custom parsers to extract strings that are to be translated from custom files (.csv, .json etc.).
</brief_description>
<description>
- Plugins are registered via [method EditorPlugin.add_translation_parser_plugin] method. To define the parsing and string extraction logic, override the [method parse_text] method in script.
+ Plugins are registered via [method EditorPlugin.add_translation_parser_plugin] method. To define the parsing and string extraction logic, override the [method parse_file] method in script.
The extracted strings will be written into a POT file selected by user under "POT Generation" in "Localization" tab in "Project Settings" menu.
Below shows an example of a custom parser that extracts strings in a CSV file to write into a POT.
[codeblock]
tool
extends EditorTranslationParserPlugin
- func parse_text(text, extracted_strings):
+
+ func parse_file(path, extracted_strings):
+ var file = File.new()
+ file.open(path, File.READ)
+ var text = file.get_as_text()
var split_strs = text.split(",", false, 0)
for s in split_strs:
extracted_strings.append(s)
#print("Extracted string: " + s)
+
func get_recognized_extensions():
return ["csv"]
[/codeblock]
+ [b]Note:[/b] If you override parsing logic for standard script types (GDScript, C#, etc.), it would be better to load the [code]path[/code] argument using [method ResourceLoader.load]. This is because built-in scripts are loaded as [Resource] type, not [File] type.
+ For example:
+ [codeblock]
+ func parse_file(path, extracted_strings):
+ var res = ResourceLoader.load(path, "Script")
+ var text = res.get_source_code()
+ # Parsing logic.
+
+
+ func get_recognized_extensions():
+ return ["gd"]
+ [/codeblock]
</description>
<tutorials>
</tutorials>
@@ -31,10 +48,10 @@
Gets the list of file extensions to associate with this parser, e.g. [code]["csv"][/code].
</description>
</method>
- <method name="parse_text" qualifiers="virtual">
+ <method name="parse_file" qualifiers="virtual">
<return type="void">
</return>
- <argument index="0" name="text" type="String">
+ <argument index="0" name="path" type="String">
</argument>
<argument index="1" name="extracted_strings" type="Array">
</argument>