[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Handling qt-format in gettext tools (was: Updating qt-format handlin
From: |
Bruno Haible |
Subject: |
Re: Handling qt-format in gettext tools (was: Updating qt-format handling?) |
Date: |
Tue, 4 Sep 2007 11:57:04 +0200 |
User-agent: |
KMail/1.5.4 |
Chusslove Illich wrote on 2007-04-19 and 2007-07-11
<http://lists.gnu.org/archive/html/bug-gnu-utils/2007-07/msg00030.html>:
> The messages with placeholders (format strings) in KDE4 are going to be
> proper qt-format (to the point of its own well-definedness), so we'd like
> to have the POs pass msgfmt -c in the future.
>
> However, qt-format specs in Gettext are a bit outdated, probably due to its
> low usage (KDE didn't use it before, and there is also the native
> QtLinguist format for pure Qt apps).
>
> The current specifications for placeholder replacement in QString are given
> here:
>
> http://doc.trolltech.com/4.3/qstring.html#arg
> http://doc.trolltech.com/4.3/qstring.html#arg-2
>
> As I read (and tested), it is that:
>
> 1. The limit on placeholder numbers are no longer 1-9, but 1-99.
>
> 2. There is no special requirement on all placeholders being unique.
> Equal-numbered placeholders are allowed, and will be substituted with the
> same argument.
>
> Points 1 and 2 are there to amend the following assertion by the Gettext
> manual:
>
> "...a directive consists of a `%' followed by a digit. The same directive
> cannot occur more than once in a format string."
The written specification is not enough. You also need to look into the
source code. As far as I can see, the initial comment in format-qt.c needs
to be changed as follows:
***************
*** 31,44 ****
#define _(str) gettext (str)
/* Qt format strings are processed by QString::arg and are documented in
! qt-3.0.5/doc/html/qstring.html.
! A directive starts with '%' and is followed by a digit ('0' to '9').
! Each %n must occur only once in the given string.
The first .arg() invocation replaces the %n with the lowest numbered n,
the next .arg() invocation then replaces the %n with the second-lowest
numbered n, and so on.
! (This is inherently buggy because a '%' in the first replacement confuses
! the second .arg() invocation.)
Although %0 is supported, usually %1 denotes the first argument, %2 the
second argument etc. */
--- 31,51 ----
#define _(str) gettext (str)
/* Qt format strings are processed by QString::arg and are documented in
! qt-4.3.0/doc/html/qstring.html.
! A directive
! - starts with '%',
! - is optionally followed by 'L' (indicates locale-dependent processing),
! - is followed by one or two digits ('0' to '9'). %0n is equivalent to %n.
! An unterminated directive ('%' or '%L' at the end) is not an error.
The first .arg() invocation replaces the %n with the lowest numbered n,
the next .arg() invocation then replaces the %n with the second-lowest
numbered n, and so on.
! This is inherently buggy because a '%' in the first replacement confuses
! the second .arg() invocation.
! To reduce this problem and introduce another one, there are also .arg()
! methods that take up to 9 strings and perform the replacements in one
swoop.
! But this method works only on strings that contain no 'L' flags and only
! single-digit argument designators.
Although %0 is supported, usually %1 denotes the first argument, %2 the
second argument etc. */
So, effectively we have two kinds of Qt format strings: those that contain
no 'L' flags and only single-digit argument designators, and those that have
'L' flags or two-digit argument designators. The translator must not give a
translation of the second kind for an msgid of the first kind.
Maybe it can still be handled through a single 'format-qt' attribute,
through the format_check function?
> And now suggestions for some heuristics:
>
> 3. Since same-numbered placeholders represent same piece of data, I would
> not insist on strict congruence between the number of same-numbered
> placeholders in msgid and msgstr. It may be that the msgid uses %1 twice
> due to sentence structure, whereas the translation can get away with a
> single %1 and a pronoun -- or vice versa. It is enough if each placeholder
> number from msgid exists in msgstr at least once.
Yes, I agree. Qt3 had a limitation "Each %n must occur only once in the
given string." Qt4 does not have this limitation any more.
> 4. How about letting qt-format use the same heuristic for plural messages
> as the c-format? Eg. not having to mention the placeholder in msgstr[x],
> if [x] is used only for the case strictly n==1 (I'm not sure what the full
> heuristic here is, but since noone complains for the c-format itself...)
Yes, this sounds good. The 'equality' parameter to format_check contains the
information whether to do strict checking, or loose checking for the case
you mention.
> If not too time-intensive, could the maintainer himself make these changes
> for the next release? *looks at Bruno with puppy eyes*
As you can see, I haven't found the time to do these changes in 4 months.
I would appreciate a patch that takes into account the finding for 1. + 2.
mentioned above.
Bruno
- Re: Handling qt-format in gettext tools (was: Updating qt-format handling?),
Bruno Haible <=
- Re: [Translation-i18n] Handling qt-format in gettext tools (was: Updating qt-format handling?), Chusslove Illich, 2007/09/04
- Re: [Translation-i18n] Handling qt-format in gettext tools (was: Updating qt-format handling?), Bruno Haible, 2007/09/09
- Re: [Translation-i18n] Handling qt-format in gettext tools (was: Updating qt-format handling?), Chusslove Illich, 2007/09/10
- Re: [Translation-i18n] Handling qt-format in gettext tools (was: Updating qt-format handling?), Bruno Haible, 2007/09/10
- Re: [Translation-i18n] Handling qt-format in gettext tools (was: Updating qt-format handling?), Chusslove Illich, 2007/09/10
- Re: [Translation-i18n] Handling qt-format in gettext tools (was: Updating qt-format handling?), Bruno Haible, 2007/09/10
- Re: [Translation-i18n] Handling qt-format in gettext tools (was: Updating qt-format handling?), Chusslove Illich, 2007/09/11