e93a247064e584c0ae48f877d5779f88cdbe8487
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 ] && msgmerge $f/messages.po locale/${l_path}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/${l_path}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 locale/${l_path} -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/${l_path}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 ASSUME_Y=0
118 while getopts ":gyh" opt
119 do
120 case $opt in
121 g) GENERATE=1;
122 ;;
123 y) ASSUME_Y=1;
124 ;;
125 h|--help)
126 echo "Usage: $(basename $0) [-g] [-y] method"
127 echo " method can be 'core' or 'plugin'"
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 # Check method
137 if [ "$1" != "plugin" -a "$1" != "core" ]; then
138 echo "Need explicit method 'core' or 'plugin' to create locale."
139 exit 1
140 fi
141 if [ "$1" == "plugin" ]; then
142 l_path=""
143 else
144 l_path="core/"
145 fi
147 # Default to generate
148 if [ $GENERATE -eq 0 ]; then
149 GENERATE=1
150 fi
152 [ $GENERATE -eq 1 ] && generate_po
154 # vim:tabstop=2:expandtab:shiftwidth=2:syntax:ruler: