[Davical-dev] Internationalisation-Patch

Andrew McMillan andrew at morphoss.com
Tue Oct 27 22:09:00 NZDT 2009


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>


More information about the Davical-dev mailing list