]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_protofile: add messages to localization catalog
authorDarrick J. Wong <djwong@kernel.org>
Tue, 1 Apr 2025 14:44:28 +0000 (07:44 -0700)
committerAndrey Albershteyn <aalbersh@kernel.org>
Tue, 8 Apr 2025 09:20:10 +0000 (11:20 +0200)
Add the source code of these two Python programs to the list of files
that are scanned for the gettext message catalog.  This will enable
localization of the outputs of these programs.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Andrey Albershteyn <aalbersh@kernel.org>
Reviewed-by: Bill O'Donnell <bodonnel@redhat.com>
configure.ac
include/buildrules
libfrog/Makefile
libfrog/gettext.py.in [new file with mode: 0644]
mkfs/Makefile
mkfs/xfs_protofile.py.in

index 71596711685a8a9bfb473a41ef18757a0921c195..4202144710d18780e6893020467623430f929adf 100644 (file)
@@ -130,7 +130,7 @@ test -n "$multiarch" && enable_lib64=no
 # to "find" is required, to avoid including such directories in the
 # list.
 LOCALIZED_FILES=""
-for lfile in `find ${srcdir} -path './.??*' -prune -o -name '*.c' -type f -print || exit 1`; do
+for lfile in `find ${srcdir} -path './.??*' -prune -o -name '*.c' -print -o -name '*.py.in' -print || exit 1`; do
     LOCALIZED_FILES="$LOCALIZED_FILES \$(TOPDIR)/$lfile"
 done
 AC_SUBST(LOCALIZED_FILES)
index ae047ac41fe27ca22541873c0d76c92674736f47..871e92db02de1408c4597a131b789a829793e915 100644 (file)
@@ -86,7 +86,6 @@ endif
 
 ifdef POTHEAD
 XGETTEXT_FLAGS=\
-       --language=C \
        --keyword=_ \
        --keyword=N_ \
        --package-name=$(PKG_NAME) \
index fc7e506d96bbad7549023dbb2f149c6411d09821..b64ca4597f4ea903217f5ca92cb768a5e9c108d3 100644 (file)
@@ -64,11 +64,20 @@ randbytes.h \
 scrub.h \
 workqueue.h
 
+GETTEXT_PY = \
+       gettext.py
+
 LSRCFILES += gen_crc32table.c
 
 LDIRT = gen_crc32table crc32table.h
 
-default: ltdepend $(LTLIBRARY)
+ifeq ($(ENABLE_GETTEXT),yes)
+HAVE_GETTEXT = True
+else
+HAVE_GETTEXT = False
+endif
+
+default: ltdepend $(LTLIBRARY) $(GETTEXT_PY)
 
 crc32table.h: gen_crc32table.c crc32defs.h
        @echo "    [CC]     gen_crc32table"
@@ -76,6 +85,13 @@ crc32table.h: gen_crc32table.c crc32defs.h
        @echo "    [GENERATE] $@"
        $(Q) ./gen_crc32table > crc32table.h
 
+$(GETTEXT_PY): $(GETTEXT_PY).in $(TOPDIR)/include/builddefs
+       @echo "    [SED]    $@"
+       $(Q)$(SED) -e "s|@HAVE_GETTEXT@|$(HAVE_GETTEXT)|g" \
+                  -e "s|@PACKAGE@|$(PKG_NAME)|g" \
+                  -e "s|@LOCALEDIR@|$(PKG_LOCALE_DIR)|g" \
+                  < $< > $@
+
 include $(BUILDRULES)
 
 install install-dev: default
diff --git a/libfrog/gettext.py.in b/libfrog/gettext.py.in
new file mode 100644 (file)
index 0000000..61559f7
--- /dev/null
@@ -0,0 +1,12 @@
+
+if __name__ == '__main__':
+       if @HAVE_GETTEXT@:
+               import gettext
+               # set up gettext before main so that we can set up _().
+               gettext.bindtextdomain("@PACKAGE@", "@LOCALEDIR@")
+               gettext.textdomain("@PACKAGE@")
+               _ = gettext.gettext
+       else:
+               def _(a):
+                       return a
+
index b1369e1853a98f784820c3720c512921a6c042a6..04905bd5101ccbab2f64de5fb007315a59f03ae6 100644 (file)
@@ -30,9 +30,12 @@ default: depend $(LTCOMMAND) $(CFGFILES) $(XFS_PROTOFILE)
 
 include $(BUILDRULES)
 
-$(XFS_PROTOFILE): $(XFS_PROTOFILE).in
+$(XFS_PROTOFILE): $(XFS_PROTOFILE).in $(TOPDIR)/include/builddefs $(TOPDIR)/libfrog/gettext.py
        @echo "    [SED]    $@"
-       $(Q)$(SED) -e "s|@pkg_version@|$(PKG_VERSION)|g" < $< > $@
+       $(Q)$(SED) -e "s|@pkg_version@|$(PKG_VERSION)|g" \
+                  -e '/@INIT_GETTEXT@/r $(TOPDIR)/libfrog/gettext.py' \
+                  -e '/@INIT_GETTEXT@/d' \
+                  < $< > $@
        $(Q)chmod a+x $@
 
 install: default
index e83c39f5325846f677133f57759c2729578b032b..040454da1da4df06f8bf20aeed0023c4b308a637 100644 (file)
@@ -7,6 +7,7 @@
 
 # Walk a filesystem tree to generate a protofile for mkfs.
 
+@INIT_GETTEXT@
 import os
 import argparse
 import sys
@@ -86,12 +87,12 @@ def walk_tree(path, depth):
 
        for fname in files:
                if ' ' in fname:
-                       raise ValueError( \
-                               f'{fname}: Spaces not allowed in file names.')
+                       msg = _("Spaces not allowed in file names.")
+                       raise ValueError(f'{fname}: {msg}')
        for fname in dirs:
                if ' ' in fname:
-                       raise Exception( \
-                               f'{fname}: Spaces not allowed in file names.')
+                       msg = _("Spaces not allowed in subdirectory names.")
+                       raise Exception(f'{fname}: {msg}')
 
        fname_width = max_fname_len(files)
        for fname in files:
@@ -114,15 +115,17 @@ def walk_tree(path, depth):
 
 def main():
        parser = argparse.ArgumentParser( \
-                       description = "Generate mkfs.xfs protofile for a directory tree.")
-       parser.add_argument('paths', metavar = 'paths', type = str, \
-                       nargs = '*', help = 'Directory paths to walk.')
-       parser.add_argument("-V", help = "Report version and exit.", \
+                       description = _("Generate mkfs.xfs protofile for a directory tree."))
+       parser.add_argument('paths', metavar = _('paths'), type = str, \
+                       nargs = '*', help = _('Directory paths to walk.'))
+       parser.add_argument("-V", help = _("Report version and exit."), \
                        action = "store_true")
        args = parser.parse_args()
 
        if args.V:
-               print("xfs_protofile version @pkg_version@")
+               msg = _("xfs_protofile version")
+               pkgver = "@pkg_version@"
+               print(f"{msg} {pkgver}")
                sys.exit(0)
 
        emit_proto_header()