On 23 oct, 18:39, Mike Orr <[email protected]> wrote:
> On Fri, Oct 23, 2009 at 1:05 PM, Marius Gedminas <[email protected]> wrote:
> > On Fri, Oct 23, 2009 at 12:41:48PM -0700, Mariano Mara wrote:
> >> Hi,
> >> I have this mako template where I want to print a message but part of
> >> it depends on a certain variable that I will get from the controller.
> >> E.g.:
> >> ${_(u'No tickets were found in the last n days')}
> >> where "n" comes from the variable c.lastNdays in the controller.
>
> > You probably want ngettext instead of _ then. How to hook it up with
> > everything is left as an excercise for the reader.
>
> >> How can I place it correctly in the template?
> >> I'm using
> >> ${_(u'No tickets were found in the last ')}${c.lastNdays} ${_
> >> (u'days')}
> >> but I'm sure there should be a better way to have a proper
> >> translatable string, like:
> >> ${_(u'No tickets were found in the last %(num)d days') %
> >> {'num':c.lastNdays}}
> >> although this last one raises an error in the template.
>
> > I'm guessing it's because the expression gets terminated at the first }?
>
> Yeah, it looks like Mako can't handle dict literals in placeholders.
> This template fails too:
>
> ===
> Hello, world!
> <br />
> ${{"A": 1, "B": 2}["A"]}
> ===
>
> However, a Python escape works fine;
>
> ===
> Hello, world!
> <br />
> <% dic = {"A": 1, "B": 2} %>
> ${dic["A"]}
> ===
>
> > I'd go with dict(num=c.lastNdays) instead of {'num':c.lastNdays} (also,
> > missing space after ':' hurts my eyes).
>
> Down with dict()! It reminds me of array() in PHP.
>
> --
> Mike Orr <[email protected]>
Thank you very much Marius and Mike for your help. I finally used the
python escape and seems to be working ok.
Mariano.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---