Code

Removed bashisms
[gosa.git] / gosa-core / update-locale
1 #!/bin/bash
3 generate_po() {
4   ORIG=`pwd`
5   TEMPDIR="/tmp/gosa-locale"
6   TRUE=`which true`
8   echo
9   echo "Creating temporary directory..."
10   [ -d $TEMPDIR ] && rm -rf $TEMPDIR
11   mkdir $TEMPDIR
13   echo "Creating copy of GOsa..."
14   tar c . | tar x -C $TEMPDIR
16   echo "Converting .tpl files..."
17   pushd . &> /dev/null
18   cd $TEMPDIR
20   for template in $(find . -name '*.tpl'); do
21     echo "* converting .tpl files: $(basename $template)"
22     sed -e 's/{t}/<?php $t= _("/g;s!{/t}!");?>!g' $template > $template.new
23     mv $template.new $template
24   done
26   for class in $(find . -name 'class_*.inc'); do
27     echo "* converting class_*.inc files: $(basename $class)"
28     sed -e 's/\($pl[DH][^=]*\)= *"\([^"]*\)";$/\1= _("\2");/g' $class > $class.new
29     mv $class.new $class
30   done
32   echo "Extracting languages..."
33   [ -f locale/${l_path}messages.po ] && rm locale/${l_path}messages.po
34   find . -name '*.[ctpi][ophn][nlpc]' | xgettext -f - --keyword=must -d Domain -L PHP -n -o locale/${l_path}messages.po
36   echo "Merging po files with existing ones"
37   error=0
38   for f in locale/${l_path}??/LC_MESSAGES; do
39     [[ "$f" == "locale/${l_path}??/LC_MESSAGES" ]] && break
40     echo -n "* merging $f/messages.po: "
41     [ ! -f $f/messages.po ] && touch $f/messages.po
42     msgmerge $f/messages.po locale/${l_path}messages.po --output-file=$f/messages.po.new &> /dev/null
44     # Do an extra check for dummy dir 'locale/en/LC_MESSAGES'
45     if [ $? -ne 0 ]; then
46       [ "$f" == "locale/${l_path}en/LC_MESSAGES" ] && $TRUE
47     fi
49     if [ $? -eq 0 ]; then
50       echo "done";
51     else
52       echo "failed";
53       error=1
54     fi
56   done
58   echo "Copying new po files, making backups..."
59   find locale/${l_path} -name messages.po | while read f; do
61     if [ -f $ORIG/$f ]; then
62       mv $ORIG/$f $ORIG/$f.orig
63     fi
65     echo $f | grep -q "locale/${l_path}messages.po"
66     if [ $? -ne 0 ]; then
67       echo "* replaced $ORIG/$f"
68       cp $f.new $ORIG/$f
69     else
70       cp $f $ORIG/$f
71     fi
73   done
75   rm -rf $TEMPDIR
77   echo
78   if [ $error -eq 0 ]; then
79     if [ $ASSUME_Y -eq 1 ]; then
80       find $ORIG/ -type f -name 'messages.po.orig' -exec rm -f {} \;
81     else
82       read -p "Do you want to erase the message.po.orig files? (y/n)" -n1 ans
84       if [ "$ans" == "y" -o "$ans" == "Y" ]; then
85         find $ORIG/ -type f -name 'messages.po.orig' -exec rm -f {} \;
86       fi
87     fi
89   else
90     echo "There were errors during the transition. Please fix!"
91     exit 1
92   fi
94 cat <<-EOF
96 ---------------------------------------------------------------------
98 Now edit all files that have been replaced above (i.e. using kbabel
99 or gtranslator) and mail the changes to gosa@oss.gonicus.de to be 
100 included in the next release.
102 To see the changes you've made in GOsa, run "msgfmt messages.po" on
103 your freshly edited files and restart your apache after that. Set
104 the webbrowser to the language you've edited and go back to the
105 login screen.
107 ---------------------------------------------------------------------
109 EOF
111   popd &> /dev/null
115 # MAIN
117 GENERATE=0
118 ASSUME_Y=0
119 while getopts ":gyh" opt
120 do
121   case $opt in
122     g) GENERATE=1;
123        ;;
124     y) ASSUME_Y=1;
125        ;;
126     h|--help)
127        echo "Usage: $(basename $0) [-g] [-y]"
128        echo "       -g extract strings from GOsa and generate po files"
129        echo "       -y assume yes"
130        exit 1
131        ;;
132   esac
133 done
134 shift $(($OPTIND - 1))
136 # If there's a plugin.dsc in ., then assume "plugin"
137 if [ -f plugin.dsc ]; then
138         l_path=""
139 else
140         l_path="core/"
141 fi
143 # Default to generate
144 if [ $GENERATE -eq 0 ]; then
145   GENERATE=1
146 fi
148 [ $GENERATE -eq 1 ] && generate_po
150 # vim:tabstop=2:expandtab:shiftwidth=2:syntax:ruler: