Skip to content

Commit 79a4463

Browse files
authored
Merge pull request #301 from endlessm/automate-translation
Translation scripts
2 parents 909ac54 + 9dcb6ef commit 79a4463

File tree

7 files changed

+116
-9
lines changed

7 files changed

+116
-9
lines changed

addons/block_code/README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,20 @@ up to date.
9090
* If files are added or removed, the list of translatable files needs to be
9191
updated. This can be done by using the **Add** dialog in the [POT
9292
Generation][pot-generation] tab. Or you can use the **Project → Tools →
93-
Update BlockCode translated files** menu item in the editor.
93+
Update BlockCode translated files** menu item in the editor. From the command
94+
line, the POT file can be regenerated with the `scripts/update-pot-files.sh`
95+
shell script.
9496

9597
* If translatable strings have changed, the POT file needs to be updated. This
9698
can be done by using the **Generate POT** dialog in the [POT
9799
Generation][pot-generation] tab. Or you can use the **Project → Tools →
98-
Regenerate BlockCode POT file** menu item in the editor.
100+
Regenerate BlockCode POT file** menu item in the editor. From the command
101+
line, the POT file can be regenerated with the `scripts/regenerate-pot.sh`
102+
shell script.
99103

100104
* If the POT file has changed, the PO message files need to be updated. This
101-
can be done using the gettext `msgmerge` tool in the
102-
`addons/block_code/locale` directory:
103-
```
104-
for po in *.po; do
105-
msgmerge --update --backup=none "$po" godot_block_coding.pot
106-
done
107-
```
105+
can be done using the gettext `msgmerge` tool with the
106+
`scripts/merge-messages.sh` shell script.
108107

109108
[pot-generation]: https://docs.godotengine.org/en/stable/tutorials/i18n/localization_using_gettext.html#automatic-generation-using-the-editor
110109

scripts/godot.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Wrapper script to try to execute the Godot binary.
4+
set -e
5+
6+
get_godot_bin() {
7+
# GODOT environment variable preferred.
8+
if [ -n "$GODOT" ]; then
9+
echo "$GODOT"
10+
return 0
11+
fi
12+
13+
# godot in PATH.
14+
if type -p godot >/dev/null; then
15+
echo godot
16+
return 0
17+
fi
18+
19+
# Flatpak Godot with <installation>/exports/bin in PATH.
20+
if type -p org.godotengine.Godot >/dev/null; then
21+
echo org.godotengine.Godot
22+
return 0
23+
fi
24+
25+
# Flatpak Godot without <installation>/exports/bin in PATH.
26+
if flatpak info org.godotengine.Godot &>/dev/null; then
27+
echo "flatpak run org.godotengine.Godot"
28+
return 0
29+
fi
30+
31+
echo "error: Could not find godot executable, set GODOT environment variable" >&2
32+
return 1
33+
}
34+
35+
godot_bin=$(get_godot_bin)
36+
exec $godot_bin "$@"

scripts/merge-messages.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
# Merge new strings from POT file into message catalogs.
4+
set -e
5+
6+
SCRIPTDIR=$(dirname "$0")
7+
PROJDIR=$(dirname "$SCRIPTDIR")
8+
LOCALEDIR="$PROJDIR/addons/block_code/locale"
9+
POT="$LOCALEDIR/godot_block_coding.pot"
10+
11+
for po in "$LOCALEDIR"/*.po; do
12+
echo -n "$po"
13+
msgmerge --update --backup=none "$po" "$POT"
14+
done

scripts/regenerate-pot.gd

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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
19+
20+
21+
# The editor won't be shut down in the normal way, which will cause a bunch of
22+
# leaks. There's nothing we can do about that and we don't care about them,
23+
# anyways. Let the user following along know this is OK.
24+
func _finalize():
25+
print_rich("[b]%s causes Godot to leak resources. Ignore the warnings and errors![/b]" % get_script().resource_path.get_file())

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"

scripts/update-pot-files.gd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## BlockCode update translated files script
2+
##
3+
## Use this on the Godot command line with the --script option.
4+
extends SceneTree
5+
6+
const TxUtils := preload("res://addons/block_code/translation/utils.gd")
7+
8+
9+
func _init():
10+
TxUtils.update_pot_files()
11+
quit()

scripts/update-pot-files.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 update-pot-files.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/update-pot-files.gd"
10+
11+
exec "$GODOT_SH" --path "$PROJDIR" --headless --script "$SCRIPT"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy