Launchpad automatic translations update.
[odoo/odoo.git] / gen_translations.sh
1 #!/bin/sh
2
3 usage() {
4 cat << EOF
5 usage: $0 -a [DIR]
6 usage: $0 <ADDON_DIR> <OUTPUT_FILE>
7
8 OPTIONS:
9    -a [DIR]  export the .pot files for all web addons found
10              at target path (default: ./addons) 
11    -h        print this message
12 EOF
13 exit 0
14 }
15
16 do_all=
17
18 while getopts "a" opt
19 do
20     case "$opt" in
21     a) 
22         do_all=true;;
23     h)
24         usage;;
25     \?)
26         usage;;  
27   esac
28 done
29
30 shift $((OPTIND-1))
31
32 if [ -n "$do_all" ]
33 then
34     if [ "x$(which msgcat)" = "x" ]
35     then
36         echo "The msgcat command from the gettext tools is required in the PATH."
37         echo "On a Debian/Ubuntu system you may install gettext via 'sudo apt-get install gettext'"
38         exit 1
39     fi
40
41     echo "Extracting all web addons translations"
42     executable=$0
43     target_dir=${1:-./addons}
44     echo "Using target dir: ${target_dir}"
45     for mod in $(find ${target_dir} -type d -name 'static' -exec sh -c 'basename $(dirname {})' \;); do
46        echo ${mod}
47        mod_pot=${target_dir}/${mod}/i18n/${mod}.pot
48        web_pot=${mod_pot}.web 
49        mkdir -p $(dirname ${web_pot})
50        $executable ${target_dir}/${mod} ${web_pot} 
51        if [ -f "${mod_pot}" ]; then
52          echo "Merging with existing PO file: ${mod_pot}"
53          msgcat --force-po -o "${mod_pot}.tmp" ${mod_pot} ${web_pot}
54          mv ${mod_pot}.tmp ${mod_pot}
55          rm ${web_pot}
56        else
57          echo "Renaming to final PO file: ${mod_pot}"
58          mv ${web_pot} ${mod_pot}
59        fi
60     done
61 elif [ -n "$2" ]
62 then
63     ./npybabel.py extract -F babel.cfg -o $2 -k _t -k _lt --no-default-keywords $1
64 else
65     usage
66 fi