descriptionPython script to update mod translations for Minetest
ownerWuzzy@disroot.org
last changeSun, 14 Jun 2020 03:49:26 +0000 (14 05:49 +0200)
content tags
add:
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)).

shortlog
2020-06-14 WuzzyUpdate bash_completion (partially)simplify
2020-06-14 WuzzyUpdate README
2020-06-13 WuzzyIncrease doublespace threshold
2020-06-13 WuzzyAdd short cmd line parameters
2020-06-13 WuzzyDisable alphabetic sorting by default
2020-06-13 WuzzyRemove comment noise
2020-03-10 FaceDeerMerge pull request #6 from louisroyer/no_old_files
2020-03-09 Louis RoyerAdd --no-old-file option parameter
2020-03-02 FaceDeerAdd url of repository to the main script
2020-03-01 FaceDeerUpdate readme.md
2020-02-21 FaceDeeradd bash autocompletion to the readme
2020-02-21 FaceDeerMerge pull request #5 from louisroyer/bash_completion
2020-02-20 Louis RoyerAdd bash_completion
2020-02-20 FaceDeerah, I see what the intention was. replacing + with ,
2020-02-20 FaceDeerwithout this slash here the path is invalid and .po...
2020-02-19 FaceDeeradd double-spacing only for lines over a certain threshold
...
heads
3 years ago params
3 years ago simplify