]> git.draconx.ca Git - dxcommon.git/blob - m4/linguas.m4
Add "join" detection macro.
[dxcommon.git] / m4 / linguas.m4
1 dnl Copyright © 2011, 2021-2022 Nick Bowler
2 dnl
3 dnl Computes the set of .po and .mo files based on the LINGUAS environment
4 dnl variable.  The variable POFILES is set to the complete list of .po files,
5 dnl according to the LINGUAS file in the po directory.  The variable MOFILES
6 dnl is set to the list of .mo files that the user has requested be installed.
7 dnl Both POFILES and MOFILES are AC_SUBSTed.
8 dnl
9 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
10 dnl This is free software: you are free to do what the fuck you want to.
11 dnl There is NO WARRANTY, to the extent permitted by law.
12
13 AC_DEFUN([DX_LINGUAS],
14 [AC_REQUIRE([AM_GNU_GETTEXT])dnl
15 AC_REQUIRE([DX_PROG_JOIN])dnl
16
17 POFILES=
18 MOFILES=
19
20 if test -f "$srcdir/po/LINGUAS"; then
21   awk '{ sub(/#.*$/, "")
22     for (i = 1; i <= NF; i++) {
23       print $(i)
24     }
25   }' "$srcdir/po/LINGUAS" | LC_ALL=C sort -u >conftest.all
26
27   : "${LINGUAS=all}"
28   if test x"$LINGUAS" = x"all"; then
29     cp conftest.all conftest.ena
30   else
31     :; {
32       for arg in $LINGUAS; do
33         # Ensure that if "la_CC"-style code is requested then so is plain "la".
34         printf '%s\n' "$arg"
35         case $arg in
36         *_*)
37           save_IFS=$IFS; IFS=_
38           set x $arg
39           IFS=$save_IFS
40           AS_ECHO(["${2}"])
41           ;;
42         esac
43       done
44     } | LC_ALL=C sort -u >conftest.ena
45   fi
46
47   exec 3<conftest.all
48   while read x <&3; do
49     AS_VAR_APPEND([POFILES], ["${POFILES:+ }po/$x.po"])
50   done
51
52   if test x"$USE_NLS" = x"yes"; then
53     LC_ALL=C $JOIN conftest.ena conftest.all >conftest.out
54     exec 3<conftest.out
55     while read x <&3; do
56       AS_VAR_APPEND([MOFILES], ["${MOFILES:+ }po/$x.mo"])
57     done
58   fi
59
60   exec 3<&-
61   rm -f conftest.all conftest.ena conftest.out
62 fi
63
64 AC_SUBST([POFILES])
65 AC_SUBST([MOFILES])
66 ])