Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/threadbare_editor/plugin.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[plugin]

name="ThreadbareEditor"
description="Adds an editor debugger."
description="Threadbare editor integrations: a debugger and a translation parser."
author="The Threadbare Authors"
version=""
script="plugin.gd"
11 changes: 11 additions & 0 deletions addons/threadbare_editor/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,27 @@ class_name ThreadbareEditorPlugin
extends EditorPlugin

const ThreadbareDebugger := preload("res://addons/threadbare_editor/threadbare_debugger.gd")
const QuestTranslationParser := preload(
"res://addons/threadbare_editor/quest_translation_parser.gd"
)

var threadbare_debugger: EditorDebuggerPlugin
var quest_translation_parser: EditorTranslationParserPlugin


func _enter_tree() -> void:
threadbare_debugger = ThreadbareDebugger.new()
add_debugger_plugin(threadbare_debugger)

quest_translation_parser = QuestTranslationParser.new()
add_translation_parser_plugin(quest_translation_parser)


func _exit_tree() -> void:
if threadbare_debugger:
remove_debugger_plugin(threadbare_debugger)
threadbare_debugger = null

if quest_translation_parser:
remove_translation_parser_plugin(quest_translation_parser)
quest_translation_parser = null
32 changes: 32 additions & 0 deletions addons/threadbare_editor/quest_translation_parser.gd

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. I expected that there would be some vfunc on nodes/resources that gets translations for their properties; or maybe some property export flag that means "translate me". But no! In fact the built-in translations of properties of scenes is an implementation of EditorTranslationParserPlugin with loads of hardcoded special cases, e.g. "If a node is a direct child of a TabContainer, then its name should be translated".

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know! Great source to use as reference too. For example, the use of get_recognized_extensions_for_type().

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# SPDX-FileCopyrightText: The Threadbare Authors
# SPDX-License-Identifier: MPL-2.0
@tool
extends EditorTranslationParserPlugin
## Extracts the translatable strings of a [Quest] resource.
##
## A [Quest] is a custom resource, so by default is not recognized by the translation system.
## This parser makes it possible, so adding a quest.tres to the list of translatable
## files puts its title and description in the catalog.

const TITLE_COMMENT := "Quest title"
const DESCRIPTION_COMMENT := "Quest description"


func _get_recognized_extensions() -> PackedStringArray:
return ResourceLoader.get_recognized_extensions_for_type("Quest")


func _parse_file(path: String) -> Array[PackedStringArray]:
var messages: Array[PackedStringArray] = []

# Skip .tres files that aren't Quests.
var quest := ResourceLoader.load(path, "", ResourceLoader.CACHE_MODE_IGNORE) as Quest
if not quest:
return messages

if quest.title:
messages.append(PackedStringArray([quest.title, "", "", TITLE_COMMENT]))
if quest.description:
messages.append(PackedStringArray([quest.description, "", "", DESCRIPTION_COMMENT]))

return messages
1 change: 1 addition & 0 deletions addons/threadbare_editor/quest_translation_parser.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://v8n7t54c7iqy
Loading