Localization of scriptsExplains how to add translation capabilities to your scripts
Adding the translated versions of the strings adds a great value to your scripts. The process of translating a part of software is called localization. KVIrc offers some commands and functions for this purpose and this document explains briefly how to use them.
The big picture
All of the strings in your script are written in a "primary language". The most common "primary language" is english, but theoretically it can be any language of your choice.
By the means of the gettext package programs you extract the strings from your script and produce a translation file.
The translation file is then effectively translated in another language and later compiled in a binary form.
The binary form translations are then loaded in the KVIrc executable at runtime and a function is used to look up the translations.
How to translate scripts
Your strings should be surrounded by the $tr() function in the following way:
Then you should run the xgettext command on your script files.
This is done by a shell commandline similar to the following:
Copy the translation file obtained in the following way:
cp myscript.pot myscript_XX.potWhere the XX is your country/language code. For example, for Italian it would be:
cp myscript.pot myscript_it.po
Translate mytranslation_it.po. The format of the po file is straightforward.
There are msgid lines with the original english text and immediately
following msgstr lines that must be filled with the corresponding translation.
For example in Italian you would translate:
Compile your translation to binary form with the following command:
msgfmt -o myscript_it.mo myscript_it.po
Set the system language to the XX above with the following command:
For Italian it would be:
Start KVIrc and type in the commandline:
Obviously if you don't set LANG="XX", the same command will output the original string unchanged.
You can manage translations in several languages by producing several *.mo files all with the proper language/country code appended. The right *.mo file will be magically loaded by KVIrc that will look up the user's LANG variable. (If you don't want to use LANG, you can use KVIRC_LANG instead, it will still work).
You should NEVER use variables or identifiers inside the $tr() function. This because the translation files are generated offline, when the string is not evaluated yet (i.e variables ad identifiers are not substituted by their actual return values). The translation process, instead, happens at runtime, when the variables and identifiers have been substituted by their actual values. This would lead to a mismatch between the string you look up in the translation catalogue and the effectively translated one. If you need to include variables in your strings you should compose the string with smaller pieces
The translation process can be realized only if your scripts are written in external files. This makes sense since if you're translating the script then you will probably want to distribute it and the only way to distribute it is on files. But well.. this is a caveat.