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 "Extracting languages..."
33 rm locale/messages.po
34 find . -name '*.[ctpi][ophn][nlpc]' | xgettext -f - --keyword=must -d Domain -L PHP -n -o locale/messages.po
36 echo "Merging po files with existing ones"
37 error=0
38 for f in locale/??/LC_MESSAGES; do
39 echo -n "* merging $f/messages.po: "
40 [ -f $f/messages.po ] && msgmerge $f/messages.po locale/messages.po --output-file=$f/messages.po.new &> /dev/null
42 # Do an extra check for dummy dir 'locale/en/LC_MESSAGES'
43 if [ $? -ne 0 ]; then
44 [ "$f" == "locale/en/LC_MESSAGES" ] && $TRUE
45 fi
47 if [ $? -eq 0 ]; then
48 echo "done";
49 else
50 echo "failed";
51 error=1
52 fi
54 done
56 echo "Copying new po files, making backups..."
57 find . -name messages.po | while read f; do
59 if [ -f $ORIG/$f ]; then
60 mv $ORIG/$f $ORIG/$f.orig
61 else
62 continue
63 fi
65 echo $f | grep -q "locale/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 error=0
79 if [ $error -eq 0 ]; then
80 if [ $ASSUME_Y -eq 1 ]; then
81 find $ORIG/ -type f -name 'messages.po.orig' -exec rm -f {} \;
82 else
83 read -p "Do you want to erase the message.po.orig files? (y/n)" -n1 ans
85 if [ "$ans" == "y" -o "$ans" == "Y" ]; then
86 find $ORIG/ -type f -name 'messages.po.orig' -exec rm -f {} \;
87 fi
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 ---------------------------------------------------------------------
110 EOF
112 popd &> /dev/null
113 }
115 compile_po()
116 {
117 po='messages.po'
118 mo='messages.mo'
120 echo "Compiling po files..."
121 for f in locale/??/LC_MESSAGES; do
123 if [ -f $f/$po ]; then
124 echo "* compiling $f/$po"
125 msgfmt $f/$po -o $f/$mo
126 else
127 echo "! skipped $f/$po - does not exist"
128 error=1
129 continue
130 fi
132 done
133 }
135 #
136 # MAIN
137 #
138 GENERATE=0
139 COMPILE=0
140 ASSUME_Y=0
141 while getopts ":cgyh" opt
142 do
143 case $opt in
144 c) COMPILE=1
145 ;;
146 g) GENERATE=1;
147 ;;
148 y) ASSUME_Y=1;
149 ;;
150 h|--help)
151 echo "Usage: $(basename $0) [-c] [-g] [-y]"
152 echo " -c compile existing po files into mo files"
153 echo " -g extract strings from GOsa and generate po files"
154 echo " -y assume yes"
155 exit 1
156 ;;
157 esac
158 done
159 shift $(($OPTIND - 1))
161 # Default to generate
162 if [ $GENERATE -eq 0 -a $COMPILE -eq 0 ]; then
163 GENERATE=1
164 fi
166 [ $GENERATE -eq 1 ] && generate_po
167 [ $COMPILE -eq 1 ] && compile_po
169 # vim:tabstop=2:expandtab:shiftwidth=2:syntax:ruler: