Re: [pylons-discuss] Localized URL schema using chameleon
On 21 Aug 2014, at 01:29, Kamal Gill designbyka...@gmail.com wrote: Oscar, It's probably safer to pass the translated string as a template variable from the view callable, since Pyramid's i18n machinery only picks up translation strings marked via i18n:translate and i18n:attributes in .pt files IIRC. Basically, you would pass products as a string marked for translation to your template from the view. The template would be the following (using your original code)... pa href=/${request.locale_name}/${products}img src=products.jpg alt= //a/p While the view would mark the products string for i18n as follows... from pyramid.i18n import TranslationString as _ ... @view_config(route_name='products', renderer='templates/products.pt http://products.pt/') def products_view(): ... return dict(products=_(u'products')) HTH, Kamal On Aug 20, 2014, at 4:13 PM, Oscar Curero flext...@gmail.com mailto:flext...@gmail.com wrote: On Wednesday, August 20, 2014 7:28:28 PM UTC+2, Wichert Akkerman wrote: On 20 Aug 2014, at 19:21, Oscar Curero flex...@gmail.com javascript: wrote: Hi, I'm building my first application using pyramid and chameleon and I'm having problems with the localized URL schema. It's something like this: /en/products /es/productos /ca/productes The problem starts when I need to make the HTML templates. For example, I want to make the following template: pa href=/${request.locale_name}/${products}img src=products.jpg alt= //a/p The problem here is that ${products} assumes that you have a python variable named products at hand and want to insert its value in the template. But since you have no such variable you get a NameError exception. If you goal is to make the word products translatable you can do this: ${_(products)} . Wichert. Thanks Wichert. If I try what you say with nothing else, it doesn't work yet: NameError: _ - Expression: ${request.locale_name}/${_('products')} - Filename: ... ate/templates/products.pt http://products.pt/ - Location: (line 10: col 30) - Source: ... pa href=/${request.locale_name}/${_('products')}img ... However, if I add at the top of the template the following statement, it works as expected: ?python from pyramid.i18n import TranslationString as _ ? Is this the way it should work? It is! You can also use a BeforeRender event to expose _ to all templates. See http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/api/events.html#pyramid.events.BeforeRender http://docs.pylonsproject.org/projects/pyramid/en/1.5-branch/api/events.html#pyramid.events.BeforeRender for an example of doing that. Wichert. -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/d/optout.
[pylons-discuss] Localized URL schema using chameleon
Hi, I'm building my first application using pyramid and chameleon and I'm having problems with the localized URL schema. It's something like this: /en/products /es/productos /ca/productes The problem starts when I need to make the HTML templates. For example, I want to make the following template: pa href=/${request.locale_name}/${products}img src=products.jpg alt= //a/p That template should render the link depending on the user locale setting (request.locale_name is a variable where I save the locale name and products is a translation string), ie: For en locale -- pa href=/en/productsimg src=products.jpg alt= //a/p For es locale -- pa href=/es/productosimg src=products.jpg alt= //a/p For ca locale -- pa href=/ca/productesimg src=products.jpg alt= //a/p However, what I get is: NameError: products - Expression: /${request.locale_name}/${products} - Filename: ... ate/templates/products.pt - Location: (line 10: col 30) - Source: ... pa href=/${request.locale_name}/${products}img ... Reading the page http://docs.pylonsproject.org/projects/pyramid/en/1.0-branch/narr/i18n.html#chameleon-template-support-for-translation-strings; I get he feeling that what I'm trying to achieve is possible. What do I'm doing wrong? Thanks in advance, -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/d/optout.
Re: [pylons-discuss] Localized URL schema using chameleon
On 20 Aug 2014, at 19:21, Oscar Curero flext...@gmail.com wrote: Hi, I'm building my first application using pyramid and chameleon and I'm having problems with the localized URL schema. It's something like this: /en/products /es/productos /ca/productes The problem starts when I need to make the HTML templates. For example, I want to make the following template: pa href=/${request.locale_name}/${products}img src=products.jpg alt= //a/p The problem here is that ${products} assumes that you have a python variable named “products” at hand and want to insert its value in the template. But since you have no such variable you get a NameError exception. If you goal is to make the word “products” translatable you can do this: ${_(“products”)} . Wichert. -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/d/optout.
Re: [pylons-discuss] Localized URL schema using chameleon
On Wednesday, August 20, 2014 7:28:28 PM UTC+2, Wichert Akkerman wrote: On 20 Aug 2014, at 19:21, Oscar Curero flex...@gmail.com javascript: wrote: Hi, I'm building my first application using pyramid and chameleon and I'm having problems with the localized URL schema. It's something like this: /en/products /es/productos /ca/productes The problem starts when I need to make the HTML templates. For example, I want to make the following template: pa href=/${request.locale_name}/${products}img src=products.jpg alt= //a/p The problem here is that ${products} assumes that you have a python variable named “products” at hand and want to insert its value in the template. But since you have no such variable you get a NameError exception. If you goal is to make the word “products” translatable you can do this: ${_(“products”)} . Wichert. Thanks Wichert. If I try what you say with nothing else, it doesn't work yet: NameError: _ - Expression: ${request.locale_name}/${_('products')} - Filename: ... ate/templates/products.pt - Location: (line 10: col 30) - Source: ... pa href=/${request.locale_name}/${_('products')}img ... However, if I add at the top of the template the following statement, it works as expected: ?python from pyramid.i18n import TranslationString as _ ? Is this the way it should work? Thanks! -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/d/optout.
Re: [pylons-discuss] Localized URL schema using chameleon
Oscar, It's probably safer to pass the translated string as a template variable from the view callable, since Pyramid's i18n machinery only picks up translation strings marked via i18n:translate and i18n:attributes in .pt files IIRC. Basically, you would pass products as a string marked for translation to your template from the view. The template would be the following (using your original code)... pa href=/${request.locale_name}/${products}img src=products.jpg alt= //a/p While the view would mark the products string for i18n as follows... from pyramid.i18n import TranslationString as _ ... @view_config(route_name='products', renderer='templates/products.pt') def products_view(): ... return dict(products=_(u'products')) HTH, Kamal On Aug 20, 2014, at 4:13 PM, Oscar Curero flext...@gmail.com wrote: On Wednesday, August 20, 2014 7:28:28 PM UTC+2, Wichert Akkerman wrote: On 20 Aug 2014, at 19:21, Oscar Curero flex...@gmail.com wrote: Hi, I'm building my first application using pyramid and chameleon and I'm having problems with the localized URL schema. It's something like this: /en/products /es/productos /ca/productes The problem starts when I need to make the HTML templates. For example, I want to make the following template: pa href=/${request.locale_name}/${products}img src=products.jpg alt= //a/p The problem here is that ${products} assumes that you have a python variable named products at hand and want to insert its value in the template. But since you have no such variable you get a NameError exception. If you goal is to make the word products translatable you can do this: ${_(products)} . Wichert. Thanks Wichert. If I try what you say with nothing else, it doesn't work yet: NameError: _ - Expression: ${request.locale_name}/${_('products')} - Filename: ... ate/templates/products.pt - Location: (line 10: col 30) - Source: ... pa href=/${request.locale_name}/${_('products')}img ... However, if I add at the top of the template the following statement, it works as expected: ?python from pyramid.i18n import TranslationString as _ ? Is this the way it should work? Thanks! -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups pylons-discuss group. To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discuss+unsubscr...@googlegroups.com. To post to this group, send email to pylons-discuss@googlegroups.com. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/d/optout.