1 #!/bin/sh
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 "* converting strings from gosa.conf"
33 sed -e 's/headline="\([^"]*\)"/<?php $headline=_("\1");?>/g;s/name="\([^"]*\)"/<?php $t= _("\1");?>/g' contrib/gosa.conf > contrib/gosa.conf.new
34 mv contrib/gosa.conf.new contrib/gosa.conf
36 echo "Extracting languages..."
37 rm locale/messages.po
38 (echo contrib/gosa.conf; find . -name '*.[ctpi][ophn][nlpc]') | xgettext -f - --keyword=must -d Domain -L PHP -n -o locale/messages.po
40 echo "Merging po files with existing ones"
41 error=0
42 for f in locale/??/LC_MESSAGES; do
43 echo -n "* merging $f/messages.po: "
44 [ -f $f/messages.po ] && msgmerge $f/messages.po locale/messages.po --output-file=$f/messages.po.new &> /dev/null
46 # Do an extra check for dummy dir 'locale/en/LC_MESSAGES'
47 if [ $? -ne 0 ]; then
48 [ "$f" == "locale/en/LC_MESSAGES" ] && $TRUE
49 fi
51 if [ $? -eq 0 ]; then
52 echo "done";
53 else
54 echo "failed";
55 error=1
56 fi
58 done
60 echo "Copying new po files, making backups..."
61 find . -name messages.po | while read f; do
63 if [ -f $ORIG/$f ]; then
64 mv $ORIG/$f $ORIG/$f.orig
65 else
66 continue
67 fi
69 echo $f | grep -q "locale/messages.po"
70 if [ $? -ne 0 ]; then
71 echo "* replaced $ORIG/$f"
72 cp $f.new $ORIG/$f
73 else
74 cp $f $ORIG/$f
75 fi
77 done
79 rm -rf $TEMPDIR
81 echo
82 if [ $error -eq 0 ]; then
83 if [ $ASSUME_Y -eq 1 ]; then
84 find $ORIG/ -type f -name 'messages.po.orig' -exec rm -f {} \;
85 else
86 read -p "Do you want to erase the message.po.orig files? (y/n)" -n1 ans
88 if [ "$ans" == "y" -o "$ans" == "Y" ]; then
89 find $ORIG/ -type f -name 'messages.po.orig' -exec rm -f {} \;
90 fi
91 fi
93 else
94 echo "There were errors during the transition. Please fix!"
95 exit 1
96 fi
98 cat <<-EOF
100 ---------------------------------------------------------------------
102 Now edit all files that have been replaced above (i.e. using kbabel
103 or gtranslator) and mail the changes to gosa@oss.gonicus.de to be
104 included in the next release.
106 To see the changes you've made in GOsa, run "msgfmt messages.po" on
107 your freshly edited files and restart your apache after that. Set
108 the webbrowser to the language you've edited and go back to the
109 login screen.
111 ---------------------------------------------------------------------
113 EOF
115 popd &> /dev/null
116 }
118 compile_po()
119 {
120 po='messages.po'
121 mo='messages.mo'
123 echo "Compiling po files..."
124 for f in locale/??/LC_MESSAGES; do
126 if [ -f $f/$po ]; then
127 echo "* compiling $f/$po"
128 msgfmt $f/$po -o $f/$mo
129 else
130 echo "! skipped $f/$po - does not exist"
131 error=1
132 continue
133 fi
135 done
136 }
138 #
139 # MAIN
140 #
141 GENERATE=0
142 COMPILE=0
143 ASSUME_Y=0
144 while getopts ":cgyh" opt
145 do
146 case $opt in
147 c) COMPILE=1
148 ;;
149 g) GENERATE=1;
150 ;;
151 y) ASSUME_Y=1;
152 ;;
153 h|--help)
154 echo "Usage: $(basename $0) [-c] [-g] [-y]"
155 echo " -c compile existing po files into mo files"
156 echo " -g extract strings from GOsa and generate po files"
157 echo " -y assume yes"
158 exit 1
159 ;;
160 esac
161 done
162 shift $(($OPTIND - 1))
164 # Default to generate
165 if [ $GENERATE -eq 0 -a $COMPILE -eq 0 ]; then
166 GENERATE=1
167 fi
169 [ $GENERATE -eq 1 ] && generate_po
170 [ $COMPILE -eq 1 ] && compile_po
172 # vim:tabstop=2:expandtab:shiftwidth=2:syntax:ruler: