/* xgettext Vala backend.
- Copyright (C) 2013-2014, 2018-2023 Free Software Foundation, Inc.
+ Copyright (C) 2013-2014, 2018-2024 Free Software Foundation, Inc.
This file was written by Daiki Ueno <ueno@gnu.org>, 2013.
xgettext_record_flag ("N_:1:pass-c-format!Vala");
xgettext_record_flag ("NC_:2:pass-c-format!Vala");
- xgettext_record_flag ("printf:1:c-format!Vala");
+ /* In Vala, vprintf does not exist as a function, only as a method.
+ https://valadoc.org/?q=printf provides this list:
+
+ Method Arguments
+
+ Posix.FILE.printf (posix) (string format, ...)
+ Posix.printf (posix) (string format, ...)
+ Alsa.Output.printf (alsa) (string format, ...)
+ Dazzle.Path.printf (libdazzle-1.0) ()
+ Dazzle.ShortcutChordTable.printf (libdazzle-1.0) ()
+ string.printf (glib-2.0) (...)
+ GLib.FileStream.printf (glib-2.0) (string format, ...)
+ GLib.StringBuilder.printf (glib-2.0) (string format, ...)
+ GLib.Variant.Variant.printf (glib-2.0) (string format, ...)
+ FastCGI.FileStream.printf (fcgi) (string format, ...)
+ FastCGI.Stream.printf (fcgi) (string format, ...)
+ Purple.Stringref.printf (purple) (string format)
+ Gsl.Stream.printf (gsl) (string label, string file, int line, string reason)
+ Gsf.Output.printf (libgsf-1) (string format, ...)
+ GLib.OutputStream.printf (gio-2.0) (out size_t bytes_written, Cancellable? cancellable, string format, ...)
+ TokyoCabinet.XString.printf (tokyocabinet) (string format, ...)
+ ZLib.GZFileStream.printf (zlib) (string format, ...)
+
+ Therefore, whenever the first argument is a string, it may be a format
+ string or a plain string. We don't know. Therefore we cannot enable
+ this flag. Recognition of format strings that occur as a first argument
+ therefore relies on the heuristics. */
+ /* Override the effect of
+ xgettext_record_flag ("printf:1:c-format");
+ in x-c.c. */
+ xgettext_record_flag ("printf:1:undecided-c-format!Vala");
+
+ /* In Vala, vprintf does not exist as a function, only as a method.
+ https://valadoc.org/?q=vprintf provides this list:
+
+ Method Arguments
+ string.vprintf (glib-2.0) (va_list args)
+ GLib.FileStream.vprintf (glib-2.0) (string format, va_list args)
+ GLib.StringBuilder.vprintf (glib-2.0) (string format, va_list args)
+ FastCGI.FileStream.vprintf (fcgi) (string format, va_list args)
+ FastCGI.Stream.vprintf (fcgi) (string format, va_list args)
+ Gsf.Output.vprintf (libgsf-1) (string format, va_list args)
+ GLib.OutputStream.vprintf (gio-2.0) (out size_t bytes_written, Cancellable? cancellable, string format, va_list args)
+
+ Therefore, whenever the first argument is a string, it must be a format
+ string. */
xgettext_record_flag ("vprintf:1:c-format!Vala");
}
## Makefile for the gettext-tools/tests subdirectory of GNU gettext
-## Copyright (C) 1995-1997, 2001-2010, 2012-2016, 2018-2023 Free Software Foundation, Inc.
+## Copyright (C) 1995-1997, 2001-2010, 2012-2016, 2018-2024 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
xgettext-tcl-stackovfl-1 xgettext-tcl-stackovfl-2 \
xgettext-tcl-stackovfl-3 xgettext-tcl-stackovfl-4 \
xgettext-vala-1 xgettext-vala-2 xgettext-vala-3 xgettext-vala-4 \
- xgettext-vala-5 \
+ xgettext-vala-5 xgettext-vala-6 \
xgettext-vala-stackovfl-1 xgettext-vala-stackovfl-2 \
xgettext-ycp-1 xgettext-ycp-2 xgettext-ycp-3 xgettext-ycp-4 \
xgettext-ycp-stackovfl-1 xgettext-ycp-stackovfl-2 \
--- /dev/null
+#! /bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# Test Vala support: printf and format strings.
+
+: ${XGETTEXT=xgettext}
+
+cat <<\EOF > xg-vala-6.vala
+"<b>%s</b>".printf(_("Hello 1"));
+_("Explanation: %s").printf(_("Hello 2"));
+Posix.printf(_("Hello 3"));
+Posix.printf(_("Hello 4 %s!"), _("Sir"));
+EOF
+
+${XGETTEXT} --omit-header --no-location -o xg-vala-6.tmp xg-vala-6.vala || Exit 1
+func_filter_POT_Creation_Date xg-vala-6.tmp xg-vala-6.po
+
+cat <<\EOF > xg-vala-6.ok
+msgid "Hello 1"
+msgstr ""
+
+#, c-format
+msgid "Explanation: %s"
+msgstr ""
+
+msgid "Hello 2"
+msgstr ""
+
+msgid "Hello 3"
+msgstr ""
+
+#, c-format
+msgid "Hello 4 %s!"
+msgstr ""
+
+msgid "Sir"
+msgstr ""
+EOF
+
+: ${DIFF=diff}
+${DIFF} xg-vala-6.ok xg-vala-6.po
+result=$?
+
+exit $result