i18n questions

2 views
Skip to first unread message

Ilja Everilä

unread,
Apr 29, 2009, 3:07:50 AM4/29/09
to getpaid-dev, mi...@redinnovation.com
Hello,

I've been translating GetPaid (0.7) core and some plugins to Finnish
and encountered some issues. For example when rendering cart contents
table headings wouldn't localize. After some digging it turned out
that these strings were rendered in python and not in template
context.

The problematic classes were
Products.PloneGetPaid.browser.cart.CartFormatter and
Products.PloneGetPaid.browser.cart.ShoppingCartListing. Now, I tried
to use context.translate to wrap these messages, but it turned out
that the cart context was missing this method. Finally I used (ugly)
hacks and used zope.app.component.hooks.getSite method to fetch site
object and used its translate method.

As commented in the diff, these feel like ugly hacks and that's why
I'm asking what would be the correct way of fixing these messages. I'm
new to Plone and haven't gotten familiar with its possibilities yet.

Here's the diff on cart.py:

Index: browser/
cart.py
===================================================================
--- browser/cart.py (revision
2446)
+++ browser/cart.py (working
copy)
@@ -11,6 +11,9
@@
from zope.formlib import
form
from zc.table import column,
table

+# FIXME: this is here for translation
hacks
+from zope.app.component.hooks import
getSite
+
from ore.viewlet.container import ContainerViewlet
from ore.viewlet.core import FormViewlet

@@ -196,6 +199,11 @@
return interfaces.ILineContainerTotals( self.context )

def renderExtra( self ):
+
+ # FIXME: This is an ugly hack that fixes certain strings not
translating since
+ # they're never rendered in template context
+ translate = lambda msg: getSite().translate(msgid=msg,
domain='plonegetpaid')
+
if not len( self.context ):
return super( CartFormatter, self).renderExtra()

@@ -206,16 +214,22 @@
subtotal_price = totals.getSubTotalPrice()
total_price = totals.getTotalPrice()

