]> git.pld-linux.org Git - packages/rpm-pld-macros.git/blob - find-lang.sh
find lang 1.40: add --with-django; previous change (701db50) removed
[packages/rpm-pld-macros.git] / find-lang.sh
1 #!/bin/sh
2
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.
7
8 # findlang is copyright (c) 1998 by W. L. Estes <wlestes@uncg.edu>
9
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.
14
15 # Changes:
16 #
17 # 2012-12-22 Elan Ruusamäe <glen@pld-linux.org>
18 #   * added --with-mate
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
37
38 PROG=${0##*/}
39 VERSION=1.40
40
41 usage () {
42 cat <<EOF
43 Usage: $PROG TOP_DIR PACKAGE_NAME [prefix]
44
45 where TOP_DIR is
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
51 to \$3.
52 Additional options:
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
63 EOF
64 exit 1
65 }
66
67 if [ -z "$1" ]; then
68         usage
69 elif [ $1 = / ]; then
70         echo >&2 "$PROG: expects non-/ argument for '$1'"
71         exit 1
72 elif [ ! -d $1 ]; then
73         echo >&2 "$PROG: $1: No such directory"
74         exit 1
75 else
76         TOP_DIR="${1%/}"
77 fi
78 shift
79
80 if [ -z "$1" ]; then
81         usage
82 else
83         NAME=$1
84 fi
85 shift
86
87 GNOME='#'
88 MATE='#'
89 KDE='#'
90 OMF='#'
91 QM='#'
92 DJANGO='#'
93 MO=''
94 OUTPUT=$NAME.lang
95 ALL_NAME='#'
96 NO_ALL_NAME=''
97 APPEND=''
98 while test $# -gt 0; do
99     case "$1" in
100         --with-gnome)
101                 GNOME=''
102                 echo >&2 "$PROG: Enabling with GNOME"
103                 shift
104                 ;;
105         --with-mate)
106                 MATE=''
107                 echo >&2 "$PROG: Enabling with MATE"
108                 shift
109                 ;;
110         --with-kde)
111                 echo >&2 "$PROG: Enabling with KDE"
112                 KDE=''
113                 shift
114                 ;;
115         --with-omf)
116                 echo >&2 "$PROG: Enabling with OMF"
117                 OMF=''
118                 shift
119                 ;;
120         --with-qm)
121                 echo >&2 "$PROG: Enabling with Qt QM"
122                 QM=''
123                 shift
124                 ;;
125         --with-django)
126                 echo >&2 "$PROG: Enabling with Django"
127                 DJANGO=''
128                 shift
129                 ;;
130         --without-mo)
131                 echo >&2 "$PROG: Disabling .mo files"
132                 MO='#'
133                 shift
134                 ;;
135         --all-name)
136                 echo >&2 "$PROG: Enabling with all names"
137                 ALL_NAME=''
138                 NO_ALL_NAME='#'
139                 shift
140                 ;;
141         -o)
142                 shift
143                 OUTPUT=$1
144                 shift
145                 ;;
146         -a)
147                 shift
148                 OUTPUT=$1
149                 APPEND='>'
150                 shift
151                 ;;
152         *)
153                 OUTPUT=$1
154                 shift
155                 ;;
156     esac
157 done
158
159 echo >&2 "$PROG/$VERSION: find-lang '$NAME' $APPEND> $OUTPUT"
160
161 MO_NAME=.$OUTPUT.tmp~
162 echo '%defattr(644,root,root,755)' > $MO_NAME
163
164 # .mo
165 if [ ! -f __find.files ] || [ "$TOP_DIR" -nt __find.files ]; then
166         find $TOP_DIR -xtype f -name '*.mo' | xargs -r file -L | \
167         sed -e '
168                 /, 1 messages$/d
169                 s/:.*//
170                 s:'"$TOP_DIR"'::' > __find.files
171 else
172         echo >&2 "$PROG: Using cached __find.files"
173 fi
174
175 # .omf
176 if [ ! -f __omf.files ] || [ "$TOP_DIR" -nt __omf.files ]; then
177         find $TOP_DIR -type f -name '*.omf' | \
178         sed -e '
179                 s:'"$TOP_DIR"'::' > __omf.files
180 else
181         echo >&2 "$PROG: Using cached __omf.files"
182 fi
183
184 # .qm
185 if [ ! -f __qm.files ] || [ "$TOP_DIR" -nt __qm.files ]; then
186         find $TOP_DIR -type f -name '*.qm' | \
187         sed -e '
188                 s:'"$TOP_DIR"'::' > __qm.files
189 else
190         echo >&2 "$PROG: Using cached __qm.files"
191 fi
192
193 # .mo
194 (
195         if [ "$ALL_NAME" ]; then
196                 grep -F $NAME __find.files
197         else
198                 cat __find.files
199         fi
200 ) | sed '
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:
203 /^[^%]/d
204 s:%lang(C) ::' >> $MO_NAME
205
206 # Django
207 cat __find.dirs | sed -r -e '
208 '"$DJANGO"'s:(.+/share/python.+/locale/)([^/@]+)(@quot|@boldquot)?(@[^/]*)?$:%lang(\2\4) \1\2\3\4:
209 /^[^%]/d
210 s:%lang(C) ::' >> $MO_NAME
211
212 # .omf
213 (
214         if [ "$ALL_NAME" ]; then
215                 grep -F $NAME __omf.files
216         else
217                 cat __omf.files
218         fi
219 ) | sed '
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:
222 /^[^%]/d
223 s:%lang(C) ::' >> $MO_NAME
224
225 # .qm
226 (
227         if [ "$ALL_NAME" ]; then
228                 grep -F $NAME __qm.files
229         else
230                 cat __qm.files
231         fi
232 ) | sed '
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:
239 s:^[^%].*::
240 /^[^%]/d
241 s:%lang(C) ::' >> $MO_NAME
242
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
245 else
246         echo >&2 "$PROG: Using cached __find.dirs"
247 fi
248
249 # gnome
250 (
251         if [ "$ALL_NAME" ]; then
252                 grep -F $NAME __find.dirs
253         else
254                 cat __find.dirs
255         fi
256 ) | sed '
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:
263 /^[^%]/d
264 s:%lang(C) ::' >> $MO_NAME
265
266 # mate
267 (
268         if [ "$ALL_NAME" ]; then
269                 grep -F $NAME __find.dirs
270         else
271                 cat __find.dirs
272         fi
273 ) | sed '
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:
280 /^[^%]/d
281 s:%lang(C) ::' >> $MO_NAME
282
283 # kde
284 (
285         if [ "$ALL_NAME" ]; then
286                 grep -F $NAME __find.dirs
287         else
288                 cat __find.dirs
289         fi
290 ) | sed '
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:
293 /^[^%]/d
294 s:%lang(C) ::' >> $MO_NAME
295
296 (
297         if [ "$ALL_NAME" ]; then
298                 grep -F $NAME __find.dirs
299         else
300                 cat __find.dirs
301         fi
302 ) | sed '
303 '"$NO_ALL_NAME$OMF"'s:\(.*/share/omf/'"$NAME"'$\):%dir \1:
304 '"$ALL_NAME$OMF"'s:\(.*/share/omf/[^/]\+$\):%dir \1:
305 /^[^%]/d
306 s:%lang(C) ::' >> $MO_NAME
307
308 if [ "$(grep -Ev '(^%defattr|^$)' $MO_NAME | wc -l)" -le 0 ]; then
309         echo >&2 "$PROG: Error: international files not found for '$NAME'!"
310         exit 1
311 fi
312
313 if [ "$APPEND" ]; then
314         cat $MO_NAME >> $OUTPUT
315         rm -f $MO_NAME
316 else
317         mv -f $MO_NAME $OUTPUT
318 fi
This page took 0.054908 seconds and 3 git commands to generate.