Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

tgext and i18n

5 views
Skip to first unread message

Daniele Favara

unread,
Jul 14, 2009, 8:43:39 AM7/14/09
to turbo...@googlegroups.com
Hi all,

i'm working on a tgext.pages or tgext.admin like tg2 app.

I can extract and compile messages from my tgext.example but

how can i render those trasnlated messages in the main app where i 'plug' it?


--
Daniele Favara

cd34

unread,
Jul 14, 2009, 10:46:46 AM7/14/09
to TurboGears
http://turbogears.org/2.0/docs/main/Internationalization.html

When you edit the .po file for the appropriate language, and compile
the catalog, if your browser is set to accept the language or you have
forced the language in the development.ini file, you should be able to
see the translations.

If you are not seeing those extracted messages, then the application
doesn't have the text within the controller properly written.

There seem to be two conventions used within the TG2 source for i18n
within the application

flash(_('this message should be translated'))

and

msg = l_('this message should be translated')

l_() versus _() determines when the text will be translated. _() is
translated when the code is loaded, l_() is translated when the code
is executed.

Daniele Favara

unread,
Jul 14, 2009, 1:41:38 PM7/14/09
to turbo...@googlegroups.com
2009/7/14 cd34 <mcd...@gmail.com>:
>
> http://turbogears.org/2.0/docs/main/Internationalization.html
>

> When you edit the .po file for the appropriate language, and compile
> the catalog, if your browser is set to accept the language or you have
> forced the language in the development.ini file, you should be able to
> see the translations

Yes and a *quickstart* project works fine.

>
> If you are not seeing those extracted messages, then the application
> doesn't have the text within the controller properly written.

The problem i have is that i import in the root controller of the
main app a controller of a tgext i wrote, in the same way as on the
default quickstart project is imported Catwalk (admin).

What i'd need to do is to get translated messages of the imported controller.

Is it clear ? I'm not sure i explained the goal very well .

Many thanks

--
Daniele Favara

cd34

unread,
Jul 14, 2009, 2:47:38 PM7/14/09
to TurboGears
When you extract and create the catalog for the language, do the
messages you want to translate show up in the .po file?

Are the messages in your template able to be translated? How about
the messages in your model? Is it just the controller that isn't
showing up in the .po file?

In your controller, have you imported gettext?

from pylons.i18n import ugettext as _

and do you have any messages within your controller written as:

msg = _('message to be displayed')

flash(_('flash message'))

title = _('title')

When you run extract, does your base .po file have the messages that
you want to translate?

When you did the init_catalog for your language, did the message you
were looking for show up in the .po file for that language?

When you compiled the catalog, did it show that it recognized the
translation for the language you modified?

Do you have babel installed for your virtual environment? Does your
application work if you copy it over to a quickstarted project
environment? Are you using an older setup.py that has the following
lines commented out:

message_extractors={'cp': [
('**.py', 'python', None),
('templates/**.mako', 'mako', None),
('templates/**.html', 'genshi', None),
('public/**', 'ignore', None)]},

Of course, if you are using mako, you need to change the extension
there to .mak

Or, are you saying that you didn't move the files over from the i18n
directory of the other project and that your translations have
disappeared?

Daniele Favara

unread,
Jul 14, 2009, 8:12:22 PM7/14/09
to turbo...@googlegroups.com
Let's make an example, the controller of the main app looks like:

-----------------------------------
#myappext/myext/controllers/root.py
class MyController(BaseController):
@expose('myapptext.myext.templates.index')
def index(self):
return dict(page=_('index2'))

-----------------------------------
#myapp/controllers/root.py
from myapp import model
.....
from myappext.myext.controllers.root import MyController
class RootController(BaseController):
mycontroller = MyController()
@expose('myapp.templates.index')
def index(self):
return dict(page=_('index1'))

here we have two 'messages':

_('index1') : in myapp.controllers.root --> transalted as *index_lang1*
_('index2'): in myappext.myext.controllers.root --> transalted as *index_lang2*

first of all i extract and compile messages from *myappext* then i
extract and compile messages from *myapp*.

in http://localhost:8080/ i get *index_lang1* [correct]
in http://localhost:8080/mycontroller i get *index2* [not correct]

I checked if apps as :

- tgext.admin
- tgext.registration

use i18n, but i could not find anything useful.

Any suggestion is very appreciated

Many thanks

2009/7/14 cd34 <mcd...@gmail.com>:
--
Daniele Favara

cd34

