groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 27/30: [mm,tmac]: Refactor date format localization.


From: G. Branden Robinson
Subject: [groff] 27/30: [mm,tmac]: Refactor date format localization.
Date: Fri, 8 Nov 2024 01:14:32 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit eb76bfeb35ddbb17dcb29a9e9b608e00aab5c293
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Thu Nov 7 15:21:13 2024 -0600

    [mm,tmac]: Refactor date format localization.
    
    * contrib/mm/m.tmac: New string `cov*local-date-format` does what it
      says, using `\E` to delay interpretation of relevant registers and
      strings.  New string `cov*iso-date-format` work similarly, but is not
      expected to be overriden by localization files.
    
      (cov*set-date): Use one or the other of the foregoing strings.
    
    * contrib/mm/tests/date-localization-works.sh: Add unit test.
    * contrib/mm/mm.am (mm_TESTS): Run test.
    
    * tmac/cs.tmac:
    * tmac/de.tmac:
    * tmac/es.tmac:
    * tmac/fr.tmac:
    * tmac/it.tmac:
    * tmac/ru.tmac:
    * tmac/sv.tmac: Migrate to new mm date format localization method; now
      one string definition is all we need.
---
 ChangeLog                                   | 11 +++++
 contrib/mm/ChangeLog                        | 13 ++++++
 contrib/mm/m.tmac                           | 16 +++++++-
 contrib/mm/mm.am                            |  1 +
 contrib/mm/tests/date-localization-works.sh | 63 +++++++++++++++++++++++++++++
 tmac/cs.tmac                                | 14 +------
 tmac/de.tmac                                | 14 +------
 tmac/es.tmac                                | 14 +------
 tmac/fr.tmac                                | 14 +------
 tmac/it.tmac                                | 14 +------
 tmac/ru.tmac                                | 14 +------
 tmac/sv.tmac                                |  4 +-
 12 files changed, 117 insertions(+), 75 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2b78c122c..7137bbd3f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2024-11-07  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * tmac/cs.tmac:
+       * tmac/de.tmac:
+       * tmac/es.tmac:
+       * tmac/fr.tmac:
+       * tmac/it.tmac:
+       * tmac/ru.tmac:
+       * tmac/sv.tmac: Migrate to new mm date format localization
+       method; now one string definition is all we need.
+
 2024-11-07  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * tmac/ru.tmac: Stop enabling automatic hyphenation by default
diff --git a/contrib/mm/ChangeLog b/contrib/mm/ChangeLog
index 8c165b719..bf33fa6b3 100644
--- a/contrib/mm/ChangeLog
+++ b/contrib/mm/ChangeLog
@@ -1,3 +1,16 @@
+2024-11-07  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       Refactor date format localization.
+
+       * m.tmac: New string `cov*local-date-format` does what it says,
+       using `\E` to delay interpretation of relevant registers and
+       strings.  New string `cov*iso-date-format` work similarly, but
+       is not expected to be overriden by localization files.
+       (cov*set-date): Use one or the other of the foregoing strings.
+
+       * tests/date-localization-works.sh: Add unit test.
+       * mm.am (mm_TESTS): Run test.
+
 2024-11-07  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * m.tmac: Trivially refactor: rename registers `cov*mm` and
diff --git a/contrib/mm/m.tmac b/contrib/mm/m.tmac
index 15de42865..0356fa9fe 100644
--- a/contrib/mm/m.tmac
+++ b/contrib/mm/m.tmac
@@ -353,6 +353,7 @@ http://savannah.gnu.org/bugs/?group=groff.
 .ie t .nr Lsp 0.5v
 .el   .nr Lsp 1v
 .
+.\" Note: See comment under `cov*set-date` macro definition.
 .ds MO1 January
 .ds MO2 February
 .ds MO3 March
@@ -3508,15 +3509,26 @@ argument: '\\$2'
 .de AE
 \\*[debug@dump-args]\\
 ..
+.\" XXX: In principle, a localization file can (and should be able to)
+.\" customize the month's register format, but we look up the string for
+.\" the month name assuming that `mo`'s format will be '0'.  To date,
+.\" however, no one has submitted a localization file for groff that
+.\" uses an alternative register format for `mo` (or `dy`).  If that day
+.\" comes, we might rename MO1 to MO01 (and so on) and look up the
+.\" string with a dedicated register using a format of '00'.
+.ds cov*local-date-format \E*[MO\En[mo]] \En[dy], \En[year]
 .af cov*iso-mm 00
 .af cov*iso-dd 00
