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 [ -f locale/messages.po ] && 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 [[ "$f" == "locale/??/LC_MESSAGES" ]] && break
40 echo -n "* merging $f/messages.po: "
41 [ -f $f/messages.po ] && msgmerge $f/messages.po locale/messages.po --output-file=$f/messages.po.new &> /dev/null
43 # Do an extra check for dummy dir 'locale/en/LC_MESSAGES'
44 if [ $? -ne 0 ]; then
45 [ "$f" == "locale/en/LC_MESSAGES" ] && $TRUE
46 fi
48 if [ $? -eq 0 ]; then
49 echo "done";
50 else
51 echo "failed";
52 error=1
53 fi
55 done
57 echo "Copying new po files, making backups..."
58 find . -name messages.po | while read f; do
60 if [ -f $ORIG/$f ]; then
61 mv $ORIG/$f $ORIG/$f.orig
62 fi
64 echo $f | grep -q "locale/messages.po"
65 if [ $? -ne 0 ]; then
66 echo "* replaced $ORIG/$f"
67 cp $f.new $ORIG/$f
68 else
69 cp $f $ORIG/$f
70 fi
72 done
74 rm -rf $TEMPDIR
76 echo
77 if [ $error -eq 0 ]; then
78 if [ $ASSUME_Y -eq 1 ]; then
79 find $ORIG/ -type f -name 'messages.po.orig' -exec rm -f {} \;
80 else
81 read -p "Do you want to erase the message.po.orig files? (y/n)" -n1 ans
83 if [ "$ans" == "y" -o "$ans" == "Y" ]; then
84 find $ORIG/ -type f -name 'messages.po.orig' -exec rm -f {} \;
85 fi
86 fi
88 else
89 echo "There were errors during the transition. Please fix!"
90 exit 1
91 fi
93 cat <<-EOF
95 ---------------------------------------------------------------------
97 Now edit all files that have been replaced above (i.e. using kbabel
98 or gtranslator) and mail the changes to gosa@oss.gonicus.de to be
99 included in the next release.
101 To see the changes you've made in GOsa, run "msgfmt messages.po" on
102 your freshly edited files and restart your apache after that. Set
103 the webbrowser to the language you've edited and go back to the
104 login screen.
106 ---------------------------------------------------------------------
108 EOF
110 popd &> /dev/null
111 }
113 #
114 # MAIN
115 #
116 GENERATE=0
117 COMPILE=0
118 ASSUME_Y=0
119 while getopts ":gyh" opt
120 do
121 case $opt in
122 g) GENERATE=1;
123 ;;
124 y) ASSUME_Y=1;
125 ;;
126 h|--help)
127 echo "Usage: $(basename $0) [-g] [-y]"
128 echo " -g extract strings from GOsa and generate po files"
129 echo " -y assume yes"
130 exit 1
131 ;;
132 esac
133 done
134 shift $(($OPTIND - 1))
136 # Default to generate
137 if [ $GENERATE -eq 0 -a $COMPILE -eq 0 ]; then
138 GENERATE=1
139 fi
141 [ $GENERATE -eq 1 ] && generate_po
143 # vim:tabstop=2:expandtab:shiftwidth=2:syntax:ruler: