Code

Branch for testing
[gosa.git] / gen_locale.sh
1 #!/bin/sh
3 ORIG=`pwd`
4 TEMPDIR="/tmp/gosa-locale"
6 echo
7 echo "Creating temporary directory..."
8 [ -d $TEMPDIR ] && rm -rf $TEMPDIR
9 mkdir $TEMPDIR
11 echo "Creating copy of GOsa..."
12 tar c . | tar x -C $TEMPDIR
14 echo -n "Converting .tpl files: "
15 pushd . &> /dev/null
16 cd $TEMPDIR
18 for template in $(find -name '*.tpl'); do
19   echo -en "\rConverting .tpl files: $(basename $template)                 \r"
20   sed -e 's/{t}/<?php $t= _("/g;s!{/t}!");?>!g' $template > $template.new
21   mv $template.new $template
22 done
24 for class in $(find -name 'class_*.inc'); do
25   echo -en "\rConverting class_*.inc files: $(basename $template)                 \r"
26   sed -e 's/\($pl[DH][^=]*\)= *"\([^"]*\)";$/\1= _("\2");/g' $class > $class.new
27   mv $class.new $class
28 done
29 echo -e "\rConverting .tpl files: done                    "
31 echo "Converting strings from gosa.conf..."
32 sed -e 's/headline="\([^"]*\)"/<?php $headline=_("\1");?>/g;s/name="\([^"]*\)"/<?php $t= _("\1");?>/g' contrib/gosa.conf > contrib/gosa.conf.new
33 mv contrib/gosa.conf.new contrib/gosa.conf
35 echo "Extracting languages..."
36 rm locale/messages.po
37 (echo contrib/gosa.conf; find . -name '*.[ctpi][ophn][nlpc]') | xgettext -f - --omit-header --keyword=must -d Domain -L PHP -n -o locale/messages.po
39 echo "Merging po files with existing ones:"
40 error=0
41 for f in locale/??/LC_MESSAGES; do
42   echo -n "* merging $f/messages.po: "
43   [ -f $f/messages.po ] && msgmerge $f/messages.po locale/messages.po --output-file=$f/messages.po.new &> /dev/null
45   # Do an extra check for dummy dir 'locale/en/LC_MESSAGES'
46   if [ $? -ne 0 ]; then
47     [ "$f" == "locale/en/LC_MESSAGES" ] && /bin/true
48   fi
50   if [ $? -eq 0 ]; then
51     echo "done";
52   else
53     echo "failed";
54     error=1
55   fi
57 done
59 echo "Copying new po files, making backups:"
60 find . -name messages.po | while read f; do
62   if [ -f $ORIG/$f ]; then
63     mv $ORIG/$f $ORIG/$f.orig
64   else
65     echo "! skipped $ORIG/$f because of errors during the conversation"
66     error=1
67     continue
68   fi
70   echo $f | grep -q "locale/messages.po"
71   if [ $? -ne 0 ]; then
72     echo "* replaced $ORIG/$f"
73     cp $f.new $ORIG/$f
74   else
75     cp $f $ORIG/$f
76   fi
78 done
80 rm -rf $TEMPDIR
82 echo
83 if [ $error -eq 0 ]; then
84   read -p "Do you want to erase the message.po.orig files? (y/n)" -n1 ans
86   if [ "$ans" == "y" -o "$ans" == "Y" ]; then
87     find $ORIG/ -type f -name 'messages.po.orig' -exec rm -f {} \;
88   fi
90 else
91   echo "There were errors during the transition. Please fix!"
92   exit 1
93 fi
95 cat << EOF
97 ---------------------------------------------------------------------
99 Now edit all files that have been replaced above (i.e. using kbabel
100 or gtranslator) and mail the changes to gosa@oss.gonicus.de to be 
101 included in the next release.
103 To see the changes you've made in GOsa, run "msgfmt messages.po" on
104 your freshly edited files and restart your apache after that. Set
105 the webbrowser to the language you've edited and go back to the
106 login screen.
108 ---------------------------------------------------------------------
109 EOF
111 popd &> /dev/null
113 # vim:tabstop=2:expandtab:shiftwidth=2:syntax:ruler: