diff --git a/addons/block_code/README.md b/addons/block_code/README.md index 55a0e4d0..c3625cdd 100644 --- a/addons/block_code/README.md +++ b/addons/block_code/README.md @@ -87,21 +87,20 @@ up to date. * If files are added or removed, the list of translatable files needs to be updated. This can be done by using the **Add** dialog in the [POT Generation][pot-generation] tab. Or you can use the **Project → Tools → - Update BlockCode translated files** menu item in the editor. + Update BlockCode translated files** menu item in the editor. From the command + line, the POT file can be regenerated with the `scripts/update-pot-files.sh` + shell script. * If translatable strings have changed, the POT file needs to be updated. This can be done by using the **Generate POT** dialog in the [POT Generation][pot-generation] tab. Or you can use the **Project → Tools → - Regenerate BlockCode POT file** menu item in the editor. + Regenerate BlockCode POT file** menu item in the editor. From the command + line, the POT file can be regenerated with the `scripts/regenerate-pot.sh` + shell script. * If the POT file has changed, the PO message files need to be updated. This - can be done using the gettext `msgmerge` tool in the - `addons/block_code/locale` directory: - ``` - for po in *.po; do - msgmerge --update --backup=none "$po" godot_block_coding.pot - done - ``` + can be done using the gettext `msgmerge` tool with the + `scripts/merge-messages.sh` shell script. [pot-generation]: https://docs.godotengine.org/en/stable/tutorials/i18n/localization_using_gettext.html#automatic-generation-using-the-editor diff --git a/scripts/godot.sh b/scripts/godot.sh new file mode 100755 index 00000000..48046738 --- /dev/null +++ b/scripts/godot.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Wrapper script to try to execute the Godot binary. +set -e + +get_godot_bin() { + # GODOT environment variable preferred. + if [ -n "$GODOT" ]; then + echo "$GODOT" + return 0 + fi + + # godot in PATH. + if type -p godot >/dev/null; then + echo godot + return 0 + fi + + # Flatpak Godot with /exports/bin in PATH. + if type -p org.godotengine.Godot >/dev/null; then + echo org.godotengine.Godot + return 0 + fi + + # Flatpak Godot without /exports/bin in PATH. + if flatpak info org.godotengine.Godot &>/dev/null; then + echo "flatpak run org.godotengine.Godot" + return 0 + fi + + echo "error: Could not find godot executable, set GODOT environment variable" >&2 + return 1 +} + +godot_bin=$(get_godot_bin) +exec $godot_bin "$@" diff --git a/scripts/merge-messages.sh b/scripts/merge-messages.sh new file mode 100755 index 00000000..90871dfb --- /dev/null +++ b/scripts/merge-messages.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# Merge new strings from POT file into message catalogs. +set -e + +SCRIPTDIR=$(dirname "$0") +PROJDIR=$(dirname "$SCRIPTDIR") +LOCALEDIR="$PROJDIR/addons/block_code/locale" +POT="$LOCALEDIR/godot_block_coding.pot" + +for po in "$LOCALEDIR"/*.po; do + echo -n "$po" + msgmerge --update --backup=none "$po" "$POT" +done diff --git a/scripts/regenerate-pot.gd b/scripts/regenerate-pot.gd new file mode 100644 index 00000000..16720f46 --- /dev/null +++ b/scripts/regenerate-pot.gd @@ -0,0 +1,25 @@ +## BlockCode POT regeneration script +## +## Use this on the Godot command line with the --script option. This depends on +## the Godot editor, so the --editor option is also required. +extends SceneTree + +const TxUtils := preload("res://addons/block_code/translation/utils.gd") + + +# Everything happens in _process to ensure the editor is fully initialized. +func _process(_delta): + if Engine.is_editor_hint(): + TxUtils.regenerate_pot_file() + else: + push_error("%s can only be run with --editor" % get_script().resource_path) + + # Stop processing the main loop. + return true + + +# The editor won't be shut down in the normal way, which will cause a bunch of +# leaks. There's nothing we can do about that and we don't care about them, +# anyways. Let the user following along know this is OK. +func _finalize(): + print_rich("[b]%s causes Godot to leak resources. Ignore the warnings and errors![/b]" % get_script().resource_path.get_file()) diff --git a/scripts/regenerate-pot.sh b/scripts/regenerate-pot.sh new file mode 100755 index 00000000..dca7c938 --- /dev/null +++ b/scripts/regenerate-pot.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# Wrapper script to try to execute the regenerate-pot.gd main loop script. +set -e + +SCRIPTDIR=$(dirname "$0") +PROJDIR=$(dirname "$SCRIPTDIR") +GODOT_SH="$SCRIPTDIR/godot.sh" +SCRIPT="$SCRIPTDIR/regenerate-pot.gd" + +exec "$GODOT_SH" --path "$PROJDIR" --headless --editor --script "$SCRIPT" diff --git a/scripts/update-pot-files.gd b/scripts/update-pot-files.gd new file mode 100644 index 00000000..149074b0 --- /dev/null +++ b/scripts/update-pot-files.gd @@ -0,0 +1,11 @@ +## BlockCode update translated files script +## +## Use this on the Godot command line with the --script option. +extends SceneTree + +const TxUtils := preload("res://addons/block_code/translation/utils.gd") + + +func _init(): + TxUtils.update_pot_files() + quit() diff --git a/scripts/update-pot-files.sh b/scripts/update-pot-files.sh new file mode 100755 index 00000000..9280acee --- /dev/null +++ b/scripts/update-pot-files.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# Wrapper script to try to execute the update-pot-files.gd main loop script. +set -e + +SCRIPTDIR=$(dirname "$0") +PROJDIR=$(dirname "$SCRIPTDIR") +GODOT_SH="$SCRIPTDIR/godot.sh" +SCRIPT="$SCRIPTDIR/update-pot-files.gd" + +exec "$GODOT_SH" --path "$PROJDIR" --headless --script "$SCRIPT"