3 # find-lang - automagically generate list of language specific files
4 # for inclusion in an rpm spec file.
5 # This does assume that the *.mo files are under .../share/locale/...
6 # Run with no arguments gets a usage message.
8 # findlang is copyright (c) 1998 by W. L. Estes <wlestes@uncg.edu>
10 # Redistribution and use of this software are hereby permitted for any
11 # purpose as long as this notice and the above copyright notice remain
12 # in tact and are included with any redistribution of this file or any
13 # work based on this file.
17 # 2012-12-22 Elan Ruusamäe <glen@pld-linux.org>
19 # 2006-08-28 Elan Ruusamäe <glen@pld-linux.org>
20 # * fixed --all-name which got broken with last change.
21 # 2006-08-09 Elan Ruusamäe <glen@pld-linux.org>
22 # * huge performance boost for packages calling %find_lang multiple times (kde*i18n)
23 # 2001-01-08 Michał Kochanowicz <mkochano@pld.org.pl>
24 # * --all-name support for KDE.
25 # 2000-11-28 Rafał Cygnarowski <pascalek@pld.org.pl>
26 # * next simple rule for KDE
27 # 2000-11-12 Rafał Cygnarowski <pascalek@pld.org.pl>
28 # * simple rules for KDE help files
29 # 2000-06-05 Michał Kochanowicz <mkochano@pld.org.pl>
30 # * exact, not substring matching $NAME, i.e. find-lang top_dir NAME will
31 # no longer find /usr/share/locale/pl/LC_MESSAGES/<anything>NAME.mo.
32 # 2000-04-17 Arkadiusz Miśkiewicz <misiek@pld.org.pl>
33 # * exit 1 when no files found
34 # 1999-10-19 Artur Frysiak <wiget@pld.org.pl>
35 # * added support for GNOME help files
36 # * start support for KDE help files
43 Usage: $PROG TOP_DIR PACKAGE_NAME [prefix]
46 the top of the tree containing the files to be processed--should be
47 \$RPM_BUILD_ROOT usually. TOP_DIR gets sed'd out of the output list.
48 PACKAGE_NAME is the %{name} of the package. This should also be
49 the basename of the .mo files. the output is written to
50 PACKAGE_NAME.lang unless \$3 is given in which case output is written
53 --with-gnome find GNOME help files
54 --with-mate find MATE help files
55 --with-kde find KDE help files
56 --with-omf find OMF files
57 --with-qm find QT .qm files
58 --with-django find translations in Django project
59 --all-name match all package/domain names
60 --without-mo skip *.mo locale files
61 -o NAME output will be saved to NAME
62 -a NAME output will be appended to NAME
70 echo >&2 "$PROG: expects non-/ argument for '$1'"
72 elif [ ! -d $1 ]; then
73 echo >&2 "$PROG: $1: No such directory"
98 while test $# -gt 0; do
102 echo >&2 "$PROG: Enabling with GNOME"
107 echo >&2 "$PROG: Enabling with MATE"
111 echo >&2 "$PROG: Enabling with KDE"
116 echo >&2 "$PROG: Enabling with OMF"
121 echo >&2 "$PROG: Enabling with Qt QM"
126 echo >&2 "$PROG: Enabling with Django"
131 echo >&2 "$PROG: Disabling .mo files"
136 echo >&2 "$PROG: Enabling with all names"
159 echo >&2 "$PROG/$VERSION: find-lang '$NAME' $APPEND> $OUTPUT"
161 MO_NAME=.$OUTPUT.tmp~
162 echo '%defattr(644,root,root,755)' > $MO_NAME
165 if [ ! -f __find.files ] || [ "$TOP_DIR" -nt __find.files ]; then
166 find $TOP_DIR -xtype f -name '*.mo' | xargs -r file -L | \
170 s:'"$TOP_DIR"'::' > __find.files
172 echo >&2 "$PROG: Using cached __find.files"
176 if [ ! -f __omf.files ] || [ "$TOP_DIR" -nt __omf.files ]; then
177 find $TOP_DIR -type f -name '*.omf' | \
179 s:'"$TOP_DIR"'::' > __omf.files
181 echo >&2 "$PROG: Using cached __omf.files"
185 if [ ! -f __qm.files ] || [ "$TOP_DIR" -nt __qm.files ]; then
186 find $TOP_DIR -type f -name '*.qm' | \
188 s:'"$TOP_DIR"'::' > __qm.files
190 echo >&2 "$PROG: Using cached __qm.files"
195 if [ "$ALL_NAME" ]; then
196 grep -F $NAME __find.files
201 '"$ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*\.mo$\):%lang(\2\4) \1\2\3\4\5:
202 '"$NO_ALL_NAME$MO"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.mo$\):%lang(\2\4) \1\2\3\4\5:
204 s:%lang(C) ::' >> $MO_NAME
208 if [ "$ALL_NAME" ]; then
209 grep -F $NAME __omf.files
214 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
215 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
217 s:%lang(C) ::' >> $MO_NAME
221 if [ "$ALL_NAME" ]; then
222 grep -F $NAME __qm.files
227 '"$NO_ALL_NAME$QM"'s:\(.*/'"$NAME"'_\([a-zA-Z]\{2\}\([_@].*\)\?\)\.qm$\):%lang(\2) \1:
228 '"$NO_ALL_NAME$QM"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.qm$\):%lang(\2\4) \1\2\3\4\5:
229 '"$ALL_NAME$QM"'s:\(.*/[^/_]\+_\([a-zA-Z]\{2\}[_@].*\)\.qm$\):%lang(\2) \1:
230 '"$ALL_NAME$QM"'s:\(.*/[^/_]\+_\([a-zA-Z]\{2\}\)\.qm$\):%lang(\2) \1:
231 '"$ALL_NAME$QM"'s:^\([^%].*/[^/]\+_\([a-zA-Z]\{2\}[_@].*\)\.qm$\):%lang(\2) \1:
232 '"$ALL_NAME$QM"'s:^\([^%].*/[^/]\+_\([a-zA-Z]\{2\}\)\.qm$\):%lang(\2) \1:
235 s:%lang(C) ::' >> $MO_NAME
237 if [ ! -f __find.dirs ] || [ "$TOP_DIR" -nt __find.dirs ]; then
238 find $TOP_DIR -mindepth 1 -type d | sed 's:'"$TOP_DIR"'::' > __find.dirs
240 echo >&2 "$PROG: Using cached __find.dirs"
245 if [ "$ALL_NAME" ]; then
246 grep -F $NAME __find.dirs
251 '"$NO_ALL_NAME$GNOME"'s:\(.*/share/help/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
252 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'$\):%dir \1:
253 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'/\)\([^/]\+\)$:%lang(\2) \1\2:
254 '"$ALL_NAME$GNOME"'s:\(.*/share/help/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
255 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+$\):%dir \1:
256 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
258 s:%lang(C) ::' >> $MO_NAME
262 if [ "$ALL_NAME" ]; then
263 grep -F $NAME __find.dirs
268 '"$NO_ALL_NAME$MATE"'s:\(.*/share/help/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
269 '"$NO_ALL_NAME$MATE"'s:\(.*/mate/help/'"$NAME"'$\):%dir \1:
270 '"$NO_ALL_NAME$MATE"'s:\(.*/mate/help/'"$NAME"'/\)\([^/]\+\)$:%lang(\2) \1\2:
271 '"$ALL_NAME$MATE"'s:\(.*/share/help/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
272 '"$ALL_NAME$MATE"'s:\(.*/mate/help/[^/]\+$\):%dir \1:
273 '"$ALL_NAME$MATE"'s:\(.*/mate/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
275 s:%lang(C) ::' >> $MO_NAME
279 if [ "$ALL_NAME" ]; then
280 grep -F $NAME __find.dirs
285 '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
286 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
288 s:%lang(C) ::' >> $MO_NAME
292 if [ "$ALL_NAME" ]; then
293 grep -F $NAME __find.dirs
298 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'$\):%dir \1:
299 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+$\):%dir \1:
301 s:%lang(C) ::' >> $MO_NAME
304 cat __find.dirs | sed -r -e '
305 '"$DJANGO"'s:(.+/share/python.+/locale/)([^/@]+)(@quot|@boldquot)?(@[^/]*)?$:%lang(\2\4) \1\2\3\4:
307 s:%lang(C) ::' >> $MO_NAME
309 if [ "$(grep -Ev '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then
310 echo >&2 "$PROG: Error: international files not found for '$NAME'!"
314 if [ "$APPEND" ]; then
315 cat $MO_NAME >> $OUTPUT
318 mv -f $MO_NAME $OUTPUT