unread,
Jul 15, 2009, 1:25:08 AM7/15/09
to TurboGears
On Jul 14, 8:12 pm, Daniele Favara <no...@dsslive.org> wrote:
> Let's make an example, the controller of the main app looks like:
>
> -----------------------------------
> #myappext/myext/controllers/root.py
> class MyController(BaseController):
>     @expose('myapptext.myext.templates.index')
>     def index(self):
>             return dict(page=_('index2'))
>
> -----------------------------------
> #myapp/controllers/root.py
> from myapp import model
> .....
> from myappext.myext.controllers.root import MyController
> class RootController(BaseController):
>     mycontroller = MyController()
>     @expose('myapp.templates.index')
>     def index(self):
>         return dict(page=_('index1'))
>
> here we have two 'messages':
>
> _('index1') : in myapp.controllers.root --> transalted as *index_lang1*
> _('index2'):  in myappext.myext.controllers.root --> transalted as *index_lang2*
>
> first of all i extract and compile messages from *myappext* then i
> extract and compile messages from *myapp*.
>
> inhttp://localhost:8080/i get *index_lang1* [correct]
> inhttp://localhost:8080/mycontrolleri get *index2* [not correct]

I think the problem here is that your application in
myapp.controllers.root is looking for myapp.i18n for the messages for
your entire application. Even though you have imported your
controller from myappext.myext, I believe the .po files in myapp.i18n
are what is being checked. I could be wrong, but, I am guessing this
is the issue.

You should be able to test it by adding the respective lines from
the .po file from myappext.i18n to the .pot and .po file in your
language file and recompiling the catalog.

If that is the case, you should be able to change setup.py so that it
also searches your application in myappext for the catalogs and update
the .po files for your language.

Daniele Favara

unread,
Jul 15, 2009, 5:36:47 AM7/15/09
to turbo...@googlegroups.com
2009/7/15 cd34 <mcd...@gmail.com>:

> I think the problem here is that your application in
> myapp.controllers.root is looking for myapp.i18n for the messages for
> your entire application.  Even though you have imported your
> controller from myappext.myext, I believe the .po files in myapp.i18n
> are what is being checked.  I could be wrong, but, I am guessing this
> is the issue.

How should be supported translations of tw.apps and tgext.apps ?

>
> You should be able to test it by adding the respective lines from
> the .po file from myappext.i18n to the .pot and .po file in your
> language file and recompiling the catalog.
>
> If that is the case, you should be able to change setup.py so that it
> also searches your application in myappext for the catalogs and update
> the .po files for your language.

i'm going to test this, but i'd really love to find a better approach.

If there is any devel reading this mail i'd like to receive
suggestions from him, i'm even available to work on a patch if it's
needed.

--
Daniele Favara

cd34

unread,
Jul 15, 2009, 10:39:05 AM7/15/09
to TurboGears


On Jul 15, 5:36 am, Daniele Favara <no...@dsslive.org> wrote:
> 2009/7/15 cd34 <mcd...@gmail.com>:
>
> > I think the problem here is that your application in
> > myapp.controllers.root is looking for myapp.i18n for the messages for
> > your entire application.  Even though you have imported your
> > controller from myappext.myext, I believe the .po files in myapp.i18n
> > are what is being checked.  I could be wrong, but, I am guessing this
> > is the issue.
>
> How should be supported translations of tw.apps and tgext.apps ?

Where are your .po files for your translations for the controller
you've included?

myappext/i18n/

or are you calling myappext from a directory inside the virtual
environment where your structure is:

myappext/controllers
myappext/i18n

in that case, you would need to have the i18n translations beneath the
controller.

eggs that contain their own translations have a different directory
structure than an application.

Daniele Favara

unread,
Jul 17, 2009, 3:24:47 AM7/17/09
to turbo...@googlegroups.com
2009/7/15 cd34 <mcd...@gmail.com>:
> On Jul 15, 5:36 am, Daniele Favara <no...@dsslive.org> wrote:
>> 2009/7/15 cd34 <mcd...@gmail.com>:
>>
>> > I think the problem here is that your application in
>> > myapp.controllers.root is looking for myapp.i18n for the messages for
>> > your entire application.  Even though you have imported your
>> > controller from myappext.myext, I believe the .po files in myapp.i18n
>> > are what is being checked.  I could be wrong, but, I am guessing this
>> > is the issue.
>>
>> How should be supported translations of tw.apps and tgext.apps ?
>
> Where are your .po files for your translations for the controller
> you've included?
>
> myappext/i18n/

myappext/myext/i18n

>
> or are you calling myappext from a directory inside the virtual
> environment where your structure is:
>
> myappext/controllers
> myappext/i18n

myappext/myext/controllers
myappext/myext/i18n

> in that case, you would need to have the i18n translations beneath the
> controller.
>
> eggs that contain their own translations have a different directory
> structure than an application.

as a workaround i export_messages of myapext.myext to myapp, anyway
that's not exactly what i wanted.

> >
>



--
Daniele Favara
Reply all
Reply to author
Forward
0 new messages