You need to follow these steps:
- Determine that the name of your project, gettext calls it textdomain, you will need it to get the translation for your project. Let me call him "PRJ".
- Mark the lines you want to translate. The following snippet gives an example:
(let's call it PRJ.sh )
#!/bin/sh alias GETTEXT='gettext "PRJ"'
- Create a .pot file so that translators can work on it.
Run the following command, it only searches for GETTEXT, the ones you really want to translate.
xgettext -o PRJ.pot -L Shell --keyword --keyword=GETTEXT PRJ.sh
- (Optional) Create .po files.
For each locale you want to cover.
msginit -i PRJ.pot -l fr.UTF-8
Please note that "UTF-8" is requested, otherwise msginit may mistakenly choose outdated encoding for you.
- Get completed .po files and convert them to .mo file
(file that the machine can read)
msgfmt -v fr.po -o fr.mo
- Install .mo files
Run:
sudo install fr.mo /usr/share/locale/fr/LC_MESSAGES/PRJ.mo
Now you can try the result:
LANGUAGE=fr ./PRJ.sh
and you should see the French translation for Hello world.
source share