Mailing List Archive

Internationalisation-Patch
Hi,

> Another possibility would be to distinguish between format strings and
> parameters and store them separately in a multi dimensional array
> Like follows:
> $c->messages[] = array( 'format' -> i18n("text with params %s, %s"),
> 'params' -> array( $param1, $param2 ) );
> After that you could send the format string through the translate
> function
> and put the whole string together afterwards...
I now created a patch to awl-0.38 (only User.php) and DAViCal-0.9.7.6 which
does the above for all places where the given format string contains parameters.
The output of that strings is in page-header.php; therefore I modified that
place to respects such message arrays which split format and parameters and
only translate the format strings (and put it together with its parameters
afterwards).

The patch also removes all unnecessary sprintf where no parameters are given...

One additional note:
I suggest, that all format strings with parameters which shall be translated
should change the format, so that it's possible to change the order of the
parameters in a translation (e.g. flip two parameters).
In PHP this works as follows:
instead of a format string
'host=%s, user=%s, something else %s, %d'
you'll write
'host=%1$s, user=%2$s, something else %3$s, %4$d'
then you could write as translated string e.g.
'Benutzer=%2$s, Rechner=%1$s, %4$d was anderes %3$s'
and therefore change the order of the parameter values for different languages...
Regarding the PHP manual this works since PHP 4.06; though I'm not sure if it
works with gettext...
I didn't add this to the patches because it would change all existring strings
with parameters --> they would have been translated again for all languages.

Maybe it would be a good time to change it for 0.9.8 where a lot strings
changes anyway?

regards,
Matthias

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: davical-0.9.7.6_internationalisation.diff
URL: <http://lists.morphoss.com/pipermail/davical-dev/attachments/20091026/7106c859/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: awl-0.38_internationalisation.diff
URL: <http://lists.morphoss.com/pipermail/davical-dev/attachments/20091026/7106c859/attachment.asc>
Internationalisation-Patch [ In reply to ]
On Mon, 2009-10-26 at 13:38 +0100, Matthias Mohr wrote:
> Hi,
>
> > Another possibility would be to distinguish between format strings and
> > parameters and store them separately in a multi dimensional array
> > Like follows:
> > $c->messages[] = array( 'format' -> i18n("text with params %s, %s"),
> > 'params' -> array( $param1, $param2 ) );
> > After that you could send the format string through the translate
> > function
> > and put the whole string together afterwards...
> I now created a patch to awl-0.38 (only User.php) and DAViCal-0.9.7.6 which
> does the above for all places where the given format string contains parameters.
> The output of that strings is in page-header.php; therefore I modified that
> place to respects such message arrays which split format and parameters and
> only translate the format strings (and put it together with its parameters
> afterwards).

I won't apply this at present, because I think it needs a bit more
thought. Possibly this is a reasonable approach within the gettext
framework (although see my link below, and my earlier e-mail...) but if
so then we can perhaps we could design an object to encapsulate it.


> The patch also removes all unnecessary sprintf where no parameters are given...

I'd happily apply a patch covering just that :-)


> One additional note:
> I suggest, that all format strings with parameters which shall be translated
> should change the format, so that it's possible to change the order of the
> parameters in a translation (e.g. flip two parameters).
> In PHP this works as follows:
> instead of a format string
> 'host=%s, user=%s, something else %s, %d'
> you'll write
> 'host=%1$s, user=%2$s, something else %3$s, %4$d'
> then you could write as translated string e.g.
> 'Benutzer=%2$s, Rechner=%1$s, %4$d was anderes %3$s'
> and therefore change the order of the parameter values for different languages...
> Regarding the PHP manual this works since PHP 4.06; though I'm not sure if it
> works with gettext...
> I didn't add this to the patches because it would change all existring strings
> with parameters --> they would have been translated again for all languages.

Yeah, indeed. Though gettext does do some fuzzy matching on things, so
they might not all be completely lost


> Maybe it would be a good time to change it for 0.9.8 where a lot strings
> changes anyway?

I'd be happier to make changes like this when I'm not making
functionality changes at the same time. So maybe after 0.9.8 is
released I can start accepting patches like this. For now, perhaps read
up some further on the capabilities of gettext in this regard:

http://www.gnu.org/software/hello/manual/gettext/Plural-forms.html


Cheers,
Andrew.

------------------------------------------------------------------------
andrew (AT) morphoss (DOT) com +64(272)DEBIAN
Familiarity breeds contempt -- and children.
-- Mark Twain

------------------------------------------------------------------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.morphoss.com/pipermail/davical-dev/attachments/20091027/4d20697f/attachment.pgp>
Internationalisation-Patch [ In reply to ]
Hi Andrew,

>> The patch also removes all unnecessary sprintf where no parameters are given...
>
> I'd happily apply a patch covering just that :-)
Attached are simpler patches, which don't add the array functionality
to $c->messages assignments (and output).
- It fixes some message assignment in libawl (assignments made to the non
existing $client_messages array instead of $c->messages).
- removes all unnecessary sprintf where no parameters are given...
- adds some calls to "i18n" where they were missing.
- changes some calls from "translate" to "i18n" in assignments to
$c->messages where no parameters are given
(this messages will be translated later in page-header.php)
- changes some calls from "i18n" to "translate" in assignments to
$c->messages where paramters are given
This is the unclean solution of the original patch; just to make sure,
the format strings get translated before they'll combined with the
variable contents
(unclean, because the strings will be sent twice through "translate":
first as "format string" and a second time when alredy translated and
after replacment of the variables with their contents...)

The patches are pretty small, so I think it's O.K. to combine the above things
in only two patches...

kind regards,
Matthias
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: awl-0.38_internationalisation_simpler.diff
URL: <http://lists.morphoss.com/pipermail/davical-dev/attachments/20091029/b57fff7f/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: davical-0.9.7.6_internationalisation_simpler.diff
URL: <http://lists.morphoss.com/pipermail/davical-dev/attachments/20091029/b57fff7f/attachment.asc>
Internationalisation-Patch [ In reply to ]
On Thu, 2009-10-29 at 13:43 +0100, Matthias Mohr wrote:
> Hi Andrew,
>
> >> The patch also removes all unnecessary sprintf where no parameters are given...
> >
> > I'd happily apply a patch covering just that :-)
> Attached are simpler patches, which don't add the array functionality
> to $c->messages assignments (and output).

Both are applied to HEAD now.


> - It fixes some message assignment in libawl (assignments made to the non
> existing $client_messages array instead of $c->messages).

A holdover from some other older applications which use AWL. Hopefully
everything that uses AWL has been switched to $c->messages now.


> - changes some calls from "i18n" to "translate" in assignments to
> $c->messages where paramters are given
> This is the unclean solution of the original patch; just to make sure,
> the format strings get translated before they'll combined with the
> variable contents
> (unclean, because the strings will be sent twice through "translate":
> first as "format string" and a second time when alredy translated and
> after replacment of the variables with their contents...)

Given the content of the strings is error messages, such as ones sourced
from PostgreSQL, I don't think there is a better way for much of it.


> The patches are pretty small, so I think it's O.K. to combine the above things
> in only two patches...

Yep. There was only one reject when applying this to HEAD, and it was
easily resolved.

Patches with a small consistent change to many files, or a larger
consistent change to few files are both OK. The first kind will *look*
larger, of course, due to the amount of context in the patch.

Cheers,
Andrew.

------------------------------------------------------------------------
andrew (AT) morphoss (DOT) com +64(272)DEBIAN
You are taking yourself far too seriously.
------------------------------------------------------------------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.morphoss.com/pipermail/davical-dev/attachments/20091030/e479d484/attachment.pgp>