Code

Apply patch for #5508
[gosa.git] / trunk / 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
43     # If we're in a plugin of a trunk checkout, we can use the gosa-all messages.po as a dictionary
44     DICT_FILE_ALL="$ORIG/../../gosa-all/gosa/${f/locale/locale/core}/messages.po"
45     DICT_FILE_CORE="$ORIG/../../gosa-core/${f/locale/locale/core}/messages.po"
46     DICT=""
47     [ -r $DICT_FILE_ALL ] && DICT="-C $DICT_FILE_ALL"
48     [ ${#DICT} -eq 0 ] && [ -r $DICT_FILE_CORE ] && DICT="-C $DICT_FILE_CORE"
49     msgmerge $DICT $f/messages.po locale/${l_path}messages.po --output-file=$f/messages.po.tmp &> /dev/null
51     # Filter out duplicates
52     msguniq $f/messages.po.tmp --output-file=$f/messages.po.new &> /dev/null
53     rm $f/messages.po.tmp
55     # Do an extra check for dummy dir 'locale/en/LC_MESSAGES'
56     if [ $? -ne 0 ]; then
57       [ "$f" == "locale/${l_path}en/LC_MESSAGES" ] && $TRUE
58     fi
60     if [ $? -eq 0 ]; then
61       echo "done";
62     else
63       echo "failed";
64       error=1
65     fi
67   done
69   echo "Copying new po files, making backups..."
70   find locale/${l_path} -name messages.po | while read f; do
72     if [ -f $ORIG/$f ]; then
73       mv $ORIG/$f $ORIG/$f.orig
74     fi
76     echo $f | grep -q "locale/${l_path}messages.po"
77     if [ $? -ne 0 ]; then
78       echo "* replaced $ORIG/$f"
79       cp $f.new $ORIG/$f
80     else
81       cp $f $ORIG/$f
82     fi
84   done
86   rm -rf $TEMPDIR
88   echo
89   if [ $error -eq 0 ]; then
90     if [ $ASSUME_Y -eq 1 ]; then
91       find $ORIG/ -type f -name 'messages.po.orig' -exec rm -f {} \;
92     else
93       read -p "Do you want to erase the message.po.orig files? (y/n)" -n1 ans
95       if [ "$ans" == "y" -o "$ans" == "Y" ]; then
96         find $ORIG/ -type f -name 'messages.po.orig' -exec rm -f {} \;
97       fi
98     fi
100   else
101     echo "There were errors during the transition. Please fix!"
102     exit 1
103   fi
105 cat <<-EOF
107 ---------------------------------------------------------------------
109 Now edit all files that have been replaced above (i.e. using kbabel
110 or gtranslator) and mail the changes to gosa@oss.gonicus.de to be 
111 included in the next release.
113 To see the changes you've made in GOsa, run "msgfmt messages.po" on
114 your freshly edited files and restart your apache after that. Set
115 the webbrowser to the language you've edited and go back to the
116 login screen.
118 ---------------------------------------------------------------------
120 EOF
122   popd &> /dev/null
126 # MAIN
128 GENERATE=0
129 ASSUME_Y=0
130 while getopts ":gyh" opt
131 do
132   case $opt in
133     g) GENERATE=1;
134        ;;
135     y) ASSUME_Y=1;
136        ;;
137     h|--help)
138        echo "Usage: $(basename $0) [-g] [-y]"
139        echo "       -g extract strings from GOsa and generate po files"
140        echo "       -y assume yes"
141        exit 1
142        ;;
143   esac
144 done
145 shift $(($OPTIND - 1))
147 # If there's a plugin.dsc in ., then assume "plugin"
148 if [ -f plugin.dsc ]; then
149         l_path=""
150 else
151         l_path="core/"
152 fi
154 # Default to generate
155 if [ $GENERATE -eq 0 ]; then
156   GENERATE=1
157 fi
159 [ $GENERATE -eq 1 ] && generate_po
161 # vim:tabstop=2:expandtab:shiftwidth=2:syntax:ruler: