1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
# Tue Feb 24 19:59:40 CET 2009 <jelledejong@powercraft.nl> <http://www.tuxcrafter.net/>
# 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 <jelledejong@powercraft.nl>
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 <jelledejong@powercraft.nl>
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:~$
|