# Tue Feb 24 19:59:40 CET 2009 # http://mywiki.wooledge.org/BashFAQ/098 # localization: http://pgas.freeshell.org/mirror/ABSlocalization.html http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/localization.html # gettext http://www.gnu.org/software/gettext/manual/html_node/index.html # step 1: update your strings # before translation function version() { echo "Usage: $0 --help" echo "Version: $version" echo "Author: $author" echo "Donation: $donation" } # after translation function version() { echo $"Usage: $0 --help" echo $"Version: $version" echo $"Author: $author" echo $"Donation: $donation" } # step 2: create some sort of structure for your source mkdir --parent --verbose locale/nl/LC_MESSAGES/ mkdir --parent --verbose lang # step 3: check the strings bash -D pct-scanner-script bash -D pct-scanner-script-process # step 4: dump po strings to your directory bash --dump-po-strings pct-scanner-script > lang/pct-scanner-script-nl.pot bash --dump-po-strings pct-scanner-script-process > lang/pct-scanner-script-process-nl.pot # step 5: try to merge existing po with new updates # remove duplicated strings by hand or with sed or something else # awk '/^msgid/&&!seen[$0]++;!/^msgid/' lang/nl.pot > lang/nl.pot.new msgmerge lang/nl.po lang/nl.pot # step 5.1: try to merge existing po with new updates cp --verbose lang/pct-scanner-script-nl.po lang/pct-scanner-script-nl.po.old awk '/^msgid/&&!seen[$0]++;!/^msgid/' lang/pct-scanner-script-nl.pot > lang/pct-scanner-script-nl.pot.new msgmerge lang/pct-scanner-script-nl.po.old lang/pct-scanner-script-nl.pot.new > lang/pct-scanner-script-nl.po # step 5.2: try to merge existing po with new updates touch lang/pct-scanner-script-process-nl.po lang/pct-scanner-script-process-nl.po.old awk '/^msgid/&&!seen[$0]++;!/^msgid/' lang/pct-scanner-script-process-nl.pot > lang/pct-scanner-script-process-nl.pot.new msgmerge lang/pct-scanner-script-process-nl.po.old lang/pct-scanner-script-process-nl.pot.new > lang/pct-scanner-script-process-nl.po # step 6: create .mo file msgfmt -o locale/nl/LC_MESSAGES/pct-scanner-script.mo lang/pct-scanner-script-nl.po msgfmt -o locale/nl/LC_MESSAGES/pct-scanner-script-process.mo lang/pct-scanner-script-process-nl.po # step 7: move single .mo file to system locales sudo cp --verbose locale/nl/LC_MESSAGES/pct-scanner-script.mo /usr/share/locale/nl/LC_MESSAGES/ sudo chown root:root /usr/share/locale/nl/LC_MESSAGES/pct-scanner-script.mo sudo chmod 644 /usr/share/locale/nl/LC_MESSAGES/pct-scanner-script.mo sudo ls -hal /usr/share/locale/nl/LC_MESSAGES/pct-scanner-script.mo # step 8: move all .mo files to system locales sudo cp --verbose --recursive locale/* /usr/share/locale/ sudo chown root:root /usr/share/locale/nl/LC_MESSAGES/pct-scanner-*.mo sudo chmod 644 /usr/share/locale/nl/LC_MESSAGES/pct-scanner-*.mo sudo ls -hal /usr/share/locale/nl/LC_MESSAGES/pct-scanner-*.mo # step 9: add the following to you bash script under #!/bin/bash TEXTDOMAINDIR=/usr/share/locale TEXTDOMAIN=pct-scanner-script # step 10: start testing LANG=nl_NL bash pct-scanner-script --version LANG=en_GB bash pct-scanner-script --version ------------------------------------------------------------------------ # sudo dpkg-reconfigure locales export LANG=en_GB export TEXTDOMAINDIR=/usr/share/locale export TEXTDOMAIN=pct-scanner-script echo $"lineart: yes" echo $"color: yes" echo $"source: $SOURCE" echo $"testing" LANG=nl_NL TEXTDOMAINDIR=/usr/share/locale TEXTDOMAIN=pct-scanner-script echo $"lineart: yes" echo $"color: yes" echo $"source: $SOURCE" echo $"testing" ------------------------------------------------------------------------ jelle@debian-eeepc:~/packages-checkout/source/pct-scanner-scripts/pct-scanner-scripts-devel$ LANG=nl_NL jelle@debian-eeepc:~/packages-checkout/source/pct-scanner-scripts/pct-scanner-scripts-devel$ bash pct-scanner-script --version Gebruik: pct-scanner-script --help Versie: 0.0.5 Maker: Jelle de Jong Donatie: http://www.tuxcrafter.net/pages/contact.html#paypal-donation jelle@debian-eeepc:~/packages-checkout/source/pct-scanner-scripts/pct-scanner-scripts-devel$ jelle@debian-eeepc:~/packages-checkout/source/pct-scanner-scripts/pct-scanner-scripts-devel$ LANG=en_GB jelle@debian-eeepc:~/packages-checkout/source/pct-scanner-scripts/pct-scanner-scripts-devel$ bash pct-scanner-script --version Usage: pct-scanner-script --help Version: 0.0.5 Author: Jelle de Jong Donation: http://www.tuxcrafter.net/pages/contact.html#paypal-donation jelle@debian-eeepc:~/packages-checkout/source/pct-scanner-scripts/pct-scanner-scripts-devel$ ------------------------------------------------------------------------ jelle@debian-eeepc:~$ export LANG=en_GB jelle@debian-eeepc:~$ export TEXTDOMAINDIR=/usr/share/locale jelle@debian-eeepc:~$ export TEXTDOMAIN=pct-scanner-script jelle@debian-eeepc:~$ echo $"lineart: yes" lineart: yes jelle@debian-eeepc:~$ echo $"color: yes" color: yes jelle@debian-eeepc:~$ echo $"source: $SOURCE" source: jelle@debian-eeepc:~$ echo $"testing" testing jelle@debian-eeepc:~$ jelle@debian-eeepc:~$ LANG=nl_NL jelle@debian-eeepc:~$ TEXTDOMAINDIR=/usr/share/locale jelle@debian-eeepc:~$ TEXTDOMAIN=pct-scanner-script jelle@debian-eeepc:~$ echo $"lineart: yes" lineart: ja jelle@debian-eeepc:~$ echo $"color: yes" kleur: ja jelle@debian-eeepc:~$ echo $"source: $SOURCE" bron: jelle@debian-eeepc:~$ echo $"testing" dit is een test jelle@debian-eeepc:~$ ------------------------------------------------------------------------ jelle@debian-eeepc:~$ sudo dpkg-reconfigure locales Generating locales (this might take a while)... en_GB.ISO-8859-1... done en_GB.ISO-8859-15... done en_GB.UTF-8... done nl_NL.ISO-8859-15@euro... done nl_NL.ISO-8859-1... done nl_NL.UTF-8... done Generation complete. jelle@debian-eeepc:~$ locale -a C dutch en_GB en_GB.iso88591 en_GB.iso885915 en_GB.utf8 nl_NL nl_NL@euro nl_NL.iso88591 nl_NL.iso885915@euro nl_NL.utf8 POSIX jelle@debian-eeepc:~$