Go to file
Wuzzy ad8aa36b25 Update bash_completion (partially) 2020-06-14 05:49:26 +02:00
bash-completion/completions Update bash_completion (partially) 2020-06-14 05:49:26 +02:00
.gitattributes Initial commit 2020-02-15 22:57:41 -07:00
.gitignore Initial commit 2020-02-15 22:57:41 -07:00
LICENSE Initial commit 2020-02-15 22:57:41 -07:00
README.md Update README 2020-06-14 05:47:56 +02:00
i18n.py Increase doublespace threshold 2020-06-14 01:32:55 +02:00

README.md

This Python script is intended for use with localized Minetest mods, ie, mods that contain translatable strings of the form S("This string can be translated"). It extracts the strings from the mod's source code and updates the localization files accordingly.

Place it in the root directory of a mod and run it, and it will update the template.txt and any *.tr files present in that mod's /locale folder. If the /locale folder or template.txt file don't exist yet they will be created.

This script will also work in the root directory of a modpack. It will run on each mod inside the modpack in that situation.

It has the following command line options:

i18n.py [OPTIONS] [PATHS...]

--help, -h: prints this help message
--recursive, -r: run on all subfolders of paths given
--installed-mods, -m: run on locally installed modules
--no-old-file, -O: do not create *.old files
--verbose, -v: add output information
--sort, -s: sort strings

The script will preserve any comments in an existing template.txt or the various *.tr files, associating them with the line that follows them. So for example:

# This comment pertains to Some Text
Some text=

# Multi-line comments
# are also supported
Text as well=

Note that whenever the translation files are regenerated the translation lines will be grouped by source lua filename and sorted alphabetically, so don't bother manually organizing the order of the lines in the file yourself.

If the mod's source changes in such a way that a line with an existing translation or comment is no longer present, the unused line will be moved to the bottom of the translation file under the header:

##### not used anymore #####

This allows for old translations and comments to be reused with new lines where appropriate. This script doesn't attempt "fuzzy" matching of old strings to new, so even a single change of punctuation or spelling will put strings into the "not used anymore" section and require manual reassociation with the new string.

bash autocompletion

When running on Linux to install bash_completion for I18N, you can run

mkdir -p ${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion/completions
ln -s $PWD/bash-completion/completions/i18n ${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion/completions/i18n.py

This will provide bash autocompletion for this script (you have to run it without using python3 i18n command, use ./i18n.py instead (or i18n.py if provided by $PATH)).