From: Bruno Haible Date: Fri, 9 Jun 2023 01:37:43 +0000 (+0200) Subject: New example 'hello-c++20'. X-Git-Tag: v0.22~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2c6717ef924408b1f033b3d118238b1bb5ebfcc;p=thirdparty%2Fgettext.git New example 'hello-c++20'. * gettext-tools/examples/hello-c++20: New directory, based on gettext-tools/examples/hello-c++. * gettext-tools/examples/Makefile.am (EXAMPLESFILES, EXAMPLESDIRS): Update. * gettext-tools/examples/po/Makefile.am (POTFILES, SMALLPOTS, SMALLPOFILES_FOR_lang): Update. (hello-c++20.pot, hello-c++20/po/$(LL).po): New rules. * gettext-tools/examples/README: Update. * gettext-tools/examples/check-examples (func_check_autoclean_all, func_check_distclean_all, func_check_maintainerclean_all, func_check_maintainerclean_vpath_all, func_check_dist_all, func_check_dist_vpath_all, func_check_install_all, func_check_uninstall_all, func_check_distcheck_all, func_check_all): Handle this directory as well. * NEWS: Mention the new example. --- diff --git a/NEWS b/NEWS index 700e42e26..b204b9959 100644 --- a/NEWS +++ b/NEWS @@ -25,6 +25,8 @@ Version 0.21.2 - May 2023 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. diff --git a/gettext-tools/examples/Makefile.am b/gettext-tools/examples/Makefile.am index 184cb233a..cd4fedc3e 100644 --- a/gettext-tools/examples/Makefile.am +++ b/gettext-tools/examples/Makefile.am @@ -1,5 +1,5 @@ ## 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 @@ -77,6 +77,16 @@ EXAMPLESFILES = \ 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 \ @@ -377,6 +387,7 @@ EXAMPLESDIRS = \ hello-c-gnome \ hello-c-gnome3 \ hello-c++ \ + hello-c++20 \ hello-c++-qt \ hello-c++-kde \ hello-c++-gnome \ diff --git a/gettext-tools/examples/README b/gettext-tools/examples/README index 93878fe6b..1deb640c4 100644 --- a/gettext-tools/examples/README +++ b/gettext-tools/examples/README @@ -9,6 +9,7 @@ environment. 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) @@ -57,6 +58,7 @@ Makefile types: 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 diff --git a/gettext-tools/examples/check-examples b/gettext-tools/examples/check-examples index aac01fe90..b9fa52ea7 100755 --- a/gettext-tools/examples/check-examples +++ b/gettext-tools/examples/check-examples @@ -1,7 +1,7 @@ #!/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 @@ -132,6 +132,7 @@ func_check_autoclean_all () 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 @@ -203,6 +204,7 @@ func_check_distclean_all () #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 @@ -276,6 +278,7 @@ func_check_maintainerclean_all () #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 @@ -352,6 +355,7 @@ func_check_maintainerclean_vpath_all () #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 @@ -435,6 +439,7 @@ func_check_dist_all () #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 @@ -518,6 +523,7 @@ func_check_dist_vpath_all () #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 @@ -593,6 +599,7 @@ func_check_install_all () #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 @@ -665,6 +672,7 @@ func_check_uninstall_all () #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 @@ -739,6 +747,7 @@ func_check_distcheck_all () #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 @@ -788,6 +797,7 @@ func_check_all () 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 diff --git a/gettext-tools/examples/hello-c++20/INSTALL b/gettext-tools/examples/hello-c++20/INSTALL new file mode 100644 index 000000000..5fc66f497 --- /dev/null +++ b/gettext-tools/examples/hello-c++20/INSTALL @@ -0,0 +1,10 @@ +This example relies on libstdc++, gettext-runtime. + +Installation: + ./autogen.sh + ./configure --prefix=/some/prefix + make + make install +Cleanup: + make distclean + ./autoclean.sh diff --git a/gettext-tools/examples/hello-c++20/Makefile.am b/gettext-tools/examples/hello-c++20/Makefile.am new file mode 100644 index 000000000..2a371c664 --- /dev/null +++ b/gettext-tools/examples/hello-c++20/Makefile.am @@ -0,0 +1,29 @@ +# 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 diff --git a/gettext-tools/examples/hello-c++20/autoclean.sh b/gettext-tools/examples/hello-c++20/autoclean.sh new file mode 100755 index 000000000..55dc86404 --- /dev/null +++ b/gettext-tools/examples/hello-c++20/autoclean.sh @@ -0,0 +1,45 @@ +#!/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 diff --git a/gettext-tools/examples/hello-c++20/autogen.sh b/gettext-tools/examples/hello-c++20/autogen.sh new file mode 100755 index 000000000..0332a9b21 --- /dev/null +++ b/gettext-tools/examples/hello-c++20/autogen.sh @@ -0,0 +1,48 @@ +#!/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 .. diff --git a/gettext-tools/examples/hello-c++20/configure.ac b/gettext-tools/examples/hello-c++20/configure.ac new file mode 100644 index 000000000..ea6c8995f --- /dev/null +++ b/gettext-tools/examples/hello-c++20/configure.ac @@ -0,0 +1,30 @@ +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 +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 diff --git a/gettext-tools/examples/hello-c++20/hello.cc b/gettext-tools/examples/hello-c++20/hello.cc new file mode 100644 index 000000000..ee0e24349 --- /dev/null +++ b/gettext-tools/examples/hello-c++20/hello.cc @@ -0,0 +1,40 @@ +// Example for use of GNU gettext. +// This file is in the public domain. + +// Source code of the ISO C++ 20 program. + + +#include +#include +using namespace std; + +// Get setlocale() declaration. +#include + +// Get getpid() declaration. +#if defined _WIN32 && !defined __CYGWIN__ +/* native Windows API */ +# include +# define getpid _getpid +#else +/* POSIX API */ +# include +#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; +} diff --git a/gettext-tools/examples/hello-c++20/m4/Makefile.am b/gettext-tools/examples/hello-c++20/m4/Makefile.am new file mode 100644 index 000000000..913548ef1 --- /dev/null +++ b/gettext-tools/examples/hello-c++20/m4/Makefile.am @@ -0,0 +1,3 @@ +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 diff --git a/gettext-tools/examples/hello-c++20/po/LINGUAS b/gettext-tools/examples/hello-c++20/po/LINGUAS new file mode 100644 index 000000000..dc4a82afb --- /dev/null +++ b/gettext-tools/examples/hello-c++20/po/LINGUAS @@ -0,0 +1,5 @@ +# 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 diff --git a/gettext-tools/examples/hello-c++20/po/Makevars b/gettext-tools/examples/hello-c++20/po/Makevars new file mode 100644 index 000000000..df0a9fb1f --- /dev/null +++ b/gettext-tools/examples/hello-c++20/po/Makevars @@ -0,0 +1,84 @@ +# 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 diff --git a/gettext-tools/examples/hello-c++20/po/POTFILES.in b/gettext-tools/examples/hello-c++20/po/POTFILES.in new file mode 100644 index 000000000..bd28e81ce --- /dev/null +++ b/gettext-tools/examples/hello-c++20/po/POTFILES.in @@ -0,0 +1,5 @@ +# Example for use of GNU gettext. +# This file is in the public domain. +# +# List of files which contain translatable strings. +hello.cc diff --git a/gettext-tools/examples/po/Makefile.am b/gettext-tools/examples/po/Makefile.am index 175c3692b..825e6ce95 100644 --- a/gettext-tools/examples/po/Makefile.am +++ b/gettext-tools/examples/po/Makefile.am @@ -27,6 +27,7 @@ POTFILES = \ 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 \ @@ -67,6 +68,7 @@ SMALLPOTS = \ 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 \ @@ -251,6 +253,9 @@ hello-c-gnome3.pot : $(POTFILES_DEPS) 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 @@ -410,6 +415,7 @@ SMALLPOFILES_FOR_lang = \ $(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 \ @@ -449,6 +455,9 @@ $(srcdir)/../hello-c-gnome3/po/$(LL).po: $(srcdir)/hello-c-gnome3.pot $(srcdir)/ $(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)