+.ds cov*iso-date-format   \En[year]-\En[cov*iso-mm]-\En[cov*iso-dd]
+.\" TODO: After `ISODATE` is removed for groff 1.25, this macro can stop
+.\" handling an argument, instead testing the `Isodate` register.
 .de cov*set-date
 .\" In case the document has changed `mo` or `dy`, make sure their
 .\" alternatives using ISO 8601 format are synchronized.
 .nr cov*iso-mm \\n[mo]
 .nr cov*iso-dd \\n[dy]
-.ie '0'\\$1' .ds cov*date \\*[MO\\n[mo]] \\n[dy], \\n[year]
-.el          .ds cov*date \\n[year]-\\n[cov*iso-mm]-\\n[cov*iso-dd]
+.ie '0'\\$1' .ds cov*date \\*[cov*local-date-format]
+.el          .ds cov*date \\*[cov*iso-date-format]
 ..
 .de ISODATE
 .@warning \\$0: macro is deprecated; define register 'Isodate' instead
diff --git a/contrib/mm/mm.am b/contrib/mm/mm.am
index f80c0b18c..6fa6aee91 100644
--- a/contrib/mm/mm.am
+++ b/contrib/mm/mm.am
@@ -76,6 +76,7 @@ mm_TESTS = \
   contrib/mm/tests/Np-register-works.sh \
   contrib/mm/tests/P-indentation-works.sh \
   contrib/mm/tests/VL-accommodates-overlong-mark.sh \
+  contrib/mm/tests/date-localization-works.sh \
   contrib/mm/tests/flush-long-displays-at-end-of-input.sh \
   contrib/mm/tests/indexing-works.sh \
   contrib/mm/tests/letters-format-correctly.sh \
diff --git a/contrib/mm/tests/date-localization-works.sh 
b/contrib/mm/tests/date-localization-works.sh
new file mode 100755
index 000000000..96f9e84b4
--- /dev/null
+++ b/contrib/mm/tests/date-localization-works.sh
@@ -0,0 +1,63 @@
+#!/bin/sh
+#
+# Copyright (C) 2024 Free Software Foundation, Inc.
+#
+# This file is part of groff.
+#
+# groff is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your
+# option) any later version.
+#
+# groff is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+groff="${abs_top_builddir:-.}/test-groff"
+
+fail=
+
+wail () {
+    echo ...FAILED >&2
+    fail=YES
+}
+
+input='.
+.nr mo 10
+.nr dy 6
+.nr year 2024
+.ND
+.LT
+.P
+This is an
+.I mm
+letter.
+.'
+
+for lang in cs de en es fr it ru sv
+do
+    output=$(printf "%s\n" "$input" \
+             | "$groff" -m m -m $lang -T utf8 -P -cbou | cat -s)
+    echo "$output"
+    case $lang in
+        cs) pattern='6 .+jen 2024' ;;
+        de) pattern='6\. Oktober 2024' ;;
+        en) pattern='October 6, 2024' ;;
+        es) pattern='6 de octubre de 2024' ;;
+        fr) pattern='6 Octobre 2024' ;;
+        it) pattern='6 Ottobre 2024' ;;
+        ru) pattern='6 .+ 2024' ;; # a bit weak
+        sv) pattern='6 oktober 2024' ;;
+    esac
+    echo "checking date localization in language $lang" >&2
+    echo "$output" | grep -Eq "$pattern" || wail
+done
+
+test -z "$fail"
+
+# vim:set ai et sw=4 ts=4 tw=72:
diff --git a/tmac/cs.tmac b/tmac/cs.tmac
index afe5ade88..aaf233418 100644
--- a/tmac/cs.tmac
+++ b/tmac/cs.tmac
@@ -132,18 +132,8 @@
 .
 .
 .\" mm package
-.if d PH \{\
-.      \" update the date with the new strings
-.      ds cov*new-date \\n[dy] \\*[MO\\n[mo]] \\n[year]
-.
-.      \" ISODATE and DT update
-.      de ISODATE
-.              ie '0'\\$1' \
-.                      ds cov*new-date \\n[dy] \\*[MO\\n[mo]] \\n[year]
-.              el \
-.                      ds cov*new-date \\n[year]-\\n[cov*mm]-\\n[cov*dd]
-.      .
-.\}
+.if d PH \
+.      ds cov*local-date-format \En[dy] \E*[MO\En[mo]] \En[year]
 .
 .
 .\" Default encoding
diff --git a/tmac/de.tmac b/tmac/de.tmac
index a7b7c977a..d494d2b18 100644
--- a/tmac/de.tmac
+++ b/tmac/de.tmac
@@ -132,18 +132,8 @@
 .
 .
 .\" mm package
