in format strings.
o xgettext and msgfmt now recognize C++ format strings, as defined by
ISO C++ 20. They are marked as 'c++-format' in POT and PO files.
+ A new example has been added, 'hello-c++20', that illustrates how
+ to use these format strings with gettext.
- Tcl: xgettext now supports the \x, \u, and \U escapes as defined in
Tcl 8.6.
## Makefile for the gettext-tools/examples subdirectory of GNU gettext
-## Copyright (C) 2001-2007, 2009-2016, 2018-2022 Free Software Foundation, Inc.
+## Copyright (C) 2001-2007, 2009-2016, 2018-2023 Free Software Foundation, Inc.
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
hello-c++/po/Makevars \
hello-c++/po/POTFILES.in \
\
+ hello-c++20/INSTALL \
+ hello-c++20/autogen.sh \
+ hello-c++20/autoclean.sh \
+ hello-c++20/hello.cc \
+ hello-c++20/Makefile.am \
+ hello-c++20/configure.ac \
+ hello-c++20/m4/Makefile.am \
+ hello-c++20/po/Makevars \
+ hello-c++20/po/POTFILES.in \
+ \
hello-c++-qt/INSTALL \
hello-c++-qt/BUGS \
hello-c++-qt/autogen.sh \
hello-c-gnome \
hello-c-gnome3 \
hello-c++ \
+ hello-c++20 \
hello-c++-qt \
hello-c++-kde \
hello-c++-gnome \
hello-c-gnome C GNOME (obsolete)
hello-c-gnome3 C GNOME 3.10 or later
hello-c++ C++
+ hello-c++20 C++ 20
hello-c++-qt C++ Qt
hello-c++-kde C++ KDE
hello-c++-gnome C++ GNOME (obsolete)
hello-c-gnome .gmo Makefile.in.in
hello-c-gnome3 .gmo Makefile.in.in
hello-c++ .gmo Makefile.in.in
+ hello-c++20 .gmo Makefile.in.in
hello-c++-kde .gmo Makefile.in.in
hello-c++-gnome .gmo Makefile.in.in
hello-objc .gmo Makefile.in.in
#!/bin/bash
# Script that checks against build infrastructure mistakes in the examples.
-# Copyright (C) 2018 Free Software Foundation, Inc.
+# Copyright (C) 2018, 2023 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
func_check_autoclean hello-c-gnome
func_check_autoclean hello-c-gnome3
func_check_autoclean hello-c++
+ func_check_autoclean hello-c++20
func_check_autoclean hello-c++-qt
func_check_autoclean hello-c++-kde
func_check_autoclean hello-c++-gnome
#func_check_distclean hello-c-gnome
#func_check_distclean hello-c-gnome3
func_check_distclean hello-c++
+ func_check_distclean hello-c++20
#func_check_distclean hello-c++-qt
#func_check_distclean hello-c++-kde
#func_check_distclean hello-c++-gnome
#func_check_maintainerclean hello-c-gnome
#func_check_maintainerclean hello-c-gnome3
func_check_maintainerclean hello-c++
+ func_check_maintainerclean hello-c++20
#func_check_maintainerclean hello-c++-qt
#func_check_maintainerclean hello-c++-kde
#func_check_maintainerclean hello-c++-gnome
#func_check_maintainerclean_vpath hello-c-gnome
#func_check_maintainerclean_vpath hello-c-gnome3
func_check_maintainerclean_vpath hello-c++
+ func_check_maintainerclean_vpath hello-c++20
#func_check_maintainerclean_vpath hello-c++-qt
#func_check_maintainerclean_vpath hello-c++-kde
#func_check_maintainerclean_vpath hello-c++-gnome
#func_check_dist hello-c-gnome
#func_check_dist hello-c-gnome3
func_check_dist hello-c++
+ func_check_dist hello-c++20
#func_check_dist hello-c++-qt
#func_check_dist hello-c++-kde
#func_check_dist hello-c++-gnome
#func_check_dist_vpath hello-c-gnome
#func_check_dist_vpath hello-c-gnome3
func_check_dist_vpath hello-c++
+ func_check_dist_vpath hello-c++20
#func_check_dist_vpath hello-c++-qt
#func_check_dist_vpath hello-c++-kde
#func_check_dist_vpath hello-c++-gnome
#func_check_install hello-c-gnome
#func_check_install hello-c-gnome3
func_check_install hello-c++
+ func_check_install hello-c++20
#func_check_install hello-c++-qt
#func_check_install hello-c++-kde
#func_check_install hello-c++-gnome
#func_check_uninstall hello-c-gnome
#func_check_uninstall hello-c-gnome3
func_check_uninstall hello-c++
+ func_check_uninstall hello-c++20
#func_check_uninstall hello-c++-qt
#func_check_uninstall hello-c++-kde
#func_check_uninstall hello-c++-gnome
#func_check_distcheck hello-c-gnome
#func_check_distcheck hello-c-gnome3
func_check_distcheck hello-c++
+ func_check_distcheck hello-c++20
#func_check_distcheck hello-c++-qt
#func_check_distcheck hello-c++-kde
#func_check_distcheck hello-c++-gnome
func_check hello-c-gnome
func_check hello-c-gnome3
func_check hello-c++
+ func_check hello-c++20
func_check hello-c++-qt
func_check hello-c++-kde
func_check hello-c++-gnome
--- /dev/null
+This example relies on libstdc++, gettext-runtime.
+
+Installation:
+ ./autogen.sh
+ ./configure --prefix=/some/prefix
+ make
+ make install
+Cleanup:
+ make distclean
+ ./autoclean.sh
--- /dev/null
+# Example for use of GNU gettext.
+# This file is in the public domain.
+#
+# Makefile configuration - processed by automake.
+
+# General automake options.
+AUTOMAKE_OPTIONS = foreign no-dependencies
+ACLOCAL_AMFLAGS = -I m4
+
+# The list of subdirectories containing Makefiles.
+SUBDIRS = m4 po
+
+# The list of programs that are built.
+bin_PROGRAMS = hello
+
+# The source files of the 'hello' program.
+hello_SOURCES = hello.cc gettext.h
+
+# Define a C macro LOCALEDIR indicating where catalogs will be installed.
+DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
+
+# Make sure the gettext.h include file is found.
+AM_CPPFLAGS = -I. -I$(srcdir)
+
+# Link time dependencies.
+LDADD = @LIBINTL@
+
+# Additional files to be distributed.
+EXTRA_DIST = autogen.sh autoclean.sh
--- /dev/null
+#!/bin/sh
+# Example for use of GNU gettext.
+# This file is in the public domain.
+#
+# Script for cleaning all autogenerated files.
+
+test ! -f Makefile || make distclean
+rm -rf autom4te.cache
+
+# Brought in by explicit copy.
+rm -f gettext.h
+
+# Brought in by autopoint.
+rm -f ABOUT-NLS
+rm -f config.rpath
+rm -f m4/gettext.m4
+rm -f m4/host-cpu-c-abi.m4
+rm -f m4/iconv.m4
+rm -f m4/intlmacosx.m4
+rm -f m4/lib-ld.m4
+rm -f m4/lib-link.m4
+rm -f m4/lib-prefix.m4
+rm -f m4/nls.m4
+rm -f m4/po.m4
+rm -f m4/progtest.m4
+rm -f po/Makefile.in.in
+rm -f po/remove-potcdate.sin
+
+# Generated by aclocal.
+rm -f aclocal.m4
+
+# Generated by autoconf.
+rm -f configure
+
+# Generated or brought in by automake.
+rm -f Makefile.in
+rm -f m4/Makefile.in
+rm -f compile
+rm -f install-sh
+rm -f missing
+rm -f config.guess
+rm -f config.sub
+rm -f po/*.pot
+rm -f po/stamp-po
+rm -f po/*.gmo
--- /dev/null
+#!/bin/sh
+# Example for use of GNU gettext.
+# This file is in the public domain.
+#
+# Script for regenerating all autogenerated files.
+
+if test -r ../Makefile.am; then
+ # Inside the gettext source directory.
+ GETTEXT_TOPSRCDIR=../../..
+else
+ if test -r ../Makefile; then
+ # Inside a gettext build directory.
+ GETTEXT_TOOLS_SRCDIR=`sed -n -e 's,^top_srcdir *= *\(.*\)$,\1,p' ../Makefile`
+ # Adjust a relative top_srcdir.
+ case $GETTEXT_TOOLS_SRCDIR in
+ /*) ;;
+ *) GETTEXT_TOOLS_SRCDIR=../$GETTEXT_TOOLS_SRCDIR ;;
+ esac
+ GETTEXT_TOPSRCDIR=$GETTEXT_TOOLS_SRCDIR/../..
+ else
+ # Installed under ${prefix}/share/doc/gettext/examples.
+ . ../installpaths
+ fi
+fi
+
+cp -p ${GETTEXTSRCDIR-$GETTEXT_TOPSRCDIR/gettext-tools/gnulib-lib}/gettext.h gettext.h
+
+autopoint -f # was: gettextize -f -c
+rm po/Makevars.template
+rm po/Rules-quot
+rm po/boldquot.sed
+rm po/en@boldquot.header
+rm po/en@quot.header
+rm po/insert-header.sin
+rm po/quot.sed
+
+aclocal -I m4
+
+autoconf
+
+automake -a -c
+
+cd po
+for f in *.po; do
+ lang=`echo $f | sed -e 's,\.po$,,'`
+ msgfmt -c -o $lang.gmo $lang.po
+done
+cd ..
--- /dev/null
+dnl Example for use of GNU gettext.
+dnl This file is in the public domain.
+dnl
+dnl Configuration file - processed by autoconf.
+
+AC_INIT([hello-c++20], [0], , [hello-c++20])
+AC_CONFIG_SRCDIR([hello.cc])
+AM_INIT_AUTOMAKE([1.11])
+
+AC_PROG_CXX
+
+# Try to find compiler option for ISO C++ 20 support.
+cat <<\EOF > conftest.cc
+#include <format>
+using std::vformat;
+using std::make_format_args;
+EOF
+if ${CXX} ${CXXFLAGS} ${CPPFLAGS} -c conftest.cc 2>/dev/null; then
+ :
+elif ${CXX} ${CXXFLAGS} -std=gnu++20 ${CPPFLAGS} -c conftest.cc 2>/dev/null; then
+ CXXFLAGS="${CXXFLAGS} -std=gnu++20"
+fi
+
+AM_GNU_GETTEXT([external])
+AM_GNU_GETTEXT_VERSION([0.21.1])
+
+AC_CONFIG_FILES([Makefile])
+AC_CONFIG_FILES([m4/Makefile])
+AC_CONFIG_FILES([po/Makefile.in])
+AC_OUTPUT
--- /dev/null
+// Example for use of GNU gettext.
+// This file is in the public domain.
+
+// Source code of the ISO C++ 20 program.
+
+
+#include <format>
+#include <iostream>
+using namespace std;
+
+// Get setlocale() declaration.
+#include <locale.h>
+
+// Get getpid() declaration.
+#if defined _WIN32 && !defined __CYGWIN__
+/* native Windows API */
+# include <process.h>
+# define getpid _getpid
+#else
+/* POSIX API */
+# include <unistd.h>
+#endif
+
+// Get gettext(), textdomain(), bindtextdomain() declaration.
+#include "gettext.h"
+// Define shortcut for gettext().
+#define _(string) gettext (string)
+
+int
+main ()
+{
+ setlocale (LC_ALL, "");
+ textdomain ("hello-c++20");
+ bindtextdomain ("hello-c++20", LOCALEDIR);
+
+ cout << _("Hello, world!") << endl;
+ cout << vformat (_("This program is running as process number {:d}."),
+ make_format_args (getpid ()))
+ << endl;
+}
--- /dev/null
+EXTRA_DIST = \
+ gettext.m4 host-cpu-c-abi.m4 iconv.m4 lib-ld.m4 lib-link.m4 lib-prefix.m4 \
+ nls.m4 po.m4 progtest.m4
--- /dev/null
+# Example for use of GNU gettext.
+# This file is in the public domain.
+#
+# Set of available languages.
+af ast bg ca cs da de el eo es fi fr ga gl hr hu id it ja ka ky lv ms mt nb nl nn pl pt pt_BR ro ru sk sl sq sr sv ta tr uk vi zh_CN zh_HK zh_TW
--- /dev/null
+# Makefile variables for PO directory in any package using GNU gettext.
+#
+# Copyright (C) 2003-2019 Free Software Foundation, Inc.
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to use, copy, distribute, and modify it.
+
+# Usually the message domain is the same as the package name.
+DOMAIN = $(PACKAGE)
+
+# These two variables depend on the location of this directory.
+subdir = po
+top_builddir = ..
+
+# These options get passed to xgettext.
+XGETTEXT_OPTIONS = \
+ --keyword=_ --flag=_:1:pass-c-format \
+ --keyword=N_ --flag=N_:1:pass-c-format \
+ --flag=autosprintf:1:c-format
+
+# This is the copyright holder that gets inserted into the header of the
+# $(DOMAIN).pot file. Set this to the copyright holder of the surrounding
+# package. (Note that the msgstr strings, extracted from the package's
+# sources, belong to the copyright holder of the package.) Translators are
+# expected to transfer the copyright for their translations to this person
+# or entity, or to disclaim their copyright. The empty string stands for
+# the public domain; in this case the translators are expected to disclaim
+# their copyright.
+COPYRIGHT_HOLDER = Yoyodyne, Inc.
+
+# This tells whether or not to prepend "GNU " prefix to the package
+# name that gets inserted into the header of the $(DOMAIN).pot file.
+# Possible values are "yes", "no", or empty. If it is empty, try to
+# detect it automatically by scanning the files in $(top_srcdir) for
+# "GNU packagename" string.
+PACKAGE_GNU = no
+
+# This is the email address or URL to which the translators shall report
+# bugs in the untranslated strings:
+# - Strings which are not entire sentences, see the maintainer guidelines
+# in the GNU gettext documentation, section 'Preparing Strings'.
+# - Strings which use unclear terms or require additional context to be
+# understood.
+# - Strings which make invalid assumptions about notation of date, time or
+# money.
+# - Pluralisation problems.
+# - Incorrect English spelling.
+# - Incorrect formatting.
+# It can be your email address, or a mailing list address where translators
+# can write to without being subscribed, or the URL of a web page through
+# which the translators can contact you.
+MSGID_BUGS_ADDRESS = bug-gettext@gnu.org
+
+# This is the list of locale categories, beyond LC_MESSAGES, for which the
+# message catalogs shall be used. It is usually empty.
+EXTRA_LOCALE_CATEGORIES =
+
+# This tells whether the $(DOMAIN).pot file contains messages with an 'msgctxt'
+# context. Possible values are "yes" and "no". Set this to yes if the
+# package uses functions taking also a message context, like pgettext(), or
+# if in $(XGETTEXT_OPTIONS) you define keywords with a context argument.
+USE_MSGCTXT = no
+
+# These options get passed to msgmerge.
+# Useful options are in particular:
+# --previous to keep previous msgids of translated messages
+MSGMERGE_OPTIONS =
+
+# These options get passed to msginit.
+# If you want to disable line wrapping when writing PO files, add
+# --no-wrap to MSGMERGE_OPTIONS, XGETTEXT_OPTIONS, and
+# MSGINIT_OPTIONS.
+MSGINIT_OPTIONS =
+
+# This tells whether or not to regenerate a PO file when $(DOMAIN).pot
+# has changed. Possible values are "yes" and "no". Set this to no if
+# the POT file is checked in the repository and the version control
+# program ignores timestamps.
+PO_DEPENDS_ON_POT = yes
+
+# This tells whether or not to forcibly update $(DOMAIN).pot and
+# regenerate PO files on "make dist". Possible values are "yes" and
+# "no". Set this to no if the POT file and PO files are maintained
+# externally.
+DIST_DEPENDS_ON_UPDATE_PO = yes
--- /dev/null
+# Example for use of GNU gettext.
+# This file is in the public domain.
+#
+# List of files which contain translatable strings.
+hello.cc
hello-c-gnome3/hello.gschema.xml \
hello-c-gnome3/hello.ui \
hello-c++/hello.cc \
+ hello-c++20/hello.cc \
hello-c++-qt/hello.cc \
hello-c++-kde/hello.cc \
hello-c++-kde/hellowindow.h \
hello-c-gnome.pot \
hello-c-gnome3.pot \
hello-c++.pot \
+ hello-c++20.pot \
hello-c++-qt.pot \
hello-c++-kde.pot \
hello-c++-gnome.pot \
hello-c++.pot : $(POTFILES_DEPS)
$(USE_BUILT_PROGS) $(SHELL) '$(srcdir)/xsmallpot.sh' '$(srcdir)' hello-c++
+hello-c++20.pot : $(POTFILES_DEPS)
+ $(USE_BUILT_PROGS) $(SHELL) '$(srcdir)/xsmallpot.sh' '$(srcdir)' hello-c++20
+
hello-c++-qt.pot : $(POTFILES_DEPS)
$(USE_BUILT_PROGS) $(SHELL) '$(srcdir)/xsmallpot.sh' '$(srcdir)' hello-c++-qt
$(srcdir)/../hello-c-gnome/po/$$lang.po \
$(srcdir)/../hello-c-gnome3/po/$$lang.po \
$(srcdir)/../hello-c++/po/$$lang.po \
+ $(srcdir)/../hello-c++20/po/$$lang.po \
$(srcdir)/../hello-c++-qt/po/$$lang.po \
$(srcdir)/../hello-c++-kde/po/$$lang.po \
$(srcdir)/../hello-c++-gnome/po/$$lang.po \
$(srcdir)/../hello-c++/po/$(LL).po: $(srcdir)/hello-c++.pot $(srcdir)/$(LL).po
$(USE_BUILT_PROGS) cd $(srcdir) && $(SHELL) mmsmallpo.sh hello-c++ $(LL)
+$(srcdir)/../hello-c++20/po/$(LL).po: $(srcdir)/hello-c++20.pot $(srcdir)/$(LL).po
+ $(USE_BUILT_PROGS) cd $(srcdir) && $(SHELL) mmsmallpo.sh hello-c++20 $(LL)
+
$(srcdir)/../hello-c++-qt/po/$(LL).po: $(srcdir)/hello-c++-qt.pot $(srcdir)/$(LL).po
$(USE_BUILT_PROGS) cd $(srcdir) && $(SHELL) mmsmallpo.sh hello-c++-qt $(LL)