From 8a96f3d73d063f414b7c08577de7b4759cdd76f2 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Tue, 1 Apr 2025 07:44:28 -0700 Subject: [PATCH] xfs_protofile: add messages to localization catalog 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 Reviewed-by: Andrey Albershteyn Reviewed-by: Bill O'Donnell --- configure.ac | 2 +- include/buildrules | 1 - libfrog/Makefile | 18 +++++++++++++++++- libfrog/gettext.py.in | 12 ++++++++++++ mkfs/Makefile | 7 +++++-- mkfs/xfs_protofile.py.in | 21 ++++++++++++--------- 6 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 libfrog/gettext.py.in diff --git a/configure.ac b/configure.ac index 71596711..42021447 100644 --- a/configure.ac +++ b/configure.ac @@ -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) diff --git a/include/buildrules b/include/buildrules index ae047ac4..871e92db 100644 --- a/include/buildrules +++ b/include/buildrules @@ -86,7 +86,6 @@ endif ifdef POTHEAD XGETTEXT_FLAGS=\ - --language=C \ --keyword=_ \ --keyword=N_ \ --package-name=$(PKG_NAME) \ diff --git a/libfrog/Makefile b/libfrog/Makefile index fc7e506d..b64ca459 100644 --- a/libfrog/Makefile +++ b/libfrog/Makefile @@ -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 index 00000000..61559f73 --- /dev/null +++ b/libfrog/gettext.py.in @@ -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 + diff --git a/mkfs/Makefile b/mkfs/Makefile index b1369e18..04905bd5 100644 --- a/mkfs/Makefile +++ b/mkfs/Makefile @@ -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 diff --git a/mkfs/xfs_protofile.py.in b/mkfs/xfs_protofile.py.in index e83c39f5..040454da 100644 --- a/mkfs/xfs_protofile.py.in +++ b/mkfs/xfs_protofile.py.in @@ -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() -- 2.47.2