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