text=T("you have 1 dog") if x==1 else T("you have %s dogs",x)

Massimo


On Dec 10, 8:31 am, achipa <[EMAIL PROTECTED]> wrote:
> OK, this answers the (a) of my post (I could have sworn I tried that
> too, oh well), but how would you do (b) ? x=%.2f just outputs the
> number, but doesn't interpret it with regard to translation. T("%d
> files copied", numcopy) should return '1 file copied' if numcopy is 1,
> and '[numcopy] fileS copied' if numcopy is > 1 (or zero !).
>
> On Dec 10, 3:25 pm, mdipierro <[EMAIL PROTECTED]> wrote:
>
> > You can do all that. Here are some examples:
>
> >     name="Achipa"
> >     T("Hello %s",name)
> >     T("Hello %(name)s",dict(name=name))
> >      x=0.123515
> >     T("x=%.2f",x)
>
> > Massimo
>
> > On Dec 10, 4:40 am, achipa <[EMAIL PROTECTED]> wrote:
>
> > > I know we T() for this, but there are some shortcoming. As I'm dealing
> > > with more languages than it's probably healthy, the T() approach seems
> > > to have significant drawbacks compared to good (?) old gettext. I want
> > > to see whether some solutions already exist that I don't know about,
> > > or we need to do something about this to accomodate.
>
> > > a) string arguments. I tried something along the lines of T('User %s
> > > not available') % username, but that's a no go (TypeError: unsupported
> > > operand type(s) for %: 'lazyT' and 'str'). Obviously If I do the
> > > replacement within T, I cannot translate the string. I know I could
> > > rearrange the text so the parameter comes up on the beginning or the
> > > end of the string, but I'm talking concepts here. Preferably, this
> > > should work with dict arguments to be able to preserve word ordering
> > > and make translations easier. (think '%(obj)s not found in %(loc)s',
> > > some languages will have the parameters reversed). T('text with
> > > parameters', mydict) would be also ok.
>
> > > b) numerical parameters. It gets even more complex here. Unfortunately
> > > some words change shape depending on argument value (in english, this
> > > would be the plural 's' on the end). Some languages don't have this
> > > (like hungarian), others have a more complex scheme (like russian with
> > > 3 plurals). Gettext gets around this by having a ngettext, which takes
> > > a parameter, like ngettext('% files copied', n) which returns the
> > > string for the particular argument value. This is regulated through a
> > > header (an example for aforementioned russian):
>
> > >  Plural-Forms: nplurals=3; \
> > >               plural=n%10==1 && n%100!=11 ? 0 : \
> > >                      n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ?
> > > 1 : 2;
>
> > > For this functionality we probably we either need to change how T()
> > > works, or make a two-parameter NT() and have a special dict for that
> > > (just a mockup idea, the selector could of course be a separate dict
> > > in itself):
> > > {
> > >   '%s kralj_selector' : logical-expression-similar-to-the-example-
> > > above
> > >   '%s kralj' : ('%s kralj', '%s kralja', '%s kraljeva')
>
> > > }
>
> > > I'd like to keep the logic as close to that of gettext's to able to
> > > make a convertes as there are thousands of gettext editors translators
> > > are familiar with, it would be a shame to use a scheme which could not
> > > be converted back and forth.
>
> > > Thoughts, comments ?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to