Internationalization error

45 views
Skip to first unread message

BIN JANNE

unread,
Aug 24, 2010, 4:24:34 AM8/24/10
to mako-d...@googlegroups.com
i want make Internationalization  in mako template.
but i don't konw how to do ?
this is my code segment:

<% import mako.ext.babelplugin %>
<%inherit file="/layouts/main.html" />
<%def name="title()">
${model._meta.verbose_name} ${_("Admin")}
</%def>

but it throw error:
TypeError: 'Undefined' object is not callable

it appears  mako don't know how to deal with '_'.

sorry my poor english!

BIN JANNE

unread,
Aug 25, 2010, 2:53:51 AM8/25/10
to mako-d...@googlegroups.com
I add ugettext alias _ in to context. now, no error.
but the _ function can't read /conf/local/zh_TW or /zh_CN mo file in my project. can read mo file from django package.

second: how can make mako template work with babelplugin, whta is relation between mako and babel.

2010/8/24 BIN JANNE <pang...@gmail.com>

Michael Bayer

unread,
Aug 25, 2010, 9:51:08 AM8/25/10
to mako-d...@googlegroups.com
On Aug 25, 2010, at 2:53 AM, BIN JANNE wrote:

I add ugettext alias _ in to context. now, no error.
but the _ function can't read /conf/local/zh_TW or /zh_CN mo file in my project. can read mo file from django package.

second: how can make mako template work with babelplugin, whta is relation between mako and babel.

I've never used Babel and it would be nice if someone who has could chime in here, but the docs for this are at :






2010/8/24 BIN JANNE <pang...@gmail.com>
i want make Internationalization  in mako template.
but i don't konw how to do ?
this is my code segment:

<% import mako.ext.babelplugin %>
<%inherit file="/layouts/main.html" />
<%def name="title()">
${model._meta.verbose_name} ${_("Admin")}
</%def>

but it throw error:
TypeError: 'Undefined' object is not callable

it appears  mako don't know how to deal with '_'.

sorry my poor english!


--
You received this message because you are subscribed to the Google Groups "Mako Templates for Python" group.
To post to this group, send email to mako-d...@googlegroups.com.
To unsubscribe from this group, send email to mako-discuss...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mako-discuss?hl=en.

Alexandre Conrad

unread,
Aug 25, 2010, 3:01:42 PM8/25/10
to mako-d...@googlegroups.com
Hi there,

2010/8/25 Michael Bayer <mik...@zzzcomputing.com>:


> I've never used Babel and it would be nice if someone who has could chime in
> here, but the docs for this are at :
> http://www.makotemplates.org/docs/usage.html#usage_common_babel

I have only used Babel in Mako with Pylons, which is all
pre-configured for you. You may want to create a dummy Pylons project
and see how it is set up. Or at least read the Pylons documentation on
internationalization (i18n), it may give you some hints on how to set
it up.

--
Alex
twitter.com/alexconrad

cd34

unread,
Aug 30, 2010, 6:58:43 PM8/30/10
to Mako Templates for Python
in setup.py, uncomment:

message_extractors={'cp': [
('**.py', 'python', None),
('templates/**.mako', 'mako', {'input_encoding':
'utf-8'}),
('public/**', 'ignore', None)]},

lib/helpers.py:

from pylons.i18n import ugettext as _

Then:

mkdir projectname/i18n
python setup.py extract_messages

This creates a .pot file which you'll copy to i18n/es

You'll have an i18n/es/es.pot file that you edit to add the various
translations then run:

python setup.py init_catalog -l es

I believe you can use upgrade_catalog if you have modified the .pot
file.

http://pylonshq.com/docs/en/1.0/i18n/ does contain fairly decent
instructions. Also, you can use pootle (requires slight customization
as the path pootle expects is a little different than the path that
Pylons expects), but, it works fairly well.
Reply all
Reply to author
Forward
0 new messages