]> git.draconx.ca Git - dxcommon.git/blob - m4/linguas.m4
DX_C_ALIGNAS: Work around bash-5 parsing bug.
[dxcommon.git] / m4 / linguas.m4
1 dnl Copyright © 2011, 2021-2023 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 AC_REQUIRE([AC_PROG_AWK])dnl
17
18 POFILES=
19 MOFILES=
20
21 if test -f "$srcdir/po/LINGUAS"; then
22   $AWK '{ sub(/#.*$/, "")
23     for (i = 1; i <= NF; i++) {
24       print $(i)
25     }
26   }' "$srcdir/po/LINGUAS" | LC_ALL=C sort -u >conftest.all
27
28   : "${LINGUAS=all}"
29   if test x"$LINGUAS" = x"all"; then
30     cp conftest.all conftest.ena
31   else
32     :; {
33       for arg in $LINGUAS; do
34         # Ensure that if "la_CC"-style code is requested then so is plain "la".
35         printf '%s\n' "$arg"
36         case $arg in
37         *_*)
38           save_IFS=$IFS; IFS=_
39           set x $arg
40           IFS=$save_IFS
41           AS_ECHO(["${2}"])
42           ;;
43         esac
44       done
45     } | LC_ALL=C sort -u >conftest.ena
46   fi
47
48   exec 3<conftest.all
49   while read x <&3; do
50     AS_VAR_APPEND([POFILES], ["${POFILES:+ }po/$x.po"])
51   done
52
53   if test x"$USE_NLS" = x"yes"; then
54     LC_ALL=C $JOIN conftest.ena conftest.all >conftest.out
55     exec 3<conftest.out
56     while read x <&3; do
57       AS_VAR_APPEND([MOFILES], ["${MOFILES:+ }po/$x.mo"])
58     done
59   fi
60
61   exec 3<&-
62   rm -f conftest.all conftest.ena conftest.out
63 fi
64
65 AC_SUBST([POFILES])
66 AC_SUBST([MOFILES])
67 ])