Skip to content

Commit

Permalink
Add tool to regenerate POT file
Browse files Browse the repository at this point in the history
Currently the only way to regenerate a POT file is to go through the
Regenerate POT dialog in the Localization tab of the Project Settings.
This adds a Project->Tools menu item that drives the dialog from code
using our POT file path. Hat tip to KoBeWi for the procedure. Hopefully
in the future we'll have a Godot CLI interface to do this.
  • Loading branch information
dbnicholson committed Nov 1, 2024
1 parent d7f50c4 commit 4ed2a6c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions addons/block_code/block_code_plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func _enter_tree():
_tx_parser_plugin = BlockTranslationParserPlugin.new()
add_translation_parser_plugin(_tx_parser_plugin)

# Custom Project->Tools menu items.
add_tool_menu_item(tr("Regenerate %s POT file") % "BlockCode", TxUtils.regenerate_pot_file)

# Remove unwanted class nodes from create node
old_feature_profile = EditorInterface.get_current_feature_profile()

Expand Down
19 changes: 19 additions & 0 deletions addons/block_code/translation/utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const DOMAIN := &"godot_block_coding"
## BlockCode locale directory path
const LOCALE_DIR_PATH := "res://addons/block_code/locale"

## BlockCode POT file path
const POT_FILE_PATH := "res://addons/block_code/locale/godot_block_coding.pot"


## Get the BlockCode translation domain.
##
Expand Down Expand Up @@ -105,3 +108,19 @@ static func set_block_translation_domain(obj: Object):
if obj.has_method(&"set_translation_domain"):
print_verbose("Setting %s translation domain to %s" % [obj, DOMAIN])
obj.call(&"set_translation_domain", DOMAIN)


## Regenerate BlockCode POT file.
##
## Update the BlockCode POT file to include new translatable strings.
static func regenerate_pot_file():
# Dirty method to drive the editor's Generate POT dialog from
# https://github.com/godotengine/godot-proposals/issues/10986#issuecomment-2419914451
#
# Obviously this is pretty fragile since it depends on the editor's UI
# remaining stable. Hopefully in the future we can just do this from the
# command line. See https://github.com/godotengine/godot/pull/98422.
var localization := EditorInterface.get_base_control().find_child("*Localization*", true, false)
var file_dialog: EditorFileDialog = localization.get_child(5)
print(translate("Updating %s POT file %s") % ["BlockCode", POT_FILE_PATH])
file_dialog.file_selected.emit(POT_FILE_PATH)

0 comments on commit 4ed2a6c

Please sign in to comment.