How to Internationalize Shell Scripts
Modification of the original script
(We shall take excerpts from the script keyboardsetup as an example.)
Add the following lines after the usual introductory comments but before your actual code starts:
Example
Before modification:
After modification:
Put the following tags around the strings that need to be translated:
Example
Before modification:
After Modification:
Translation process
We first need to extract the strings to be translated from the shell script to a model file that will be distributed to the translators. To do this, run the following command from the working directory where the shell script is located:
Example
Each translator will use the model file to generate his own translation work file by running the following command from the directory where the .pot file (our translation model) is located. It is assumed that the environment locale of his operating system is the same as the locale he wants to translate into (or else he should consult the man page of msginit):
Example
Translate using PoEdit
The easiest way to localize a gettext software is to install poedit from the repositories.
If there is already a .po file for your language and you just want to update/correct it, you can open the .po file directly with poedit.
If a .po file for your language doesn't exist yet, you can create one easily with poedit, just select "New catalog from .POT file" from the file menu, add your details and start translating!
Remember to save the .po file you created like this:
Example
Translate without PoEdit
If there is no .po file for your language yet, you can create one from the .pot file with a command like this:
Example
When you create a .po file, or if one is already there, you can start editing it directly. Looking into the file is self explanatory, using a text editor of his choice each translator translate the strings in his language .po file.
Example
Before:
After:
Testing your translations
If you want to test your translation, you need to create a .mo file from the .po file, like this:
Example
The .mo filename should be exactly the same as the tool you are translating.
You can then place the .mo file you generated into its appropriate locale directory:
Example
Sending your translations
You can send your .po files to the salix-main mailing list (or the software author email) and they will be included in future versions of salixtools or other software. If it's a salixtools, just send an email to [mailto:salix-main@lists.sourceforge.net] attaching your .po files.
Extending the translations to the shell script
When the maintainer of the shell script receives back a completed .po file from a translator, he first compiles it by running the following command (from the working directory where the translated po file is located):
Example
Then he places the .mo file he generated into its appropriate locale directory:
Example
That's all!
Maintenance
Maintenance of the shell script & future translations:
If later on, the shell script is modified, its maintainer will issue a new .pot (model) file which he can send back to the translators.
Each translator will then have to run the following command in order to generate a new .po file for their language that will include their previous translation work as well as the new strings net yet translated. Both the new .pot file & the last translated .po file should be located in the directory where this command is issued.
Example
And then redo the missing translations.