Updated and new screenshots for Nautilus-Actions Configuration Tool 3.1
[nautilus-actions.git] / tools / check-po.sh
blob6ef92c926fe451d83b87d528ffa9cb8fca06ed58
1 #!/bin/sh
2 # Nautilus-Actions
3 # A Nautilus extension which offers configurable context menu actions.
5 # Copyright (C) 2005 The GNOME Foundation
6 # Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
7 # Copyright (C) 2009, 2010, 2011 Pierre Wieser and others (see AUTHORS)
9 # This Program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation; either version 2 of
12 # the License, or (at your option) any later version.
14 # This Program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public
20 # License along with this Library; see the file COPYING. If not,
21 # write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307, USA.
24 # Authors:
25 # Frederic Ruaudel <grumz@grumz.net>
26 # Rodrigo Moya <rodrigo@gnome-db.org>
27 # Pierre Wieser <pwieser@trychlos.org>
28 # ... and many others (see AUTHORS)
30 errs=0 # will be the exit code of the script
31 my_cmd="${0}" # e.g. "./make-ks.sh"
32 my_parms="$*" # e.g. "-host toaster"
33 my_cmdline="${my_cmd} ${my_parms}"
34 me="${my_cmd##*/}" # e.g. "make-ks.sh"
35 # used in msg and msgerr functions
36 my_tmproot="/tmp/$(echo ${me} | sed 's?\..*$??').$$"
37 # e.g. "/tmp/make-ks.1978"
39 # These three functions must be defined using the name() syntax in order
40 # to share traps with the caller process (cf. man (1) ksh).
42 trap_exit()
44 clear_tmpfiles
45 [ "${opt_verbose}" = "yes" -o ${errs} -gt 0 ] && msg "exiting with code ${errs}"
46 exit ${errs}
49 trap_int()
51 msg "quitting on keyboard interrupt"
52 let errs+=1
53 exit
56 trap_term()
58 [ "${opt_verbose}" = "yes" ] && msg "quitting on TERM signal"
59 exit
62 # setup the different trap functions
63 trap 'trap_term' TERM
64 trap 'trap_int' INT
65 trap 'trap_exit' EXIT
67 function clear_tmpfiles
69 \rm -f ${my_tmproot}.*
72 function msg
74 typeset _eol="\n"
75 [ $# -ge 2 ] && _eol="${2}"
76 printf "[%s] %s${_eol}" ${me} "${1}"
77 return 0
80 function msgerr
82 msg "error: ${1}" 1>&2
83 return $?
86 function msgwarn
88 msg "warning: ${1}" 1>&2
89 return $?
92 function msg_help
94 msg_version
95 echo "
96 This script checks for POTFILES.in consistency and completeness.
98 Usage: ${my_cmd} [options]
99 --[no]help print this message, and exit [${opt_help_def}]
100 --[no]version print script version, and exit [${opt_version_def}]
101 --[no]dummy dummy execution [${opt_dummy_def}]
102 --[no]verbose runs verbosely [${opt_verbose_def}]
103 --potfile=filename POTFILES.in to be checked [${opt_potfile_def}]"
106 function msg_version
108 pck_name=$(grep '^PACKAGE_NAME' Makefile 2>/dev/null | awk '{ print $3 }')
109 pck_version=$(grep '^PACKAGE_VERSION' Makefile 2>/dev/null | awk '{ print $3 }')
110 echo "
111 ${pck_name} v ${pck_version}
112 Copyright (C) 2010, 2011 Pierre Wieser."
115 # initialize common command-line options
116 nbopt=$#
117 opt_help=
118 opt_help_def="no"
119 opt_dummy=
120 opt_dummy_def="yes"
121 opt_version=
122 opt_version_def="no"
123 opt_verbose=
124 opt_verbose_def="no"
126 # a first loop over command line arguments to detect verbose mode
127 while :
129 # break when all arguments have been read
130 case $# in
132 break
134 esac
136 # get and try to interpret the next argument
137 _option=$1
138 shift
140 # make all options have two hyphens
141 _orig_option=${_option}
142 case ${_option} in
143 --*)
146 _option=-${_option}
148 esac
150 # now process options and their argument
151 case ${_option} in
152 --noverb | --noverbo | --noverbos | --noverbose)
153 opt_verbose="no"
155 --verb | --verbo | --verbos | --verbose)
156 opt_verbose="yes"
158 esac
159 done
161 [ "${opt_verbose}" = "yes" ] && msg "setting opt_verbose to 'yes'"
163 # we have scanned all command-line arguments in order to detect an
164 # opt_verbose option;
165 # reset now arguments so that they can be scanned again in main script
166 set -- ${my_parms}
168 # interpreting command-line arguments
169 opt_potfile=
170 opt_potfile_def="po/POTFILES.in"
172 # loop over command line arguments
173 pos=0
174 while :
176 # break when all arguments have been read
177 case $# in
179 break
181 esac
183 # get and try to interpret the next argument
184 option=$1
185 shift
187 # make all options have two hyphens
188 orig_option=${option}
189 case ${option} in
190 --*)
193 option=-${option}
195 esac
197 # split and extract argument for options that take one
198 case ${option} in
199 --*=*)
200 optarg=$(echo ${option} | sed -e 's/^[^=]*=//')
201 option=$(echo ${option} | sed 's/=.*//')
203 # these options take a mandatory argument
204 # since, we didn't find it in 'option', so it should be
205 # next word in the command line
206 --p | -po | -pot | -potf | -potfi | -potfil | -potfile)
207 optarg=$1
208 shift
210 esac
212 # now process options and their argument
213 case ${option} in
214 --d | --du | --dum | --dumm | --dummy)
215 [ "${opt_verbose}" = "yes" ] && msg "setting opt_dummy to 'yes'"
216 opt_dummy="yes"
218 --h | --he | --hel | --help)
219 [ "${opt_verbose}" = "yes" ] && msg "setting opt_help to 'yes'"
220 opt_help="yes"
222 --nod | --nodu | --nodum | --nodumm | --nodummy)
223 [ "${opt_verbose}" = "yes" ] && msg "setting opt_dummy to 'no'"
224 opt_dummy="no"
226 --noh | --nohe | --nohel | --nohelp)
227 [ "${opt_verbose}" = "yes" ] && msg "setting opt_help to 'no'"
228 opt_help="no"
230 --noverb | --noverbo | --noverbos | --noverbose)
232 --novers | --noversi | --noversio | --noversion)
233 [ "${opt_verbose}" = "yes" ] && msg "setting opt_version to 'no'"
234 opt_version="no"
236 --p | -po | -pot | -potf | -potfi | -potfil | -potfile)
237 [ "${opt_verbose}" = "yes" ] && msg "setting opt_potfile to '${optarg}'"
238 opt_version="no"
240 --verb | --verbo | --verbos | --verbose)
242 --vers | --versi | --versio | --version)
243 [ "${opt_verbose}" = "yes" ] && msg "setting opt_version to 'yes'"
244 opt_version="yes"
246 --*)
247 msgerr "unrecognized option: '${orig_option}'"
248 let errs+=1
250 # positional parameters
252 let pos+=1
253 #if [ ${pos} -eq 1 ]; then
254 # [ "${opt_verbose}" = "yes" ] && msg "setting opt_output to '${option}'"
255 # opt_output=${option}
256 #else
257 msgerr "unexpected positional parameter #${pos}: '${option}'"
258 let errs+=1
261 esac
262 done
264 # set option defaults
265 # does not work with /bin/sh ??
266 #set | grep -e '^opt_' | cut -d= -f1 | while read _name; do
267 # if [ "$(echo ${_name} | sed 's/.*\(_def\)/\1/')" != "_def" ]; then
268 # _value="$(eval echo "$"${_name})"
269 # if [ "${_value}" = "" ]; then
270 # eval ${_name}="$(eval echo "$"${_name}_def)"
271 # fi
272 # fi
273 #done
275 opt_help=${opt_help:-${opt_help_def}}
276 opt_dummy=${opt_dummy:-${opt_dummy_def}}
277 opt_verbose=${opt_verbose:-${opt_verbose_def}}
278 opt_version=${opt_version:-${opt_version_def}}
280 opt_potfile=${opt_potfile:-${opt_potfile_def}}
282 if [ "${opt_help}" = "yes" -o ${nbopt} -eq 0 ]; then
283 msg_help
284 echo ""
285 exit
288 if [ "${opt_version}" = "yes" ]; then
289 msg_version
290 echo ""
291 exit
294 if [ ! -r ${opt_potfile} ]; then
295 msgerr "${opt_potfile}: file not found or not readable"
296 let errs+=1
299 if [ ${errs} -gt 0 ]; then
300 msg "${errs} error(s) have been detected"
301 msg "try '${my_cmd} --help' for usage"
302 exit
305 # ---------------------------------------------------------------------
306 # MAIN CODE
308 totpass=5
309 nbpass=0
311 # first, check that all .ui are in po/POTFILE.in
312 nbfiles=0
313 nberrs=0
314 let nbpass+=1
315 msg "pass ${nbpass}/${totpass}: checking that all .ui are in ${opt_potfile}..."
316 for f in $(git ls-files *.ui); do
317 if [ "$(grep -xe "\[type:\s*gettext/glade]\s*${f}" ${opt_potfile})" = "" ]; then
318 msg " ${f} should be added to ${opt_potfile}"
319 let nberrs+=1
321 let nbfiles+=1
322 done
323 msg " nbfiles=${nbfiles} error(s)=${nberrs}"
324 let errs+=${nberrs}
326 # second, check that all .ui in PO exist
327 nbfiles=0
328 nberrs=0
329 let nbpass+=1
330 msg "pass ${nbpass}/${totpass}: checking that all .ui from ${opt_potfile} actually exist..."
331 for f in $(grep -e '\.ui$' ${opt_potfile} | sed 's,\[type:\s*gettext/glade]\s*,,'); do
332 if [ ! -r ${f} ]; then
333 msg " ${f} should be removed from ${opt_potfile}"
334 let nberrs+=1
336 let nbfiles+=1
337 done
338 msg " nbfiles=${nbfiles} error(s)=${nberrs}"
339 let errs+=${nberrs}
341 # third, check that all files which use _( construct are in PO
342 nbfiles=0
343 nberrs=0
344 let nbpass+=1
345 msg "pass ${nbpass}/${totpass}: checking that all translatable files are in ${opt_potfile}..."
346 for f in $(git grep '_(' src | cut -d: -f1 | sort -u); do
347 if [ "$(grep -x ${f} ${opt_potfile})" != "${f}" ]; then
348 msg " ${f} should be added to ${opt_potfile}"
349 let nberrs+=1
351 let nbfiles+=1
352 done
353 msg " nbfiles=${nbfiles} error(s)=${nberrs}"
354 let errs+=${nberrs}
356 # fourth, check that all files in PO actually use the _( construct
357 nbfiles=0
358 nberrs=0
359 let nbpass+=1
360 msg "pass ${nbpass}/${totpass}: checking that all files in ${opt_potfile} actually use the '_(' construct..."
361 for f in $(grep -E '^src/' ${opt_potfile} | grep -vE '\.ui$' | grep -vE '\.in$'); do
362 grep '_(' ${f} 1>/dev/null 2>&1
363 if [ $? -ne 0 ]; then
364 msg " ${f} should be removed from ${opt_potfile}"
365 let nberrs+=1
367 let nbfiles+=1
368 done
369 msg " nbfiles=${nbfiles} error(s)=${nberrs}"
370 let errs+=${nberrs}
372 # last, check that all files which include gi18n.h are relevant
373 nbfiles=0
374 nberrs=0
375 let nbpass+=1
376 msg "pass ${nbpass}/${totpass}: checking that all files have a good reason to include gi18n.h..."
377 for f in $(git grep '#include <glib/gi18n.h>' src | cut -d: -f1 | sort -u); do
378 grep '_(' ${f} 1>/dev/null 2>&1
379 if [ $? -ne 0 ]; then
380 msg " ${f} should not include <glib/gi18n.h>"
381 let nberrs+=1
383 let nbfiles+=1
384 done
385 msg " nbfiles=${nbfiles} error(s)=${nberrs}"
386 let errs+=${nberrs}
388 msg "total: ${errs} error(s)."
390 exit