Re: [Checkins] SVN: zope.i18n/branches/regebro-pluralsupport/src/zope/i18n/ Changed the API. It's unwieldy as it is, so better have separate methods
On Wed, Jul 16, 2008 at 20:22, Stephan Richter <srichter@cosmos.phy.tufts.edu> wrote:
On Wednesday 16 July 2008, Lennart Regebro wrote:
Log message for revision 88417: Changed the API. It's unwieldy as it is, so better have separate method for plurals.
It looks to me as if you only support one singular and one plural form.
Nope. Although I currently only test that case.
I have read some commentary a long time ago, that some languages, like Polish, have multiple plural forms. Is that supported?
Should be, but it's not tested yet. While talking about this, what would a ZPT implementation of this best look like? An i18n:count statement that takes expressions? <p i18n:translate="" i18n:count="view/file_count">There are %d files</p> Or? -- Lennart Regebro: Zope and Plone consulting. http://www.colliberty.com/ +33 661 58 14 64
On Wednesday 16 July 2008, Lennart Regebro wrote:
While talking about this, what would a ZPT implementation of this best look like? An i18n:count statement that takes expressions?
<p i18n:translate="" i18n:count="view/file_count">There are %d files</p>
Or?
Good question! The ZPT above is not correct; once we write a correct one, it becomes more obvious: <p i18n:translate="">There are <span tal:content="view/num" i18n:name="num" i18n:count="view/num>10</span> files.</p> Alternatively we could just evaluate the tal:content or tal:replace expression. Regards, Stephan -- Stephan Richter Web Software Design, Development and Training Google me. "Zope Stephan Richter"
Hi. It's awesome to see some progress on this. You are aware of the Gettext manual at http://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms right? Stephan Richter wrote:
On Wednesday 16 July 2008, Lennart Regebro wrote:
While talking about this, what would a ZPT implementation of this best look like? An i18n:count statement that takes expressions?
<p i18n:translate="" i18n:count="view/file_count">There are %d files</p>
Or?
Good question! The ZPT above is not correct; once we write a correct one, it becomes more obvious:
<p i18n:translate="">There are <span tal:content="view/num" i18n:name="num" i18n:count="view/num">10</span> files.</p>
Alternatively we could just evaluate the tal:content or tal:replace expression.
So here's a set of additional use-cases: <p i18n:translate=""> You selected the book called <span tal:content="title" i18n:name="title">Python for dummies</span>. </p> In this case, the i18n:name shouldn't be treated as a number, so I think we need an explicit statement like i18n:count to signal this. We could have the i18n:count default to taking the expression if it is empty. <p i18n:translate=""> You have to pay <span tal:content="view/formatted_amount" i18n:name="amount" i18n:count="view/amount">6 dollars</span>. </p> In this case the underlying value is a simple integer, but the actual presentation might be locale dependent, like currency formatting. <p i18n:translate=""> You selected <span tal:content="num" i18n:name="num">5</span> out of <span tal:content="total" i18n:name="total">10</span> files. </p> I'm not sure what to do with this actually. How does multiple numbers in the same sentence are handled? I think this is just not allowed and should cause a syntax error, as there's no general way to translate those sentences with Gettext. Or does it result in a n-dimensional matrix? <br i18n:attributes=""> You selected <span tal:content="num" i18n:name="num">5</span> out of <span tal:content="total" i18n:name="total">10</span> files. </p> Can someone think about an example involving i18n:attributes? In TAL I cannot construct a dynamic one it seems. How does this behave in regard to zope.i18nmessageid? from zope.i18nmessageid import MessageFactory _ = MessageFactory('domain') mapping=dict(num=10) foo = _(u'There are ${num} files.', mapping=mapping) mapping=dict(num=10, name='/foo/bar') foo = _(u'There are ${num} files in the folder named ${name}.', mapping=mapping) So I think we need to signal to the messageid which variable in the mapping is significant for the i18n count, right? Hanno
Sorry. There's some garbage in my last message. Disregard the following bits. Hanno Schlichting wrote:
<br i18n:attributes=""> You selected <span tal:content="num" i18n:name="num">5</span> out of <span tal:content="total" i18n:name="total">10</span> files. </p>
Can someone think about an example involving i18n:attributes? In TAL I cannot construct a dynamic one it seems.
Hanno P.S. There isn't someone working on msgctxt support, is there ;)
On Wed, Jul 16, 2008 at 22:36, Hanno Schlichting <plone@hannosch.info> wrote:
<p i18n:translate=""> You have to pay <span tal:content="view/formatted_amount" i18n:name="amount" i18n:count="view/amount">6 dollars</span>. </p>
In this case the underlying value is a simple integer, but the actual presentation might be locale dependent, like currency formatting.
Ah. Yes, that's a nice usecase I hadn't thought about.
I'm not sure what to do with this actually. How does multiple numbers in the same sentence are handled? I think this is just not allowed and should cause a syntax error, as there's no general way to translate those sentences with Gettext. Or does it result in a n-dimensional matrix?
No, gettext only supports one number per message.
How does this behave in regard to zope.i18nmessageid?
There will need to be some extension of the API, I think.
So I think we need to signal to the messageid which variable in the mapping is significant for the i18n count, right?
It's easier to just pass in the i18n count separately, IMO. -- Lennart Regebro: Zope and Plone consulting. http://www.colliberty.com/ +33 661 58 14 64
Lennart Regebro wrote:
On Wed, Jul 16, 2008 at 22:36, Hanno Schlichting <plone@hannosch.info> wrote:
<p i18n:translate=""> You have to pay <span tal:content="view/formatted_amount" i18n:name="amount" i18n:count="view/amount">6 dollars</span>. </p>
In this case the underlying value is a simple integer, but the actual presentation might be locale dependent, like currency formatting.
Ah. Yes, that's a nice usecase I hadn't thought about.
How does this behave in regard to zope.i18nmessageid?
There will need to be some extension of the API, I think.
So I think we need to signal to the messageid which variable in the mapping is significant for the i18n count, right?
It's easier to just pass in the i18n count separately, IMO.
Right. Since otherwise you won't be able to support the same use-case I outlined above in regard to the currency formatting. There the count variable might not be contained in the mapping at all. Hanno
On Wed, Jul 16, 2008 at 20:55, Stephan Richter <srichter@cosmos.phy.tufts.edu> wrote:
Good question! The ZPT above is not correct; once we write a correct one, it becomes more obvious:
<p i18n:translate="">There are <span tal:content="view/num" i18n:name="num" i18n:count="view/num>10</span> files.</p>
Ah, well, right. Of course all the examples you a %d substitution, but I just realized that gettext in itself does no substituation at all, so this is better. We should use the standard ${name} substitution for this too. However, you can't have more than one number per message, so <p i18n:translate="">There are <span tal:content="view/num" i18n:name="num" i18n:count="view/num>10</span> files and <span tal:content="view/num" i18n:name="num" i18n:count="view/dirs>10</span>directories.</p> wouldn't make any sense. Which number should be used? So I actually think i18n:count still should be on the main tag.
Alternatively we could just evaluate the tal:content or tal:replace expression.
But then we wouldn't know if we have a plural substitution or not, and we would have to start guessing... -- Lennart Regebro: Zope and Plone consulting. http://www.colliberty.com/ +33 661 58 14 64
participants (3)
-
Hanno Schlichting -
Lennart Regebro -
Stephan Richter