Re: Re: Console_CommandLine messages XML

From: Date: Fri, 19 Jun 2009 07:10:07 +0000
Subject: Re: Re: Console_CommandLine messages XML
References: 1 2 3  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-51995@lists.php.net to get a copy of this message
Christian Weiske a écrit :
Hi David and Michael,
<message name="ARGUMENT_REQUIRED">You must provide at least {$argnum} argument{$plural}.</message>
Here you expect all languages to follow the same plurality rules as English - an 's' or whatever character somewhere as extension to an existing word. In German, some words are completely different in singular and plural - you'd have to replace the whole word, not only an extension. Something alike ngettext() does it better.
Hi Christian, You are absolutely right, but in this case the code handling the "plural" stuff belongs to the default (english only) message-provider. So, if you were to write a german, or better, a multilingual gettext message provider you would do something like: <?php class GettextMessageProvider implements Console_CommandLine MessageProvider {
    public function get($message, $vars)
    {
        switch ($message) {
        case 'ARGUMENT_REQUIRED':
            return ngettext(
                'You must provide at least %d argument',
                'You must provide %d arguments',
                (int)$vars['argnum'}
            );
         case 'OPTION_VALUE_REQUIRED':
             return sprintf(
                 _('Option "%s" requires a value'),
                 $vars['name']
             );
         // other cases etc...
         }
    }
} ?> This would be fully gettext compliant and xgettext friendly. -- David

« previous php.pear.dev (#51995) next »