Skip to content

Commit 4485a46

Browse files
committed
scripts: Add regenerate pot CLI script and wrapper
This can be used to execute TxUtils.regenerate_pot_file() from the CLI. The GDScript is a SceneTree script passed via Godot's --script CLI option. The shell script is a wrapper to execute Godot with all the necessary options.
1 parent d6aaad4 commit 4485a46

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

addons/block_code/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ up to date.
9090
* If translatable strings have changed, the POT file needs to be updated. This
9191
can be done by using the **Generate POT** dialog in the [POT
9292
Generation][pot-generation] tab. Or you can use the **Project → Tools →
93-
Regenerate BlockCode POT file** menu item in the editor.
93+
Regenerate BlockCode POT file** menu item in the editor. From the command
94+
line, the POT file can be regenerated with the `scripts/regenerate-pot.sh`
95+
shell script.
9496

9597
* If the POT file has changed, the PO message files need to be updated. This
9698
can be done using the gettext `msgmerge` tool in the

scripts/regenerate-pot.gd

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## BlockCode POT regeneration script
2+
##
3+
## Use this on the Godot command line with the --script option. This depends on
4+
## the Godot editor, so the --editor option is also required.
5+
extends SceneTree
6+
7+
const TxUtils := preload("res://addons/block_code/translation/utils.gd")
8+
9+
10+
# Everything happens in _process to ensure the editor is fully initialized.
11+
func _process(_delta):
12+
if Engine.is_editor_hint():
13+
TxUtils.regenerate_pot_file()
14+
else:
15+
push_error("%s can only be run with --editor" % get_script().resource_path)
16+
17+
# Stop processing the main loop.
18+
return true

scripts/regenerate-pot.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
# Wrapper script to try to execute the regenerate-pot.gd main loop script.
4+
set -e
5+
6+
SCRIPTDIR=$(dirname "$0")
7+
PROJDIR=$(dirname "$SCRIPTDIR")
8+
GODOT_SH="$SCRIPTDIR/godot.sh"
9+
SCRIPT="$SCRIPTDIR/regenerate-pot.gd"
10+
11+
exec "$GODOT_SH" --path "$PROJDIR" --headless --editor --script "$SCRIPT"

0 commit comments

Comments
 (0)