+2003-07-05 Bruno Haible <bruno@clisp.org>
+
+ * gettext.texi (perl-format): Use braces, not brackets, in format
+ strings.
+ (Perl pitfalls): Likewise.
+
2003-07-03 Bruno Haible <bruno@clisp.org>
* gettext.texi (PHP): Mention plural form functions.
There are two kinds format strings in Perl: those acceptable to the
Perl built-in function @code{printf}, labelled as @samp{perl-format},
and those acceptable to the @code{libintl-perl} function @code{__x},
-labelled as @samp{perl-bracket-format}.
+labelled as @samp{perl-brace-format}.
Perl @code{printf} format strings are described in the @code{sprintf}
section of @samp{man perlfunc}.
-Perl bracketed format strings are described in the
+Perl brace format strings are described in the
@file{Locale::TextDomain(3pm)} manual page of the CPAN package
libintl-perl. In brief, Perl format uses placeholders put between
-brackets (@samp{[} and @samp{]}). The placeholder must have the syntax
+braces (@samp{@{} and @samp{@}}). The placeholder must have the syntax
of simple identifiers.
@node php-format, , perl-format, Translators for other Languages
versions, but since you can always make do without them at minimal effort,
these todos have very low priority.
-A nasty problem are bracketed format strings that already contain brackets
+A nasty problem are brace format strings that already contain braces
as part of the normal text, for example the usage strings typically
encountered in programs:
@example
-die "usage: $0 [OPTIONS] FILENAME...\n";
+die "usage: $0 @{OPTIONS@} FILENAME...\n";
@end example
-If you want to internationalize this code with Perl bracketed format strings,
+If you want to internationalize this code with Perl brace format strings,
you will run into a problem:
@example
-die __x ("usage: [program] [OPTIONS] FILENAME...\n", program => $0);
+die __x ("usage: @{program@} @{OPTIONS@} FILENAME...\n", program => $0);
@end example
-Whereas @code{@samp{[program]}} is a placeholder, @code{@samp{[OPTIONS]}}
+Whereas @samp{@{program@}} is a placeholder, @samp{@{OPTIONS@}}
is not and should probably be translated. Yet, there is no way to teach
the Perl parser in @code{xgettext} to recognize the first one, and leave
the other one alone.
sure that your program will run under Perl 5.8.0 or newer (these
Perl versions handle positional parameters in @code{printf()}) or
if you are sure that the translator will not have to reorder the arguments
-in her translation -- for example if you have only one bracketed placeholder
+in her translation -- for example if you have only one brace placeholder
in your string, or if it describes a syntax, like in this one --, you can
-mark the string as @code{no-perl-bracket-format} and use @code{printf()}:
+mark the string as @code{no-perl-brace-format} and use @code{printf()}:
@example
-# xgettext: no-perl-bracket-format
-die sprintf ("usage: %s [OPTIONS] FILENAME...\n", $0);
+# xgettext: no-perl-brace-format
+die sprintf ("usage: %s @{OPTIONS@} FILENAME...\n", $0);
@end example
-If you want to use the more portable Perl bracket format, you will have to do
-put placeholders in place of the literal brackets:
+If you want to use the more portable Perl brace format, you will have to do
+put placeholders in place of the literal braces:
@example
-die __x ("usage: [program] [@{]OPTIONS[@}] FILENAME...\n",
- program => $0, '@{' => '[', '@}' => ']');
+die __x ("usage: @{program@} @{[@}OPTIONS@{]@} FILENAME...\n",
+ program => $0, '[' => '@{', ']' => '@}');
@end example
-Perl bracketed format strings know no escaping mechanism. No matter how this
+Perl brace format strings know no escaping mechanism. No matter how this
escaping mechanism looked like, it would either give the programmer a
-hard time, make translating Perl bracketed format strings heavy-going, or
+hard time, make translating Perl brace format strings heavy-going, or
result in a performance penalty at runtime, when the format directives
get executed. Most of the time you will happily get along with
@code{printf()} for this special case.
+2003-07-05 Bruno Haible <bruno@clisp.org>
+
+ * POTFILES.in: Add format-perl-brace.c, remove format-perl-bracket.c.
+
2003-07-31 Bruno Haible <bruno@clisp.org>
* ca.po: Update from Ivan Vilata i Balaguer <ivan@selidor.net>.
src/format-lisp.c
src/format-pascal.c
src/format-perl.c
-src/format-perl-bracket.c
+src/format-perl-brace.c
src/format-php.c
src/format-python.c
src/format-tcl.c
+2003-07-05 Bruno Haible <bruno@clisp.org>
+
+ * format-perl-brace.c: Renamed from format-perl-bracket.c. Recognize
+ braces instead of brackets.
+ * format.h (formatstring_perl_brace): Renamed from
+ formatstring_perl_bracket.
+ * format.c (formatstring_parsers): Add formatstring_perl_brace, remove
+ formatstring_perl_bracket.
+ * message.h (enum format_type): Add format_perl_brace, remove
+ format_perl_bracket.
+ * message.c (format_language, format_language_pretty): Update.
+ * x-perl.h (SCANNERS_PERL): Update.
+ * Makefile.am (FORMAT_SOURCE): Add format-perl-brace.c, remove
+ format-perl-bracket.c.
+ * Makefile.msvc (OBJECTS): Add format-perl-brace.obj, remove
+ format-perl-bracket.obj.
+ (format-perl-brace.obj): Renamed from format-perl-bracket.obj.
+ * Makefile.vms (OBJECTS): Add format-perl-brace.obj, remove
+ format-perl-bracket.obj.
+ (format-perl-brace.obj): Renamed from format-perl-bracket.obj.
+
2003-07-03 Bruno Haible <bruno@clisp.org>
Support for PHP >= 4.2.0.
FORMAT_SOURCE = format.c format-invalid.h \
format-c.c format-python.c format-lisp.c format-elisp.c format-librep.c \
format-java.c format-awk.c format-pascal.c format-ycp.c format-tcl.c \
-format-perl.c format-perl-bracket.c format-php.c
+format-perl.c format-perl-brace.c format-php.c
# libgettextsrc contains all code that is needed by at least two programs.
libgettextsrc_la_SOURCES = \
format-ycp.obj \
format-tcl.obj \
format-perl.obj \
- format-perl-bracket.obj \
+ format-perl-brace.obj \
format-php.obj
msgcmp_OBJECTS = msgcmp.obj
format-perl.obj : format-perl.c
$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c format-perl.c
-format-perl-bracket.obj : format-perl-bracket.c
- $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c format-perl-bracket.c
+format-perl-brace.obj : format-perl-brace.c
+ $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c format-perl-brace.c
format-php.obj : format-php.c
$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c format-php.c
format-ycp.obj, \
format-tcl.obj, \
format-perl.obj, \
- format-perl-bracket.obj, \
+ format-perl-brace.obj, \
format-php.obj
msgcmp_OBJECTS = msgcmp.obj
format-perl.obj : format-perl.c
$(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) format-perl.c
-format-perl-bracket.obj : format-perl-bracket.c
- $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) format-perl-bracket.c
+format-perl-brace.obj : format-perl-brace.c
+ $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) format-perl-brace.c
format-php.obj : format-php.c
$(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) format-php.c
-/* Perl bracketed format strings.
+/* Perl brace format strings.
Copyright (C) 2003 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
#define _(str) gettext (str)
-/* Perl bracketed format strings are supported by Guido Flohr's libintl-perl
+/* Perl brace format strings are supported by Guido Flohr's libintl-perl
package, more precisely by the __expand and __x functions therein.
A format string directive here consists of
- - an opening bracket '[',
+ - an opening brace '{',
- an identifier [_A-Za-z][_0-9A-Za-z]*,
- - a closing bracket ']'.
+ - a closing brace '}'.
*/
struct named_arg
spec.named = NULL;
for (; *format != '\0';)
- if (*format++ == '[')
+ if (*format++ == '{')
{
const char *f = format;
char c;
c = *++f;
while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '_'
|| (c >= '0' && c <= '9'));
- if (c == ']')
+ if (c == '}')
{
/* A directive. */
char *name;
/* Check the argument names in spec1 are contained in those of spec2.
Additional arguments in spec2 are allowed; they expand to themselves
- (including the surrounding brackets) at runtime.
+ (including the surrounding braces) at runtime.
Both arrays are sorted. We search for the differences. */
for (i = 0, j = 0; i < n1 || j < n2; )
{
}
-struct formatstring_parser formatstring_perl_bracket =
+struct formatstring_parser formatstring_perl_brace =
{
format_parse,
format_free,
/*
* For Emacs M-x compile
* Local Variables:
- * compile-command: "/bin/sh ../libtool --mode=link gcc -o a.out -static -O -g -Wall -I.. -I../lib -I../intl -DHAVE_CONFIG_H -DTEST format-perl-bracket.c ../lib/libgettextlib.la"
+ * compile-command: "/bin/sh ../libtool --mode=link gcc -o a.out -static -O -g -Wall -I.. -I../lib -I../intl -DHAVE_CONFIG_H -DTEST format-perl-brace.c ../lib/libgettextlib.la"
* End:
*/
/* format_ycp */ &formatstring_ycp,
/* format_tcl */ &formatstring_tcl,
/* format_perl */ &formatstring_perl,
- /* format_perl_bracket */ &formatstring_perl_bracket,
+ /* format_perl_brace */ &formatstring_perl_brace,
/* format_php */ &formatstring_php
};
extern struct formatstring_parser formatstring_ycp;
extern struct formatstring_parser formatstring_tcl;
extern struct formatstring_parser formatstring_perl;
-extern struct formatstring_parser formatstring_perl_bracket;
+extern struct formatstring_parser formatstring_perl_brace;
extern struct formatstring_parser formatstring_php;
/* Table of all format string parsers. */
/* format_ycp */ "ycp",
/* format_tcl */ "tcl",
/* format_perl */ "perl",
- /* format_perl_bracket */ "perl-bracket",
+ /* format_perl_brace */ "perl-brace",
/* format_php */ "php"
};
/* format_ycp */ "YCP",
/* format_tcl */ "Tcl",
/* format_perl */ "Perl",
- /* format_perl_bracket */ "Perl bracket",
+ /* format_perl_brace */ "Perl brace",
/* format_php */ "PHP"
};
format_ycp,
format_tcl,
format_perl,
- format_perl_bracket,
+ format_perl_brace,
format_php
};
#define NFORMATS 14 /* Number of format_type enum values. */
{ "cgi", "perl" }, \
#define SCANNERS_PERL \
- { "perl", extract_perl, &formatstring_perl, &formatstring_perl_bracket }, \
+ { "perl", extract_perl, &formatstring_perl, &formatstring_perl_brace }, \
/* Scan a Perl file and add its translatable strings to mdlp. */
extern void extract_perl (FILE *fp, const char *real_filename,
+2003-07-05 Bruno Haible <bruno@clisp.org>
+
+ * format-perl-brace-1: Renamed from format-perl-bracket-1. Use braces
+ instead of brackets.
+ * format-perl-brace-2: Renamed from format-perl-bracket-2. Use braces
+ instead of brackets.
+ * format-perl-mixed-1: Use braces instead of brackets.
+ * format-perl-mixed-2: Likewise.
+ * xgettext-26: Likewise.
+ * lang-perl-2: Likewise.
+ * Makefile.am (TESTS): Add format-perl-brace-[12], remove
+ format-perl-bracket-[12].
+
2003-06-27 Bruno Haible <bruno@clisp.org>
* xgettext-27: Also test Unicode character names in here documents.
format-python-1 format-python-2 \
format-pascal-1 format-pascal-2 \
format-perl-1 format-perl-2 \
- format-perl-bracket-1 format-perl-bracket-2 \
+ format-perl-brace-1 format-perl-brace-2 \
format-perl-mixed-1 format-perl-mixed-2 \
format-tcl-1 format-tcl-2 \
format-ycp-1 format-ycp-2 \
#! /bin/sh
-# Test recognition of Perl bracket format strings.
+# Test recognition of Perl brace format strings.
tmpfiles=""
trap 'rm -fr $tmpfiles' 1 2 3 15
# Invalid: no argument
"abc"
# Valid: a named argument
-"abc[value]"
+"abc{value}"
# Invalid: an empty name
-"abc[]"
+"abc{}"
# Invalid: unterminated name
-"abc[value"
+"abc{value"
# Valid: three arguments, two with equal names
-"abc[addr],[char],[addr]"
+"abc{addr},{char},{addr}"
# Invalid: place-holder contains a space.
-"[foo bar]"
+"{foo bar}"
# Invalid: missing right angle bracket.
-"[foo bar"
+"{foo bar"
# Valid: not nested, but one single place-holder.
-"[foo[bar]baz]"
+"{foo{bar}baz}"
# Valid: no nesting error, but one single place-holder.
-"[foo[bar]baz"
+"{foo{bar}baz"
# Valid: place-holder with spaces must be ignored, but still one remaining.
-"[foo bar] [baz]"
+"{foo bar} {baz}"
# Invalid: percent sign not allowed.
-"[foo%bar]"
+"{foo%bar}"
EOF
: ${XGETTEXT=xgettext}
fail=yes
fi
else
- if grep perl-bracket-format f-pb-1-$n.po > /dev/null; then
+ if grep perl-brace-format f-pb-1-$n.po > /dev/null; then
fail=yes
else
:
#! /bin/sh
-# Test checking of Perl bracket format strings.
+# Test checking of Perl brace format strings.
tmpfiles=""
trap 'rm -fr $tmpfiles' 1 2 3 15
tmpfiles="$tmpfiles f-pb-2.data"
cat <<\EOF > f-pb-2.data
# Valid: same named arguments
-msgid "abc[date][time]"
-msgstr "xyz[date][time]"
+msgid "abc{date}{time}"
+msgstr "xyz{date}{time}"
# Valid: permutation
-msgid "abc[x3][x1][x2]def"
-msgstr "xyz[x2][x1][x3]"
+msgid "abc{x3}{x1}{x2}def"
+msgstr "xyz{x2}{x1}{x3}"
# Invalid: missing argument
-msgid "abc[x2]def[x1]"
-msgstr "xyz[x1]"
+msgid "abc{x2}def{x1}"
+msgstr "xyz{x1}"
# Invalid: missing argument
-msgid "abc[x1]def[x2]"
-msgstr "xyz[x2]"
-# Valid: added argument (valid since "[zoo]" expands to itself)
-msgid "abc[foo]def"
-msgstr "xyz[foo]uvw[zoo]"
+msgid "abc{x1}def{x2}"
+msgstr "xyz{x2}"
+# Valid: added argument (valid since "{zoo}" expands to itself)
+msgid "abc{foo}def"
+msgstr "xyz{foo}uvw{zoo}"
# Valid: multiple reuse of same argument
-msgid "[foo] [bar] [baz]"
-msgstr "[baz] [bar] [foo] [bar]"
+msgid "{foo} {bar} {baz}"
+msgstr "{baz} {bar} {foo} {bar}"
# Valid: single reuse of same argument
-msgid "[baz] [bar] [foo] [bar]"
-msgstr "[foo] [bar] [baz]"
+msgid "{baz} {bar} {foo} {bar}"
+msgstr "{foo} {bar} {baz}"
EOF
: ${MSGFMT=msgfmt}
n=`expr $n + 1`
tmpfiles="$tmpfiles f-pb-2-$n.po f-pb-2-$n.mo"
cat <<EOF > f-pb-2-$n.po
-#, perl-bracket-format
+#, perl-brace-format
${msgid_line}
${msgstr_line}
EOF
#! /bin/sh
-# Test recognition of Perl format strings of both kinds (printf and bracketed).
+# Test recognition of Perl format strings of both kinds (printf and brace).
# This test is for the combination of both kinds.
tmpfiles=""
cat <<\EOF > f-pm-1.data
# Both formats.
-#, perl-format, perl-bracket-format
-"[foo] %c [bar] %d [baz]"
+#, perl-format, perl-brace-format
+"{foo} %c {bar} %d {baz}"
# printf format only.
#, perl-format
"%c %d"
# printf format only, because '%' is not allowed in identifier.
#, perl-format
-"[foo%cbar]"
+"{foo%cbar}"
# Valid bracketed format because there is still one valid identifier.
-#, perl-format, perl-bracket-format
-"[foo%cbar] [baz]"
+#, perl-format, perl-brace-format
+"{foo%cbar} {baz}"
# Bracketed format only, because %l is not recognized in printf format.
-#, perl-bracket-format
-"[foo] %l [bar]"
+#, perl-brace-format
+"{foo} %l {bar}"
# Neither format recognized here.
-"[foo bar %l"
+"{foo bar %l"
EOF
: ${XGETTEXT=xgettext}
#! /bin/sh
# Test checking of Perl format strings.
-# This test is for the combination of printf and bracketed format strings.
+# This test is for the combination of printf and brace format strings.
tmpfiles=""
trap 'rm -fr $tmpfiles' 1 2 3 15
tmpfiles="$tmpfiles f-pm-2.data"
cat <<\EOF > f-pm-2.data
# Valid: normal case.
-#, perl-format, perl-bracket-format
-msgid "[foo] %d [bar] %s"
-msgstr "[bar] [foo] %d %s"
+#, perl-format, perl-brace-format
+msgid "{foo} %d {bar} %s"
+msgstr "{bar} {foo} %d %s"
# Invalid: missing argument.
-#, perl-format, perl-bracket-format
-msgid "[foo] %d [bar] %s"
-msgstr "[bar] %d %s"
+#, perl-format, perl-brace-format
+msgid "{foo} %d {bar} %s"
+msgstr "{bar} %d %s"
# Valid: missing argument but checking disabled.
-#, perl-format, no-perl-bracket-format
-msgid "[foo] %d [bar] %s"
-msgstr "[bar] %d %s"
+#, perl-format, no-perl-brace-format
+msgid "{foo} %d {bar} %s"
+msgstr "{bar} %d %s"
# Invalid: printf format reordered without position specifiers %1$, %2$.
-#, perl-format, perl-bracket-format
-msgid "[foo] %d [bar] %s"
-msgstr "[bar] %s [foo] %d"
+#, perl-format, perl-brace-format
+msgid "{foo} %d {bar} %s"
+msgstr "{bar} %s {foo} %d"
# Valid: same thing but checking disabled.
-#, no-perl-format, perl-bracket-format
-msgid "[foo] %d [bar] %s"
-msgstr "[bar] %s [foo] %d"
+#, no-perl-format, perl-brace-format
+msgid "{foo} %d {bar} %s"
+msgstr "{bar} %s {foo} %d"
# Invalid: unnamed vs. named arguments
#, perl-format
msgid "abc%sdef"
-msgstr "xyz[value]"
+msgstr "xyz{value}"
# Invalid: named vs. unnamed arguments
-#, perl-bracket-format
-msgid "abc[value]def"
+#, perl-brace-format
+msgid "abc{value}def"
msgstr "xyz%s"
EOF
#! /bin/sh
# Test of gettext facilities in the Perl language,
-# using bracket format strings.
+# using brace format strings.
# Assumes an fr_FR locale is installed.
# Assumes the following packages are installed: perl, libintl-perl.
print "\n"
printf __n ("a piece of cake", "%d pieces of cake", $n), $n;
print "\n"
-printf __x ("[old] is replaced by [new].", old => "FF", new => "EUR");
+printf __x ("{old} is replaced by {new}.", old => "FF", new => "EUR");
print "\n"
EOF
msgstr[0] ""
msgstr[1] ""
-#, perl-bracket-format
-msgid "[old] is replaced by [new]."
+#, perl-brace-format
+msgid "{old} is replaced by {new}."
msgstr ""
EOF
msgstr[1] "%d morceaux de gateau"
# Reverse the arguments.
-#, perl-bracket-format
-msgid "[old] is replaced by [new]."
-msgstr "[new] remplace [old]."
+#, perl-brace-format
+msgid "{old} is replaced by {new}."
+msgstr "{new} remplace {old}."
EOF
tmpfiles="$tmpfiles fr.po.new"
printf "%s\n", gettext qq(mari\\\\\huana);
# Recognition of format strings.
-gettext "This is [only] a bracketed formatstring.";
-gettext "This is %s [mixed].";
+gettext "This is {only} a brace formatstring.";
+gettext "This is %s {mixed}.";
gettext "This is only %c.";
gettext "This is nothing at all.";
gettext "And this is %l also no format at all.";
-# xgettext: no-perl-format, perl-bracket-format
-gettext "The function '[func]' expects '%c' here.";
+# xgettext: no-perl-format, perl-brace-format
+gettext "The function '{func}' expects '%c' here.";
# This is a contradictory case: The same string three times,
# with different xgettext comments.
-# xgettext: perl-bracket-format, no-perl-format
-gettext "Left as an %exercise to [maintainer].";
-# xgettext: no-perl-bracket-format, perl-format
-gettext "Left as an %exercise to [maintainer].";
+# xgettext: perl-brace-format, no-perl-format
+gettext "Left as an %exercise to {maintainer}.";
+# xgettext: no-perl-brace-format, perl-format
+gettext "Left as an %exercise to {maintainer}.";
# No xgettext comment this time.
-gettext "Left as an %exercise to [maintainer].";
+gettext "Left as an %exercise to {maintainer}.";
__END__
gettext "Discarded!";
EOF
msgstr ""
#: xg-test26.pl:102
-#, perl-bracket-format
-msgid "This is [only] a bracketed formatstring."
+#, perl-brace-format
+msgid "This is {only} a brace formatstring."
msgstr ""
#: xg-test26.pl:103
-#, perl-format, perl-bracket-format
-msgid "This is %s [mixed]."
+#, perl-format, perl-brace-format
+msgid "This is %s {mixed}."
msgstr ""
#: xg-test26.pl:104
msgstr ""
#: xg-test26.pl:109
-#, no-perl-format, perl-bracket-format
-msgid "The function '[func]' expects '%c' here."
+#, no-perl-format, perl-brace-format
+msgid "The function '{func}' expects '%c' here."
msgstr ""
#: xg-test26.pl:114 xg-test26.pl:116 xg-test26.pl:118
-#, perl-format, no-perl-bracket-format
-msgid "Left as an %exercise to [maintainer]."
+#, perl-format, no-perl-brace-format
+msgid "Left as an %exercise to {maintainer}."
msgstr ""
EOF