- buffer = [ '<div class="getpaid-totals"><table
class="listing">']
- buffer.append( '<tr><th>SubTotal</th><td style="border-top:
1px solid #8CACBB;">%0.2f</td></tr>'%( subtotal_price ) )
+ buffer = [ u'<div class="getpaid-totals"><table
class="listing">']
+ buffer.append('<tr><th>')
+ buffer.append( translate(_(u"SubTotal")) )
+ buffer.append( '</th><td style="border-top:1px solid
#8CACBB;">%0.2f</td></tr>'%( subtotal_price ) )

- buffer.append( "<tr><th>Shipping</th><td>%0.2f</td></tr>"%
( shipping_price ) )
+ buffer.append( "<tr><th>" )
+ buffer.append( translate(_(u"Shipping")) )
+ buffer.append( "</th><td>%0.2f</td></tr>"%
( shipping_price ) )

for tax in tax_list:
buffer.append( "<tr><th>%s</th><td>%0.2f</td></tr>"%( tax
['name'], tax['value'] ) )
- buffer.append( "<tr><th>Total</th><td>%0.2f</td></tr>"%
( total_price ) )
+ buffer.append( "<tr><th>" )
+ buffer.append( translate(_(u"Total")) )
+ buffer.append( "</th><td>%0.2f</td></tr>"%( total_price ) )
buffer.append('</table></div>')
-
+
return u''.join( buffer) + super( CartFormatter,
self).renderExtra()

class ShoppingCartListing( ContainerViewlet ):
@@ -240,6 +254,11 @@
def __init__( self, *args, **kw):
super( ShoppingCartListing, self ).__init__( *args, **kw )

+ # FIXME: Translation hacks, should not use something like
this
+ for column in self.columns:
+ if hasattr(column, 'title'):
+ column.title = getSite().translate
(msgid=column.title, domain='plonegetpaid')
+
def getContainerContext( self ):
return self.__parent__.cart

Lucie Lejard

unread,
Apr 29, 2009, 10:05:02 AM4/29/09
to getpa...@googlegroups.com, mi...@redinnovation.com
It doesn't seem too much of a hack to me.
If you don't get any feedback, just go ahead and commit your changes.

thanks
Lucie
--
S i x F e e t U p , I n c . | http://www.sixfeetup.com
Phone: +1 (317) 861-5948 x605
ANNOUNCING the first Plone Immersive Training Experience | Sept. 10-11-12, 2009
http://www.sixfeetup.com/immerse

rafael

unread,
Apr 29, 2009, 10:09:12 AM4/29/09
to getpa...@googlegroups.com
  I have noticed another i18n problem about the add to cart button in the portlet not being properly translated. I didn't try to fix it cause I am illetrate in i18n... Will this hack fix it?

Thanks

rafael


Lucie Lejard escreveu:

danielle davout

unread,
Apr 29, 2009, 10:56:46 AM4/29/09
to getpa...@googlegroups.com
this one is easy :

<input type="submit"
i18n:translate="label_add_to_cart"
value="Add to Cart"
i18n:attributes="value" />

the attribute value is not translated unless you put
i18n:attributes="value"

Ilja Everilä

unread,
Apr 29, 2009, 11:58:05 AM4/29/09
to getpaid-dev
I've included this among other template i18n additions. Also it turned
out that the table heading rendering that caused my first issue
manifested elsewhere. Fixed those too.

Where can I request commit rights and what are the usual practices in
committing new changes. First to some branch or so?

On 29 huhti, 17:56, danielle davout <danielle.dav...@gmail.com> wrote:
> this one is easy :
>
>               <input type="submit"
>                      i18n:translate="label_add_to_cart"
>                      value="Add to Cart"
>                      i18n:attributes="value" />
>
> the attribute value is not translated unless you put
>                      i18n:attributes="value"
>
> On Wed, Apr 29, 2009 at 4:09 PM, rafael <rafaelcro...@gmail.com> wrote:
> >   I have noticed another i18n problem about the add to cart button in the
> > portlet not being properly translated. I didn't try to fix it cause I am
> > illetrate in i18n... Will this hack fix it?
>
> > Thanks
>
> > rafael
>
> > Lucie Lejard escreveu:
>
> > It doesn't seem too much of a hack to me.
> > If you don't get any feedback, just go ahead and commit your changes.
>
> > thanks
> > Lucie
> > --
> > S i x  F e e t  U p ,  I n c .  |  http://www.sixfeetup.com
> > Phone: +1 (317) 861-5948 x605
> > ANNOUNCING the first Plone Immersive Training Experience | Sept. 10-11-12,
> > 2009
> >http://www.sixfeetup.com/immerse
>
> > On Wed, Apr 29, 2009 at 3:07 AM, Ilja Everilä <ilja.ever...@twinapex.com>

danielle davout

unread,
Apr 29, 2009, 12:23:01 PM4/29/09
to getpa...@googlegroups.com
here and there, I noticed small mistakes easy to eradicate
you did the hard job, thanks for that

Lucie Lejard

unread,
Apr 29, 2009, 4:42:42 PM4/29/09
to getpa...@googlegroups.com
I can give you commit rights. Just send me a private email containing
your gmail address.
You can commit to the trunk

Thanks
Lucie
--
S i x F e e t U p , I n c . | http://www.sixfeetup.com
Phone: +1 (317) 861-5948 x605
ANNOUNCING the first Plone Immersive Training Experience | Sept. 10-11-12, 2009
http://www.sixfeetup.com/immerse



danielle davout

unread,
Apr 30, 2009, 11:51:40 AM4/30/09
to getpa...@googlegroups.com
to be more explicit that "here and there"
in admin.zcml
+ <browser:menu
+ id="getpaid_admin"
+ title="GetPaid Administration"
++ i18n:attributes="title"
+ />
and similar
in browser/configure.zcml
+ <browser:menu
+ id="user"
+ title="Plone User Menu"
++ i18n:attributes="title"
+ />
and the like
/browser/content.zcml , settings.zcml same pbs

in checkout.py :
+ @@ -713,7 +717,7 @@ class CheckoutSelectShipping( BaseChecko
+ ship_service_names =
IGetPaidManagementOptions(siteroot).shipping_services
+
+ if not ship_service_names:
+ - self.status = "Misconfigured Store - No Shipping
Method Activated"
+ + self.status = _(u"Misconfigured Store - No Shipping
Method Activated")
+ return
+


in browser/templates/cart-listing.pt

+ i18n:domain="plonegetpaid">
+
+ <legend i18n:translate="legend_cart_contents"> Your Cart Contents </legend>
+ - <div class="formHelp" id="cart_update_delete_help">You must
confirm your shopping cart modifications by clicking "Update"
below.</div>
+ + <div class="formHelp" id="cart_update_delete_help"
i18n:translate="">You must confirm your shopping cart modifications by
clicking Update$
+ <form action="."

in interfaces.py
+ -# Configure # Configure
+ -class IGetPaidManagementContentTypes( igetpaid.IPersistentOpt
class IGetPaidManagementContentTypes( igetpaid.IPersistentOpt
+ -
+ - buyable_types = schema.List(
buyable_types = schema.List(
+ - title = _(u"Buyable Types"),
title = _(u"Buyable Types"),
+ - required = False,
required = False,
+ - default = [],
default = [],
+ - description = _(u"Buyable Content delivered through t
description = _(u"Buyable Content delivered through t
+ - value_type = schema.Choice( title=u"buyable_types", s
value_type = schema.Choice( title=u"buyable_types", s
+ - ) )
and the like
the list is non exhaustive

> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to

danielle davout

unread,
Apr 30, 2009, 5:05:01 PM4/30/09
to getpa...@googlegroups.com
once templates containing
<metal:page use-macro="context/@@manage-getpaid-order-template/macros/admin">
corrected with
<metal:page use-macro="context/@@manage-getpaid-order-template/macros/admin"
i18n:domain="plonegetpaid">
msgids are added to the pot
Reply all
Reply to author
Forward
0 new messages