]> git.draconx.ca Git - dxcommon.git/commitdiff
Fix redundant MOFILES entries computed by DX_LINGUAS.
authorNick Bowler <nbowler@draconx.ca>
Mon, 15 Feb 2021 04:44:48 +0000 (23:44 -0500)
committerNick Bowler <nbowler@draconx.ca>
Mon, 15 Feb 2021 04:47:33 +0000 (23:47 -0500)
The DX_LINGUAS macro transforms a LINGUAS setting of, for example,
"en_CA" to also include "en".  However, if LINGUAS also includes
"en", this addition results in "en" being output twice.

Add a test case that exposes this issue, and correct the problem.

m4/linguas.m4
tests/macros.at

index 2ae8a9db32ba529ed2938a4819c5a9f431a3828b..61613b6dc2f2c42c610ca2ca662971a2cf746ab7 100644 (file)
@@ -1,4 +1,4 @@
-dnl Copyright © 2011 Nick Bowler
+dnl Copyright © 2011, 2021 Nick Bowler
 dnl
 dnl Computes the set of .po and .mo files based on the LINGUAS environment
 dnl variable.  The variable POFILES is set to the complete list of .po files,
@@ -10,42 +10,53 @@ dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
 dnl This is free software: you are free to do what the fuck you want to.
 dnl There is NO WARRANTY, to the extent permitted by law.
 
-AC_DEFUN([DX_LINGUAS], [dnl
-AC_REQUIRE([AM_GNU_GETTEXT])
+AC_DEFUN([DX_LINGUAS],
+[AC_REQUIRE([AM_GNU_GETTEXT])dnl
 
 POFILES=
 MOFILES=
 
 if test -f "$srcdir/po/LINGUAS"; then
-       ALL_LINGUAS=`sed 's/#.*$//' "$srcdir/po/LINGUAS"`
-
-       : ${LINGUAS=all}
-       if test x"$LINGUAS" != x"all"; then
-               # Replicate la_CC-style codes as la.
-               LINGUAS=`printf '%s\n' "$LINGUAS" \
-                       | [sed 's/\([^_[:space:]]*\)_[^[:space:]]*/& \1/g']`
-
-               printf '%s\n' $ALL_LINGUAS | sort > conftest.LINGUAS
-               LINGUAS=`printf '%s\n' $LINGUAS | sort \
-                       | join - conftest.LINGUAS`
-       else
-               LINGUAS=$ALL_LINGUAS
-       fi
-
-       # Note: $srcdir is not used here because these variables are for make.
-       set x $ALL_LINGUAS; shift
-       case ${#} in
-       0) ;;
-       *) POFILES=`printf "po/%s.po\n" "${@}"` ;;
-       esac
-
-       if test x"$USE_NLS" = x"yes"; then
-               set x $LINGUAS; shift
-               case ${#} in
-               0) ;;
-               *) MOFILES=`printf "po/%s.mo\n" "${@}"` ;;
-               esac
-       fi
+  awk '{ sub(/#.*$/, "")
+    for (i = 1; i <= NF; i++) {
+      print $(i)
+    }
+  }' "$srcdir/po/LINGUAS" | sort -u >conftest.all
+
+  : "${LINGUAS=all}"
+  if test x"$LINGUAS" = x"all"; then
+    cp conftest.all conftest.ena
+  else
+    :; {
+      for arg in $LINGUAS; do
+        # Ensure that if "la_CC"-style code is requested then so is plain "la".
+        printf '%s\n' "$arg"
+        case $arg in
+        *_*) printf '%s\n' "${arg%%_*}" ;;
+        esac
+      done
+    } | sort -u >conftest.ena
+  fi
+
+  ALL_LINGUAS=`cat conftest.all`
+  LINGUAS=`join conftest.ena conftest.all`
+
+  # Note: $srcdir is not used here because these variables are for make.
+  set x $ALL_LINGUAS; shift
+  case ${#} in
+  0) ;;
+  *) POFILES=`printf "po/%s.po\n" "${@}"` ;;
+  esac
+
+  if test x"$USE_NLS" = x"yes"; then
+    set x $LINGUAS; shift
+    case ${#} in
+    0) ;;
+    *) MOFILES=`printf "po/%s.mo\n" "${@}"` ;;
+    esac
+  fi
+
+  rm -f conftest.all conftest.ena
 fi
 
 AC_SUBST([POFILES])
index 3b851fc09793227fa24210e097a36a40f7d57caa..9a49e35dc0fad93c14847fc7481be9bc14cc9977 100644 (file)
@@ -109,3 +109,33 @@ AT_CHECK([cat test.out], [0], [[FOOFOOFOO
 ]])
 
 AT_CLEANUP
+
+AT_SETUP([DX_LINGUAS unused country variants])
+AT_KEYWORDS([DX_LINGUAS macro])
+
+echo : >config.rpath
+chmod +x config.rpath
+
+mkdir po
+AT_DATA([po/LINGUAS], [[en
+]])
+
+AT_DATA([test.in], [[POFILES = @POFILES@
+MOFILES = @MOFILES@
+]])
+
+TEST_CONFIGURE_AC(
+[[m4@&t@_traceoff([AM_GNU_GETTEXT])
+AM_GNU_GETTEXT([external])
+DX_LINGUAS
+AC_CONFIG_FILES([test])
+]])
+
+TEST_AUTORECONF
+export LINGUAS='en_CA en'; TEST_CONFIGURE
+
+AT_CHECK([cat test], [0], [[POFILES = po/en.po
+MOFILES = po/en.mo
+]])
+
+AT_CLEANUP