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 template in $(find . -name '*.xml'); do
27 echo "* converting .xml files: $(basename $template)"
28 sed -e 's/<label>/<?php $t= _("/g;s!</label>!");?>!g' $template > $template.new
29 mv $template.new $template
30 done
32 for class in $(find . -name 'class_*.inc'); do
33 echo "* converting class_*.inc files: $(basename $class)"
34 sed -e 's/\($pl[DH][^=]*\)= *"\([^"]*\)";$/\1= _("\2");/g' $class > $class.new
35 mv $class.new $class
36 done
38 echo "Extracting languages..."
39 [ -f locale/${l_path}messages.po ] && rm locale/${l_path}messages.po
40 find . -name '*.[ctpix][mophn][nlpc]' | xgettext -f - --keyword=must -d Domain -L PHP -n -o locale/${l_path}messages.po
42 echo "Merging po files with existing ones"
43 error=0
44 for f in locale/${l_path}*/LC_MESSAGES; do
45 [[ "$f" == "locale/${l_path}/LC_MESSAGES" ]] && break
46 echo -n "* merging $f/messages.po: "
47 [ ! -f $f/messages.po ] && touch $f/messages.po
49 # If we're in a plugin of a trunk checkout, we can use the gosa-all messages.po as a dictionary
50 DICT_FILE_ALL="$ORIG/../../gosa-all/gosa/${f/locale/locale/core}/messages.po"
51 DICT_FILE_CORE="$ORIG/../../gosa-core/${f/locale/locale/core}/messages.po"
52 DICT=""
53 [ -r $DICT_FILE_ALL ] && DICT="-C $DICT_FILE_ALL"
54 [ ${#DICT} -eq 0 ] && [ -r $DICT_FILE_CORE ] && DICT="-C $DICT_FILE_CORE"
55 msgmerge $DICT $f/messages.po locale/${l_path}messages.po --output-file=$f/messages.po.tmp &> /dev/null
57 # Filter out duplicates
58 msguniq $f/messages.po.tmp --output-file=$f/messages.po.new &> /dev/null
59 rm $f/messages.po.tmp
61 # Do an extra check for dummy dir 'locale/en/LC_MESSAGES'
62 if [ $? -ne 0 ]; then
63 [ "$f" == "locale/${l_path}en/LC_MESSAGES" ] && $TRUE
64 fi
66 if [ $? -eq 0 ]; then
67 echo "done";
68 else
69 echo "failed";
70 error=1
71 fi
73 done
75 echo "Copying new po files, making backups..."
76 find locale/${l_path} -name messages.po | while read f; do
78 if [ -f $ORIG/$f ]; then
79 mv $ORIG/$f $ORIG/$f.orig
80 fi
82 echo $f | grep -q "locale/${l_path}messages.po"
83 if [ $? -ne 0 ]; then
84 echo "* replaced $ORIG/$f"
85 cp $f.new $ORIG/$f
86 else
87 cp $f $ORIG/$f
88 fi
90 done
92 rm -rf $TEMPDIR
94 echo
95 if [ $error -eq 0 ]; then
96 if [ $ASSUME_Y -eq 1 ]; then
97 find $ORIG/ -type f -name 'messages.po.orig' -exec rm -f {} \;
98 else
99 read -p "Do you want to erase the message.po.orig files? (y/n)" -n1 ans
101 if [ "$ans" == "y" -o "$ans" == "Y" ]; then
102 find $ORIG/ -type f -name 'messages.po.orig' -exec rm -f {} \;
103 fi
104 fi
106 else
107 echo "There were errors during the transition. Please fix!"
108 exit 1
109 fi
111 cat <<-EOF
113 ---------------------------------------------------------------------
115 Now edit all files that have been replaced above (i.e. using kbabel
116 or gtranslator) and mail the changes to gosa@oss.gonicus.de to be
117 included in the next release.
119 To see the changes you've made in GOsa, run "msgfmt messages.po" on
120 your freshly edited files and restart your apache after that. Set
121 the webbrowser to the language you've edited and go back to the
122 login screen.
124 ---------------------------------------------------------------------
126 EOF
128 popd &> /dev/null
129 }
131 #
132 # MAIN
133 #
134 GENERATE=0
135 ASSUME_Y=0
136 while getopts ":gyh" opt
137 do
138 case $opt in
139 g) GENERATE=1;
140 ;;
141 y) ASSUME_Y=1;
142 ;;
143 h|--help)
144 echo "Usage: $(basename $0) [-g] [-y]"
145 echo " -g extract strings from GOsa and generate po files"
146 echo " -y assume yes"
147 exit 1
148 ;;
149 esac
150 done
151 shift $(($OPTIND - 1))
153 # If there's a plugin.dsc in ., then assume "plugin"
154 if [ -f plugin.dsc ]; then
155 l_path=""
156 else
157 l_path="core/"
158 fi
160 # Default to generate
161 if [ $GENERATE -eq 0 ]; then
162 GENERATE=1
163 fi
165 [ $GENERATE -eq 1 ] && generate_po
167 # vim:tabstop=2:expandtab:shiftwidth=2:syntax:ruler: