Being fairly new to Pylons, I'm working on an Pylons-based (0.9.6rc3)
website that utilizes Genshi, Babel, ToscaWidgets and FormEncode. So
far everything is working fine except for the translations. I was able
to extract and compile language catalogs as described in
http://wiki.pylonshq.com/display/pylonsdocs/Internationalization+and+Localization
.
Problem #1:
FormEncode's error messages are not translated at all. What are the
required steps?
Problem #2:
Although all strings are correctly extracted from my Genshi templates,
the strings aren't translated in the rendered output. Do I somehow
have to apply the genshi.filters.i18n.Translator filter manually (if
so, what would be the easiest way?) or am I missing something else?
I've been searching all related documentation and lists/groups for
hours without success. Maybe anyone can give some hints?
Apart from these issues I'm really impressed how Pylons encourages
writing clean and readable code without sacrificing flexibility at
all.
Thank you,
Daniel Haus
>
> Hi!
>
> Being fairly new to Pylons, I'm working on an Pylons-based (0.9.6rc3)
> website that utilizes Genshi, Babel, ToscaWidgets and FormEncode. So
> far everything is working fine except for the translations. I was able
> to extract and compile language catalogs as described in
> http://wiki.pylonshq.com/display/pylonsdocs/Internationalization+and
> +Localization
> .
>
> Problem #1:
> FormEncode's error messages are not translated at all. What are the
> required steps?
You can use the new "state" argument to pylons' "validate" decorator
(in trunk only since r2347) and set its "_" attribute:
from pylons.i18n import _
from pylons.decorators import validate
class State:
_ = _
class AController(BaseController):
@validate(state=State(), ...)
def my_meth(self):
...
If you're using ToscaWidgets, its "validate" decorator (in
toscawidgets.mods.pylonshf) accepts a "state_factory" argument with
similar semantics to Pylons' "state" but accepts a callable instead
that returns the state:
from toscawidgets.mods.pylonshf import validate
class AController(BaseController):
@validate(state_factory= lambda: State(), ...)
def my_meth(self)
...
You'll then have to add FormEncode's messages to your app's message
catalog, compile it, etc... and that should do it.
BTW, I'd love to hear of a way to configure Pylons's "_" function to
use the message catalog inside FormEncode's egg instead of copying it
inside my app's catalog, is there any?
HTH,
Alberto
> You'll then have to add FormEncode's messages to your app's message
> catalog, compile it, etc... and that should do it.
>
> BTW, I'd love to hear of a way to configure Pylons's "_" function to
> use the message catalog inside FormEncode's egg instead of copying it
> inside my app's catalog, is there any?
I'm thinking there should be an option, that when 'on', will pass the
State class into @validate for you. I'm also curious about whether
there's some way to collect the message catalogs used in packages by
your app. Maybe that's a Babel thing, that it could look at your
dependency tree and find message catalogs to consolidate for you?
Cheers,
Ben
Now there's still this Genshi translation-filter issue. The Pylons
i18n tutorial does cover message extraction from Genshi, but there are
no hints on configuration of that filter, which i think would be
necessary. Is this a common problem, or am I missing something
obvious?
Greetings,
Daniel
> smime.p7s
> 3KHerunterladen
You'll then have to add FormEncode's messages to your app's message
catalog, compile it, etc... and that should do it.
BTW, I'd love to hear of a way to configure Pylons's "_" function to
use the message catalog inside FormEncode's egg instead of copying it
inside my app's catalog, is there any?
Take a look at http://genshi.edgewall.org/wiki/Documentation/
i18n.html#translation and the source of genshi's Buffet plugin.
Apparently (haven't tried, so tell us how it goes...:) you should be
able to do something like:
from genshi.filters import Translator
from pylons.i18n import _
def template_loaded(template):
template.filters.insert(0, Translator(_))
Then you would need to pass this callback when initializing genshi's
buffet plugin:
inside middleware.py (or load_environment):
options = {"genshi.loader_callback": template_loaded}
# options.update(options_from_config_file)
config.add_template_engine("genshi", "yourapp.templates", options)
HTH,
Alberto
Daniel
On 28 Aug., 16:18, Alberto Valverde <albe...@toscat.net> wrote:
> On Aug 27, 2007, at 10:44 PM, Daniel Haus wrote:
>
>
>
> > Now there's still this Genshi translation-filter issue. The Pylons
> > i18n tutorial does cover message extraction from Genshi, but there are
> > no hints on configuration of that filter, which i think would be
> > necessary. Is this a common problem, or am I missing something
> > obvious?
>
> Take a look athttp://genshi.edgewall.org/wiki/Documentation/