-.if d PH \{\
-.      \" update the date with the new strings
-.      ds cov*new-date \\n[dy].\& \\*[MO\\n[mo]] \\n[year]
-.
-.      \" ISODATE and DT update
-.      de ISODATE
-.              ie '0'\\$1' \
-.                      ds cov*new-date \\n[dy].\~\\*[MO\\n[mo]] \\n[year]
-.              el \
-.                      ds cov*new-date \\n[year]-\\n[cov*mm]-\\n[cov*dd]
-.      .
-.\}
+.if d PH \
+.      ds cov*local-date-format \En[dy].\& \E*[MO\En[mo]] \En[year]
 .
 .
 .\" Default encoding
diff --git a/tmac/es.tmac b/tmac/es.tmac
index 695dabfff..7b3cf5e36 100644
--- a/tmac/es.tmac
+++ b/tmac/es.tmac
@@ -132,18 +132,8 @@
 .
 .
 .\" mm package
-.if d PH \{\
-.      \" update the date with the new strings
-.      ds cov*new-date \\n[dy] de \\*[MO\\n[mo]] de \\n[year]
-.
-.      \" ISODATE and DT update
-.      de ISODATE
-.            ie '0'\\$1' \
-.                    ds cov*new-date \\n[dy] de \\*[MO\\n[mo]] de \\n[year]
-.            el \
-.                    ds cov*new-date \\n[year]-\\n[cov*mm]-\\n[cov*dd]
-.      .
-.\}
+.if d PH \
+.      ds cov*local-date-format \En[dy] de \E*[MO\En[mo]] de \En[year]
 .
 .
 .\" Default encoding
diff --git a/tmac/fr.tmac b/tmac/fr.tmac
index 4f85f2378..fc63e89ec 100644
--- a/tmac/fr.tmac
+++ b/tmac/fr.tmac
@@ -132,18 +132,8 @@
 .
 .
 .\" mm package
-.if d PH \{\
-.      \" update the date with the new strings
-.      ds cov*new-date \\n[dy] \\*[MO\\n[mo]] \\n[year]
-.
-.      \" ISODATE and DT update
-.      de ISODATE
-.              ie '0'\\$1' \
-.                      ds cov*new-date \\n[dy] \\*[MO\\n[mo]] \\n[year]
-.              el \
-.                      ds cov*new-date \\n[year]-\\n[cov*mm]-\\n[cov*dd]
-.      .
-.\}
+.if d PH \
+.      ds cov*local-date-format \En[dy] \E*[MO\En[mo]] \En[year]
 .
 .
 .\" Default encoding
diff --git a/tmac/it.tmac b/tmac/it.tmac
index 165c166b3..f4bdfea3c 100644
--- a/tmac/it.tmac
+++ b/tmac/it.tmac
@@ -132,18 +132,8 @@
 .
 .
 .\" mm package
-.if d PH \{\
-.      \" update the date with the new strings
-.      ds cov*new-date \\n[dy] \\*[MO\\n[mo]] \\n[year]
-.
-.      \" ISODATE and DT update
-.      de ISODATE
-.              ie '0'\\$1' \
-.                      ds cov*new-date \\n[dy] \\*[MO\\n[mo]] \\n[year]
-.              el \
-.                      ds cov*new-date \\n[year]-\\n[cov*mm]-\\n[cov*dd]
-.      .
-.\}
+.if d PH \
+.      ds cov*local-date-format \En[dy] \E*[MO\En[mo]] \En[year]
 .
 .
 .\" Default encoding
diff --git a/tmac/ru.tmac b/tmac/ru.tmac
index 804136543..aebaac629 100644
--- a/tmac/ru.tmac
+++ b/tmac/ru.tmac
@@ -132,18 +132,8 @@
 .
 .
 .\" mm package
-.if d PH \{\
-.      \" update the date with the new strings
-.      ds cov*new-date \\n[dy] \\*[MO\\n[mo]] \\n[year]
-.
-.      \" ISODATE and DT update
-.      de ISODATE
-.              ie '0'\\$1' \
-.                      ds cov*new-date \\n[dy] \\*[MO\\n[mo]] \\n[year]
-.              el \
-.                      ds cov*new-date \\n[year]-\\n[cov*mm]-\\n[cov*dd]
-.      .
-.\}
+.if d PH \
+.      ds cov*local-date-format \En[dy] \E*[MO\En[mo]] \En[year]
 .
 .
 .\" Default encoding
diff --git a/tmac/sv.tmac b/tmac/sv.tmac
index 57b56cd92..49a7fcfc1 100644
--- a/tmac/sv.tmac
+++ b/tmac/sv.tmac
@@ -131,7 +131,9 @@
 .\}
 .
 .
-.\" mm package -- additional Swedish localization is done in mse.tmac
+.\" mm package
+.if d PH \
+.      ds cov*local-date-format \En[dy] \E*[MO\En[mo]] \En[year]
 .
 .
 .\" Default encoding



reply via email to

[Prev in Thread] Current Thread [Next in Thread]