|
I have a translated content type.
I use <metal:use-macro="python:here.widget('FieldName', mode='view')" /> to get values from content type`s vocabulary. When I use it in content type`s view, it works fine. But when I use it in page template values are not translated. Would be greatful for help. temlate`s piese: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" xmlns:tal="http://xml.zope.org/namespaces/tal" xmlns:metal="http://xml.zope.org/namespaces/metal" xmlns:i18n="http://xml.zope.org/namespaces/i18n" lang="ru" metal:use-macro="here/main_template/macros/master" i18n:domain="my.domain"> <body> <div metal:fill-slot="main"> ............ <div tal:define="results python:context.scr()" tal:repeat="result results"> <label>Branch: </label> <metal:Branch use-macro="python:result.widget('P_Branch', mode='view')" /> </div> .............. </div> </body> </html> |
|
Hi,
How do you internationalized your vocabulary? With Message objects? What is the i18n domain? If this is a vocabulary, you need to iterate on your vocabulary and put an i18n:translate="" for each entry. See Products/Archetypes/skins/archetypes/widgets/selection.pt for an example. Vincent Fretin Ecreall Site : http://vincentfretin.ecreall.com On Mon, Sep 6, 2010 at 5:05 PM, alexanderpas <[hidden email]> wrote: > > I have a translated content type. > I use > > <metal:use-macro="python:here.widget('FieldName', mode='view')" /> > > to get values from content type`s vocabulary. > When I use it in content type`s view, it works fine. > But when I use it in page template values are not translated. > Would be greatful for help. > > > temlate`s piese: > > > <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" > xmlns:tal="http://xml.zope.org/namespaces/tal" > xmlns:metal="http://xml.zope.org/namespaces/metal" > xmlns:i18n="http://xml.zope.org/namespaces/i18n" > lang="ru" > metal:use-macro="here/main_template/macros/master" > i18n:domain="my.domain"> > > <body> > <div metal:fill-slot="main"> > > ............ > <div tal:define="results python:context.scr()" > tal:repeat="result results"> > > <label>Branch: </label> > <metal:Branch use-macro="python:result.widget('P_Branch', > mode='view')" /> > </div> > .............. > > </div> > </body> > </html> > -- > View this message in context: http://plone-regional-forums.221720.n2.nabble.com/Content-type-s-fields-translation-in-Page-Template-tp5503389p5503389.html > Sent from the Internationalization mailing list archive at Nabble.com. > > ------------------------------------------------------------------------------ > This SF.net Dev2Dev email is sponsored by: > > Show off your parallel programming skills. > Enter the Intel(R) Threading Challenge 2010. > http://p.sf.net/sfu/intel-thread-sfd > _______________________________________________ > Plone-i18n mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/plone-i18n > ------------------------------------------------------------------------------ This SF.net Dev2Dev email is sponsored by: Show off your parallel programming skills. Enter the Intel(R) Threading Challenge 2010. http://p.sf.net/sfu/intel-thread-sfd _______________________________________________ Plone-i18n mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/plone-i18n |
|
Thanks fo request so fast.
Before, to store values I used a List. And getField() method gave me translated values. But now I use Vocabulary for storing. To get values from Vocabulary in page template: <div tal:define="results python:context.scr()" tal:repeat="result results"> <div tal:define="vocab python:result.getField('MyField').Vocabulary(result); value python:result.displayValue(vocab, result.getMyField())" tal:content="value" i18n:translate=""> </div> </div> I use my product`s domain. But also tried 'plone' domain, previously extended it with my translation. May be I don`t correctly understand translation machinery. Do I need to use i18ndude to translate my template, or template can use already existing product`s translation? |
|
You need to create your vocabulary like this:
from Products.Archetypes.public import DisplayList from zope.i18nmessageid import MessageFactory _ = MessageFactory('my.product') CATEGORY_VOCABULARY = DisplayList([('general', _('label_general_news', default=u'General News')), ('lifeofthenetwork', _('label_lifeofthenetwork', default=u"Life of the network")), ('trainingcatalog', _('label_training_catalog', default=u"Training catalog")),]) And set in your archetype field: vocabulary=CATEGORY_VOCABULARY, or a string, in this case you have to implement the method which return a DisplayList. Then you can use i18ndude to extract your messages and translate them. and in your template, something like: tal:content="python:vocab.getValue(item)" i18n:translate="" please look at Products/Archetypes/skins/archetypes/widgets/selection.pt Vincent Fretin Ecreall Site : http://vincentfretin.ecreall.com On Tue, Sep 7, 2010 at 10:39 AM, alexanderpas <[hidden email]> wrote: > > Thanks fo request so fast. > Before, to store values I used a List. And getField() method gave me > translated values. > But now I use Vocabulary for storing. > > To get values from Vocabulary in page template: > > <div tal:define="results python:context.scr()" > tal:repeat="result results"> > > </div> > > I use my product`s domain. But also tried 'plone' domain, previously > extended it with my translation. > > May be I don`t correctly understand translation machinery. Do I need to use > i18ndude to translate my template, or template can use already existing > product`s translation? > -- > View this message in context: http://plone-regional-forums.221720.n2.nabble.com/Content-type-s-fields-translation-in-Page-Template-tp5503389p5505632.html > Sent from the Internationalization mailing list archive at Nabble.com. > > ------------------------------------------------------------------------------ > This SF.net Dev2Dev email is sponsored by: > > Show off your parallel programming skills. > Enter the Intel(R) Threading Challenge 2010. > http://p.sf.net/sfu/intel-thread-sfd > _______________________________________________ > Plone-i18n mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/plone-i18n > ------------------------------------------------------------------------------ This SF.net Dev2Dev email is sponsored by: Show off your parallel programming skills. Enter the Intel(R) Threading Challenge 2010. http://p.sf.net/sfu/intel-thread-sfd _______________________________________________ Plone-i18n mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/plone-i18n |
|
That is exactly what I did, except labels in vocabs values, because my vocabularies are to large for this.
Definitions like this: STAGE_LIST = DisplayList([ ('0','-'), ('1',_(u'Business-idea')), ('2',_(u'Initial stage')), ('3',_(u'Expansion stage')), ]) And all vocab values are translated, but only in content type`s view, not in other template. And in my template i do pretty much the same as in Products/Archetypes/skins/archetypes/widgets/selection.pt as shown in my previous post. |
|
On Tue, Sep 7, 2010 at 1:27 PM, alexanderpas <[hidden email]> wrote:
> > That is exactly what I did, except labels in vocabs values, because my > vocabularies are to large for this. > Definitions like this: > > STAGE_LIST = DisplayList([ > ('0','-'), > ('1',_(u'Business-idea')), > ('2',_(u'Initial stage')), > ('3',_(u'Expansion stage')), > ]) > > And all vocab values are translated, but only in content type`s view, not in > other template. > And in my template i do pretty much the same as in > Products/Archetypes/skins/archetypes/widgets/selection.pt as shown in my > previous post. I didn't see anything in your previous post concerning the template. You only wrote <div tal:define="results python:context.scr()" tal:repeat="result results"> </div> what do you do with result? For each term of the vocabulary you have to call getValue like I said in my previous post Did you see that code in Products/Archetypes/skins/archetypes/widgets/selection.pt ? <option tal:repeat="item vocab" tal:attributes="value item; selected python:item in selection and 'selected' or None" tal:content="python:vocab.getValue(item)" i18n:translate="" /> So I think something like this in your case: <ul tal:define="results python:context.scr(); vocab python:context.scr.Vocabulary(context)"> <li tal:repeat="item results" tal:content="python:vocab.getValue(item)" i18n:translate="" /> </ul> Vincent ------------------------------------------------------------------------------ This SF.net Dev2Dev email is sponsored by: Show off your parallel programming skills. Enter the Intel(R) Threading Challenge 2010. http://p.sf.net/sfu/intel-thread-sfd _______________________________________________ Plone-i18n mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/plone-i18n |
|
Hmm...It posted only a part of my code.
The full is: <div tal:define="results python:context.scr()"
tal:repeat="result results">
<div tal:define="vocab python:result.getField('MyField').Vocabulary(result);
value python:result.displayValue(vocab, result.getMyField())"
tal:content="value"
i18n:translate=""> </div>
</div>
|
|
Ahah! You use the displayValue python script! There is a unresolved
issue about it. See https://dev.plone.org/plone/ticket/7627 For now, please iterate on result.getMyField() and call vocab.getValue(item) <ul tal:define="vocab python:result.getField('MyField').Vocabulary(context);"> <li tal:repeat="item result.getMyField()" tal:content="python:vocab.getValue(item)" i18n:translate=""> </li> </ul> Vincent On Tue, Sep 7, 2010 at 2:47 PM, alexanderpas <[hidden email]> wrote: > > Hmm...It posted only a part of my code. > The full is: > > <div tal:define="results python:context.scr()" > tal:repeat="result results"> > <div tal:define="vocab > python:result.getField('MyField').Vocabulary(result); > value python:result.displayValue(vocab, > result.getMyField())" > tal:content="value" > i18n:translate=""> </div> > </div> > -- > View this message in context: http://plone-regional-forums.221720.n2.nabble.com/Content-type-s-fields-translation-in-Page-Template-tp5503389p5506258.html > Sent from the Internationalization mailing list archive at Nabble.com. > > ------------------------------------------------------------------------------ > This SF.net Dev2Dev email is sponsored by: > > Show off your parallel programming skills. > Enter the Intel(R) Threading Challenge 2010. > http://p.sf.net/sfu/intel-thread-sfd > _______________________________________________ > Plone-i18n mailing list > [hidden email] > https://lists.sourceforge.net/lists/listinfo/plone-i18n > ------------------------------------------------------------------------------ This SF.net Dev2Dev email is sponsored by: Show off your parallel programming skills. Enter the Intel(R) Threading Challenge 2010. http://p.sf.net/sfu/intel-thread-sfd _______________________________________________ Plone-i18n mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/plone-i18n |
|
Thanks for displayValue script warning!
I chenged my code as you suggested. I dont need repeat in getField, it returns single key/value. So, now it looks like this: <div tal:define="vocab python:result.getField('P_Branch').Vocabulary(context);">
<b tal:content="python:vocab.getValue(result.getP_Branch())"
i18n:translate="">
</b>
</div> But, unfortunately, values are still not translated :\ |
|
On Tue, Sep 7, 2010 at 3:28 PM, alexanderpas <[hidden email]> wrote:
> > Thanks for displayValue script warning! > > I chenged my code as you suggested. > I dont need repeat in getField, it returns single key/value. > So, now it looks like this: > > <div tal:define="vocab > python:result.getField('P_Branch').Vocabulary(context);"> > > > </div> > > But, unfortunately, values are still not translated :\ Do you already have other messages you used elsewhere in your product i18n domain? Are they translated? Vincent ------------------------------------------------------------------------------ This SF.net Dev2Dev email is sponsored by: Show off your parallel programming skills. Enter the Intel(R) Threading Challenge 2010. http://p.sf.net/sfu/intel-thread-sfd _______________________________________________ Plone-i18n mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/plone-i18n |
|
All messages are translated in content type's view.
But I've just noticed that in "Add New" popup menu the name of my content type is not translated. Could it be connected? |
|
On Tue, Sep 7, 2010 at 4:01 PM, alexanderpas <[hidden email]> wrote:
> > All messages are translated in content type's view. > But I've just noticed that in "Add New" popup menu the name of my content > type is not translated. > Could it be connected? Do you have registered your locales directory? <configure xmlns="http://namespaces.zope.org/zope" xmlns:five="http://namespaces.zope.org/five" xmlns:i18n="http://namespaces.zope.org/i18n" <i18n:registerTranslations directory="locales" /> </configure> and you should have for example locales/fr/LC_MESSAGES/my.product.po for the French translation. Vincent ------------------------------------------------------------------------------ This SF.net Dev2Dev email is sponsored by: Show off your parallel programming skills. Enter the Intel(R) Threading Challenge 2010. http://p.sf.net/sfu/intel-thread-sfd _______________________________________________ Plone-i18n mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/plone-i18n |
|
Yes it's registered. And everything works correctly on a clean site!
Sorry, I did'nt test this problem enough. My fault. So, now everything I need is to find out what makes my site think that the language is English. I supose it could be some other not translated product or template. Thanks a lot, Vincent. |
| Powered by Nabble | Edit this page |
