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ä <[email protected]> 
> wrote:
>   
>> 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
>>
>>     
>
> >
>
>   


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"getpaid-dev" 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/getpaid-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to