1403.00
[voxelands/voxelands-menche.git] / util / updatepot.sh
blob9de10489b53479ea2aefb5697013e9df2fd6d1c1
1 #!/bin/sh
4 # Update/create voxelands po and pot files
6 # To update only the pot file, execute this script with `./updatepot.sh`.
7 # You should do this with each modification, addition, or deletion of a
8 # translatable string in the source code, to give translators the most amount
9 # of time possible to translate it before the next release. (Transifex
10 # automatically pulls that file)
12 # To update the pot file and source texts in the po files, execute this script
13 # with `./updatepot.sh --po`. Though so long as we use Transifex, we shouldn't
14 # need to use this option.
16 # To start a localization for a new language, create a directory for it in po/
17 # named as it's language code, then execute this script with
18 # `./updatepot.sh --po`. But again, as long as we use Transifex, we shouldn't
19 # need to use this option.
21 # In the above examples, I execute this script from the current directory,
22 # however it can actually be executed from any directory.
24 # Because we use the --package-name flag, you must have xgettext>=0.17 for
25 # this script to work. Use `xgettext -V` to check which version you have.
28 # an auxiliary function to abort processing with an optional error message
29 abort() {
30 test -n "$1" && echo >&2 "$1"
31 exit 1
34 # If flags exist, and are written incorrectly, abort.
35 # Because this is currently the only flag available, I simply used a couple
36 # if statements to make it work. However in the future, if we want more
37 # options, we may need to switch to something more advanced, like getopt.
38 if [[ -n $1 ]] && [[ ! $1 == "--po" ]]; then
39 abort "'$1' is not a valid option"
42 # The po/ directory is assumed to be parallel to the directory where
43 # this script is. Relative paths are fine for us so we can just
44 # use the following trick (works both for manual invocations and for
45 # script found from PATH)
46 scriptisin="$(dirname "$(which "$0")")"
48 # Commands below are executed from the parent of po/, which is also the
49 # parent of this script's directory and of the src/ directory.
50 # We go through $scriptisin so that this script can be executed from whatever
51 # directory and still work correctly
52 cd "$scriptisin/.."
54 test -e po || abort "po/ directory not found"
55 test -d po || abort "po/ should be a directory, but is not!"
57 # Create a list of the languages we have to update/create.
58 # This assumes that we won't have dirnames with spaces, which is
59 # the case for language codes, which are the only subdirs we expect to
60 # find in po/ anyway. If you put anything else there, you need to suffer
61 # the consequences of your actions, so we don't do sanity checks
62 cd po || abort "couldn't change directory to po!"
64 langs=""
66 for lang in * ; do
67 if test ! -d $lang; then
68 continue
70 langs="$langs $lang"
71 done
73 # First thing first, update the .pot template. We place it in the po/
74 # directory at the top level.
75 echo "updating the pot file"
77 # go to parent dir of po/ and src/
78 cd ..
80 potfile=po/voxelands.pot
81 xgettext --package-name=voxelands --copyright-holder="Lisa 'darkrose' Milne" -kN_ -kwgettext -F -n -o $potfile src/*.cpp src/*.h
83 # We just updated the pot file, now update po files if --po was specified.
84 if [[ $1 == "--po" ]]; then
85 # Now iterate on all language dirs in po/ and create the po file if
86 # nonexistent, or update it if it exists already
87 for lang in $langs ; do # note the missing quotes around $langs
88 pofile=po/$lang/voxelands.po
89 if test -e $pofile; then
90 echo "[$lang]: updating strings"
91 msgmerge -F -U $pofile $potfile
92 else
93 # This creates a new po file and asks for the translator's identity
94 echo "[$lang]: creating $lang localization files"
95 msginit -l $lang -o $pofile -i $potfile
97 done