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
207 cat __find.dirs | sed -r -e '
208 '"$DJANGO"'s:(.+/share/python.+/locale/)([^/@]+)(@quot|@boldquot)?(@[^/]*)?$:%lang(\2\4) \1\2\3\4:
210 s:%lang(C) ::' >> $MO_NAME
214 if [ "$ALL_NAME" ]; then
215 grep -F $NAME __omf.files
220 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
221 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'/\)\(.*-\)\([^-]*\)\(\.omf\):%lang(\3) \1\2\3\4:
223 s:%lang(C) ::' >> $MO_NAME
227 if [ "$ALL_NAME" ]; then
228 grep -F $NAME __qm.files
233 '"$NO_ALL_NAME$QM"'s:\(.*/'"$NAME"'_\([a-zA-Z]\{2\}\([_@].*\)\?\)\.qm$\):%lang(\2) \1:
234 '"$NO_ALL_NAME$QM"'s:\(.*/share/locale/\)\([^/@]\+\)\(@quot\|@boldquot\)\?\(@[^/]*\)\?\(/.*/'"$NAME"'\.qm$\):%lang(\2\4) \1\2\3\4\5:
235 '"$ALL_NAME$QM"'s:\(.*/[^/_]\+_\([a-zA-Z]\{2\}[_@].*\)\.qm$\):%lang(\2) \1:
236 '"$ALL_NAME$QM"'s:\(.*/[^/_]\+_\([a-zA-Z]\{2\}\)\.qm$\):%lang(\2) \1:
237 '"$ALL_NAME$QM"'s:^\([^%].*/[^/]\+_\([a-zA-Z]\{2\}[_@].*\)\.qm$\):%lang(\2) \1:
238 '"$ALL_NAME$QM"'s:^\([^%].*/[^/]\+_\([a-zA-Z]\{2\}\)\.qm$\):%lang(\2) \1:
241 s:%lang(C) ::' >> $MO_NAME
243 if [ ! -f __find.dirs ] || [ "$TOP_DIR" -nt __find.dirs ]; then
244 find $TOP_DIR -mindepth 1 -type d | sed 's:'"$TOP_DIR"'::' > __find.dirs
246 echo >&2 "$PROG: Using cached __find.dirs"
251 if [ "$ALL_NAME" ]; then
252 grep -F $NAME __find.dirs
257 '"$NO_ALL_NAME$GNOME"'s:\(.*/share/help/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
258 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'$\):%dir \1:
259 '"$NO_ALL_NAME$GNOME"'s:\(.*/gnome/help/'"$NAME"'/\)\([^/]\+\)$:%lang(\2) \1\2:
260 '"$ALL_NAME$GNOME"'s:\(.*/share/help/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
261 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+$\):%dir \1:
262 '"$ALL_NAME$GNOME"'s:\(.*/gnome/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
264 s:%lang(C) ::' >> $MO_NAME
268 if [ "$ALL_NAME" ]; then
269 grep -F $NAME __find.dirs
274 '"$NO_ALL_NAME$MATE"'s:\(.*/share/help/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
275 '"$NO_ALL_NAME$MATE"'s:\(.*/mate/help/'"$NAME"'$\):%dir \1:
276 '"$NO_ALL_NAME$MATE"'s:\(.*/mate/help/'"$NAME"'/\)\([^/]\+\)$:%lang(\2) \1\2:
277 '"$ALL_NAME$MATE"'s:\(.*/share/help/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
278 '"$ALL_NAME$MATE"'s:\(.*/mate/help/[^/]\+$\):%dir \1:
279 '"$ALL_NAME$MATE"'s:\(.*/mate/help/[^/]\+/\)\([^/]\+\)$:%lang(\2) \1\2:
281 s:%lang(C) ::' >> $MO_NAME
285 if [ "$ALL_NAME" ]; then
286 grep -F $NAME __find.dirs
291 '"$NO_ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/'"$NAME"'\)$:%lang(\2) \1\2\3:
292 '"$ALL_NAME$KDE"'s:\(.*/doc/kde/HTML/\)\([^/]\+\)\(/[^/]\+\)$:%lang(\2) \1\2\3:
294 s:%lang(C) ::' >> $MO_NAME
297 if [ "$ALL_NAME" ]; then
298 grep -F $NAME __find.dirs
303 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'$\):%dir \1:
304 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+$\):%dir \1:
306 s:%lang(C) ::' >> $MO_NAME
308 if [ "$(grep -Ev '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then
309 echo >&2 "$PROG: Error: international files not found for '$NAME'!"
313 if [ "$APPEND" ]; then
314 cat $MO_NAME >> $OUTPUT
317 mv -f $MO_NAME $OUTPUT