Skip to content

Commit 6d149f0

Browse files
committed
Add localization documentation
A bit of info about working with the translations.
1 parent 0c044ac commit 6d149f0

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

addons/block_code/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,70 @@ Lean into animations! Godot's animations functionality goes beyond just simple a
6666

6767
Please share feedback in the [Godot Forum Block Coding thread](https://forum.godotengine.org/t/block-coding-high-level-block-based-visual-programming/68941).
6868

69+
## Localization
70+
71+
The plugin supports translations through Godot's [gettext][godot-gettext]
72+
support. We welcome contributions to make the plugin work better in your
73+
language! However, please note that translations in the Godot editor **will
74+
only work with Godot 4.4 or newer**.
75+
76+
The gettext PO files are located in the `addons/block_code/locale` directory.
77+
See the Godot [documentation][godot-gettext] for instructions on working with
78+
PO files.
79+
80+
[godot-gettext]: https://docs.godotengine.org/en/stable/tutorials/i18n/localization_using_gettext.html
81+
82+
For developers, a few things need to be done to keep the translatable strings
83+
up to date.
84+
85+
* If files are added or removed, the list of translatable files needs to be
86+
updated. This can be done by using the **Add** dialog in the [POT
87+
Generation][pot-generation] tab. Or you can use the **Project → Tools →
88+
Update BlockCode translated files** menu item in the editor.
89+
90+
* If translatable strings have changed, the POT file needs to be updated. This
91+
can be done by using the **Generate POT** dialog in the [POT
92+
Generation][pot-generation] tab. Or you can use the **Project → Tools →
93+
Regenerate BlockCode POT file** menu item in the editor.
94+
95+
* If the POT file has changed, the PO message files need to be updated. This
96+
can be done using the gettext `msgmerge` tool in the
97+
`addons/block_code/locale` directory:
98+
```
99+
for po in *.po; do
100+
msgmerge --update --backup=none "$po" godot_block_coding.pot
101+
done
102+
```
103+
104+
[pot-generation]: https://docs.godotengine.org/en/stable/tutorials/i18n/localization_using_gettext.html#automatic-generation-using-the-editor
105+
106+
Strings added in scene files or block definition resources will usually be
107+
extracted for localization and translated in the editor automatically. Strings
108+
in scripts need more consideration.
109+
110+
* `Object`s or `Node`s that are not descendents of the Block Coding panel need
111+
to have their translation domain set with the `set_block_translation_domain`
112+
helper function. This should usually be done in the object's `_init` method
113+
to make sure the translation domain is set before that object or any of its
114+
descendents (which inherit the translation domain by default) try to use
115+
localized strings.
116+
117+
* Usually [`tr`][object-tr] and [`tr_n`][object-tr-n] (or [`atr`][node-atr] and
118+
[`atr_n`][node-atr-n] for `Node`s) should be used to mark translatable
119+
strings. These will eventually call the domain's
120+
[`translate`][domain-translate] or
121+
[`translate_plural`][domain-translate-plural] methods, but the `tr` methods
122+
respect translation settings on the object instances. The only time the
123+
`translate` methods should be called directly is within a static context when
124+
an object instance isn't available.
125+
126+
[object-tr]: https://docs.godotengine.org/en/stable/classes/class_object.html#class-object-method-tr
127+
[object-tr-n]: https://docs.godotengine.org/en/stable/classes/class_object.html#class-object-method-tr-n
128+
[node-atr]: https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-atr
129+
[node-atr-n]: https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-atr-n
130+
[domain-translate]: https://docs.godotengine.org/en/latest/classes/class_translationdomain.html#class-translationdomain-method-translate
131+
[domain-translate-plural]: https://docs.godotengine.org/en/latest/classes/class_translationdomain.html#class-translationdomain-method-translate-plural
132+
69133
## Development
70134

71135
### pre-commit

0 commit comments

Comments
 (0)