-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BlockDefinition translation parser plugin
Since BlockDefinitions are generic Resources, Godot doesn't automatically extract translatable strings from them. In order to do that, we need to provide an EditorTranslationParserPlugin that extracts the desired fields so they're included in a POT file.
- Loading branch information
1 parent
7834706
commit c5b3feb
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
@tool | ||
## BlockCode translation parser plugin. | ||
## | ||
## Extracts translatable strings from BlockCode resources. Currently only | ||
## BlockDefinition resources are handled. | ||
extends EditorTranslationParserPlugin | ||
|
||
const BLOCK_DEFINITION_SCRIPT_PATH := "res://addons/block_code/code_generation/block_definition.gd" | ||
|
||
# BlockDefinition properties for translation | ||
const block_def_tx_properties: Array[String] = [ | ||
"category", | ||
"description", | ||
"display_template", | ||
] | ||
|
||
|
||
func _get_recognized_extensions() -> PackedStringArray: | ||
# BlockDefinition resources currently use the generic tres extension. | ||
return ["tres"] | ||
|
||
|
||
func _resource_is_block_definition(resource: Resource) -> bool: | ||
var script := resource.get_script() | ||
if not script: | ||
return false | ||
return script.resource_path == BLOCK_DEFINITION_SCRIPT_PATH | ||
|
||
|
||
func _parse_file(path: String, msgids: Array[String], msgids_context_plural: Array[Array]) -> void: | ||
# Only BlockDefinition resources are supported. | ||
var res = ResourceLoader.load(path, "Resource") | ||
if not res or not _resource_is_block_definition(res): | ||
return | ||
for prop in block_def_tx_properties: | ||
var value: String = res.get(prop) | ||
if value: | ||
# For now just the messages are used. It might be better to provide | ||
# context with msgids_context_plural to avoid conflicts. | ||
msgids.append(value) |