Difference between revisions of "Translation"

From Minetest Developer Wiki
Jump to navigation Jump to search
m (fix broken heading)
(→‎Maintaining translations: Add builtin maintenance instructions)
Line 38: Line 38:
  
 
== Maintaining translations ==
 
== Maintaining translations ==
=== Contributing a new translation ===
+
There are two types of translations that need maintenance: Client-side (using Gettext) and server-side translations for builtin (using <code>minetest.get_translator</code>).
 +
 
 +
=== Client-side translations (Gettext) ===
 +
==== Contributing a new translation ====
 
To create a new translation, one must create a directory named after the [http://www.mathguide.de/info/tools/languagecode.html language code], creating a copy of the <code>po/minetest.pot</code> file as <code>po/''LANG''/minetest.po</code>, and translating the original english text into your language; then <code>cmake</code> will detect it and <code>make</code> builds the language.
 
To create a new translation, one must create a directory named after the [http://www.mathguide.de/info/tools/languagecode.html language code], creating a copy of the <code>po/minetest.pot</code> file as <code>po/''LANG''/minetest.po</code>, and translating the original english text into your language; then <code>cmake</code> will detect it and <code>make</code> builds the language.
  
Line 45: Line 48:
 
''Note to coredevs'': Creating a new language directly from weblate is sufficient, no need to mess with the files directly in the repository.
 
''Note to coredevs'': Creating a new language directly from weblate is sufficient, no need to mess with the files directly in the repository.
  
=== How to merge translations from Hosted Weblate ===
+
==== How to merge translations from Hosted Weblate ====
  
 
Translations should be merged in bulk, and not too often, to not create too large "noise" in the commit log. A good schedule is once per month. Right now, nerzhul manages translations. This section explains the neccessary steps for core devs, in the case nerzhul isn't around. You will need owner access to the hosted repo though, in order to be able to push the "Rebase" button.
 
Translations should be merged in bulk, and not too often, to not create too large "noise" in the commit log. A good schedule is once per month. Right now, nerzhul manages translations. This section explains the neccessary steps for core devs, in the case nerzhul isn't around. You will need owner access to the hosted repo though, in order to be able to push the "Rebase" button.
Line 51: Line 54:
 
As of Oct 2019, est31, PilzAdam, ShadowNinja, nerzhul, sfan5, rubenwardy, Krock and possibly some other core devs have such access.
 
As of Oct 2019, est31, PilzAdam, ShadowNinja, nerzhul, sfan5, rubenwardy, Krock and possibly some other core devs have such access.
  
==== Setting up ====
+
===== Setting up =====
  
 
Add weblate as remote: <code>git remote add weblate https://hosted.weblate.org/git/minetest/minetest/</code>.
 
Add weblate as remote: <code>git remote add weblate https://hosted.weblate.org/git/minetest/minetest/</code>.
  
==== Once every translation ====
+
===== Once every translation =====
  
 
# Visit [https://hosted.weblate.org/projects/minetest/minetest/#repository Repo maintenance], and lock the repository to prevent changes from users while you are editing.
 
# Visit [https://hosted.weblate.org/projects/minetest/minetest/#repository Repo maintenance], and lock the repository to prevent changes from users while you are editing.
Line 70: Line 73:
 
# Reset the Weblate remote ("Reset" button), rebase it to match now current master, and unlock it. If pushed commits do not yet show up in Weblate you may have to press the "Pull" button.
 
# Reset the Weblate remote ("Reset" button), rebase it to match now current master, and unlock it. If pushed commits do not yet show up in Weblate you may have to press the "Pull" button.
  
=== Background information: Installing Weblate ===
+
==== Background information: Installing Weblate ====
 
See [[Installing Weblate]].
 
See [[Installing Weblate]].
 +
 +
=== Server-side builtin translations (minetest.get_translator) ===
 +
The server-side translations of builtin are located in <code>builtin/locale</code> with <code>template.txt</code> being used as the template file.
 +
 +
The template file as well as all locale files need to be updated before release to allow translators to translate.
 +
We do not have an official tool for automatically updating these translations yet, but you can use this unofficial Python script here (it might still need some manual modifications, however): https://github.com/minetest-tools/update_translations
 +
 +
To start a new translation, copy <code>template.txt</code> to create <code>__builtin.<LANGUAGE_CODE>.tr</code>.
  
 
== Translating mods and games ==
 
== Translating mods and games ==

Revision as of 15:45, 14 March 2021

This page explains how to translate Minetest, mods and games and how translations are handled and maintained.

Translating Minetest

How to translate

Translations of Minetest are automated using Weblate at here. Register an account, select the Minetest project and start translating.

Translation is a continuous effort and the texts will change almost at every version.

The developers usually will update the translation templates shortly before a new release. If you translate a long time before a release, your translation updates will still be included, but your translation will likely be incomplete because almost every new version comes with new things to translate. Check out the News forum to see if a new release is imminent.

In case you wish to translate a new language, contact a core dev.

Language-specific notes

Here is a list of wiki pages for translating specific languages:

Special strings

In the translations you will find two special strings with a special meaning. They must not be translated literally. They are used internally by Minetest to trigger certain settings. You must enter a special value into the translation field.

  • needs_fallback_font: Whether this language should use the fallback font or not. The fallback font contains some characters that are required by languages like Chinese. For most Latin-script languages, the fallback font is not needed. Enter “yes” if the fallback font is needed, “no” if not. Please try to test your translation when you enable the fallback font.
  • LANG_CODE: The language code of the language you're translating (e.g. “de” for German).

The Minetest translation system

This section is dedicated to developers.

Overview

Minetest can use the gettext library to translate the texts in Minetest. To enable internationalization support, the game must be built with the -DENABLE_GETTEXT=1 option to cmake, which is enabled by default.

Games and mods are translated using a different method (see below).

Language detection

Minetest detects the current language by inspecting the LANG environment variable. This is not a problem on Unix-based systems (such as GNU/Linux) since the system already defines this variable at login. On Windows platforms, the system language is used.

Available translations

The available translations are found in source form in the po/ directory. The cmake detects them, and they are built as part of the build process.

The main translation file must be updated now and then using the this script (configuration, bottom of the file) and this one (C++ and Lua translations). Submit a PR after running the generator or poke a core dev to update the translations when it's needed.

Maintaining translations

There are two types of translations that need maintenance: Client-side (using Gettext) and server-side translations for builtin (using minetest.get_translator).

Client-side translations (Gettext)

Contributing a new translation

To create a new translation, one must create a directory named after the language code, creating a copy of the po/minetest.pot file as po/LANG/minetest.po, and translating the original english text into your language; then cmake will detect it and make builds the language.

However, it is recomended to contact a core dev to create the .po file for you language and then use weblate to translate.

Note to coredevs: Creating a new language directly from weblate is sufficient, no need to mess with the files directly in the repository.

How to merge translations from Hosted Weblate

Translations should be merged in bulk, and not too often, to not create too large "noise" in the commit log. A good schedule is once per month. Right now, nerzhul manages translations. This section explains the neccessary steps for core devs, in the case nerzhul isn't around. You will need owner access to the hosted repo though, in order to be able to push the "Rebase" button.

As of Oct 2019, est31, PilzAdam, ShadowNinja, nerzhul, sfan5, rubenwardy, Krock and possibly some other core devs have such access.

Setting up

Add weblate as remote: git remote add weblate https://hosted.weblate.org/git/minetest/minetest/.

Once every translation
  1. Visit Repo maintenance, and lock the repository to prevent changes from users while you are editing.
  2. Generate a clean history, without merge commits. Push the "Rebase" button on the repository.
  3. Do git remote update weblate. Confirm e.g. with git log --graph weblate/master that it bases on upstream's master, and only has "Translated using Weblate" as additional commits, no merge commits.
  4. As every weblate user can freely edit translations, there can be vandalism. Therefore, check the translation commits, e.g. with help from online translator services like Google Translate, other core devs, or trusted members from the community. It might be helpful to push the commits to your GitHub clone's branch, then you have commit http links to share. In the case of required changes, let them do it over the weblate interface (after you've unlocked), and start with 2. again. Of course, its up to you to how much you want to follow this rule, as checking changes can be quite time consuming. Feel free to refine your scope e.g. to new and not yet trusted contributors.
  5. Check out the branch from Weblate's repo: git checkout weblate/master
  6. Reorder the commits from the same author, and squash them. git rebase -i is your friend (especially after you set it up to show the author, see this Stack Overflow answer on how to do it). As a good tip, rather do multiple runs of such an interactive rebase where you do small changes each, than one big run which then fails in the middle of the business. ./util/reorder_translation_commits.py can do the commit reordering for you.
  7. Confirm that git diff weblate/master is empty, to make sure that you didn't mess up at step 6. Otherwise use git reflog to find the latest rebase pass that worked, and retry the commits
  8. If required/desired, do these: (--author="updatepo.sh <script@mt>" should be used when committing changes made by the scripts)
    1. Update minetest.conf.example and the dummy *.cpp translation file and commit. Do this by uncommenting the lines at the end of builtin/mainmenu/dlg_settings_advanced.lua
    2. Run util/updatepo.sh, and commit. Note that it creates lots of unneccessary changes, and enlarges repository size disproportionately, therefore run it even less often.
  9. Push to the GitHub repo with e.g. git push origin HEAD:master
  10. Reset the Weblate remote ("Reset" button), rebase it to match now current master, and unlock it. If pushed commits do not yet show up in Weblate you may have to press the "Pull" button.

Background information: Installing Weblate

See Installing Weblate.

Server-side builtin translations (minetest.get_translator)

The server-side translations of builtin are located in builtin/locale with template.txt being used as the template file.

The template file as well as all locale files need to be updated before release to allow translators to translate. We do not have an official tool for automatically updating these translations yet, but you can use this unofficial Python script here (it might still need some manual modifications, however): https://github.com/minetest-tools/update_translations

To start a new translation, copy template.txt to create __builtin.<LANGUAGE_CODE>.tr.

Translating mods and games

Minetest supports translating mods and games. Games are translated on a per-mod basis, i.e. by translating each mod.

Is the mod translatable?

First, the mod in question must support the Minetest translation system. If you can find a locale directory within the mod directory, this mod can be translated. If it does not exist, it can't be translated. In that case request the mod or game author to add internationalization support.

How to translate

In the locale directory inside the mod directory, you might find:

  • template.txt (or similar name): Translation template for new languages
  • <NAME>.<LANGUAGE CODE>.tr: Text file containing translations, where <NAME> is an arbitrary identifier (usually the same as the technical mod name) and <LANGUAGE CODE> is the language code. Example: The German translation file for the default mod is called “default.de.tr”.

The *.tr files follow a simple syntax:

  • Lines of the form “# textdomain:<CONTEXT>” specify the context. Translators: ignore this
  • Empty lines and other lines that start with “#” are ignored. They might contain some comments for translators, however
  • All other lines must contain translations of the form <ENGLISH>=<TRANSLATION>

Translators only need to care about the last point. The English original text comes left from the equals sign, the translation is right from the equals sign. Do not insert trailing or leading spaces.

To start a new translation, simply copy the file template.txt and create a *.tr file with the appropriate name.

Special character sequences

Some characters like the equals sign cannot be used directly in the texts. Therefore, you must sometimes use special character sequences.

  • @@: Will be replaced with @.
  • @=: Will be replaced with =.
  • @n: Will be replaced by a newline.
  • @ followed by an actual newline: Will be replaced by a newline.
  • @1, ..., @9: A placeholder. Minetest will replace this with an arbitrary text, for example, a word or a number.

Example

Take for example this translation template for a mod called “example” (file name: template.txt):

# textdomain:example
Apple=
Pineapple=
Silver Ingot=
You gave @1 a cookie.=

A valid German translation would look like this (file name: example.de.tr):

# textdomain:example
Apple=Apfel
Pineapple=Ananas
Silver Ingot=Silberbarren
You gave @1 a cookie.=Sie gaben @1 einen Keks.

How to make a mod or game translatable

Please refer to the official Lua API documentation (lua_api.txt).

Untranslatable texts

Please note: A couple of things in Minetest can not be translated yet:

  • Setting help texts for settings of games and mods (settingtypes.txt) (#9070)
  • Everything that comes from builtin, including the help texts for the built-in server commands and privileges (#7883)
  • Description of mods, modpacks, games and texture packs (#9071)
  • Other (#7880)