Re: Internationalization with gettext
James Abbatiello <[email protected]> Thu, 20 Jan 2011 01:27:08 -0500
| Newsgroups | gmane.comp.python.cheetah |
|---|---|
| Message-ID | <[email protected]> |
--===============1898902015744847227==
Content-Type: multipart/alternative; boundary=000e0cd327141dfcd3049a413992
--000e0cd327141dfcd3049a413992
Content-Type: text/plain; charset=ISO-8859-1
If you want to include arbitrary Python code try using #silent like this:
#import gettext
#silent t = gettext.translation('mymodule', '/home/alec/gettexttest',
('en-US',))
#silent _ = t.gettext
$_("This is some text")
--
James Abbatiello
On Thu, Jan 20, 2011 at 1:09 AM, Alec Matusis <[email protected]> wrote:
> That did not help.
> Earlier, I also tried to define function _() like so:
>
> #import gettext
> #t = gettext.translation('mymodule', '/home/alec/gettexttest', ('en-US',))
> #_ = t.gettext
>
> This code works in a stand-alone .py file.
> Cheetah however still does not find _() function, even with this code at
> the
> top.
>
>
>
> From: James Abbatiello [mailto:[email protected]]
> Sent: Wednesday, January 19, 2011 7:24 PM
> To: [email protected]
> Subject: Re: [Cheetahtemplate-discuss] Internationalization with gettext
>
> I've never used gettext with Cheetah but perhaps including a line like:
> #from gettext import gettext as _
>
> at the top of your template might help?
>
> --
> James Abbatiello
> On Wed, Jan 19, 2011 at 5:57 PM, Alec Matusis <[email protected]> wrote:
> We're trying to translate our templates using Python's gettext module.
>
> >From reading
>
> http://www.cheetahtemplate.org/docs/users_guide_html_multipage/tips.gettext.
> html<http://www.cheetahtemplate.org/docs/users_guide_html_multipage/tips.gettext.%0Ahtml>
> it appears that I need to mark text for translation like this:
>
> $_("This text will be translated")
> or like this
> $ngettext("This text will be translated")
>
> The templates with marked text compile. Running xgettext (or pygettext.py )
> on the compiled template successfully creates the .pot files, but the files
> does not contain the marked strings.
>
> Also, running the template produces the following error:
>
> File
>
> "/usr/local/lib/python2.4/site-packages/Cheetah-2.4.4-py2.4-linux-i686.egg/C
> heetah/NameMapper.py", line 246, in valueFromSearchList
> _raiseNotFoundException(key, searchList)
> File
>
> "/usr/local/lib/python2.4/site-packages/Cheetah-2.4.4-py2.4-linux-i686.egg/C
> heetah/NameMapper.py", line 167, in _raiseNotFoundException
> raise NotFound(excString)
> NotFound: cannot find '_'
>
> which means it cannot find _() function.
> Can anybody show me how to mark text for translation?
>
> I am using Cheetah 2.4.4 for these tests. We have Cheetah 0.9.15 in
> production, but I believe that 0.9.15 does not have gettext functionality
> at
> all- is that correct?
>
>
>
> ----------------------------------------------------------------------------
> --
> Protect Your Site and Customers from Malware Attacks
> Learn about various malware tactics and how to avoid them. Understand
> malware threats, the impact they can have on your business, and how you
> can protect your company and customers by using code signing.
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> Cheetahtemplate-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
>
>
>
--000e0cd327141dfcd3049a413992
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
If you want to include arbitrary Python code try using #silent like this:<b=
r><br>#import gettext<br>#silent t =3D gettext.translation('mymodule=
9;, '/home/alec/gettexttest', ('en-US',))<br>#silent _ =3D =
t.gettext<br>
$_("This is some text")<br><br>-- <br>James Abbatiello<br><br><br=
><div class=3D"gmail_quote">On Thu, Jan 20, 2011 at 1:09 AM, Alec Matusis <=
span dir=3D"ltr"><<a href=3D"mailto:[email protected]">matusis@matusis=
.com</a>></span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex;">That did not help.<br>
Earlier, I also tried to define function _() like so:<br>
<br>
#import gettext<br>
#t =3D gettext.translation('mymodule', '/home/alec/gettexttest&=
#39;, ('en-US',))<br>
#_ =3D t.gettext<br>
<br>
This code works in a stand-alone .py file.<br>
Cheetah however still does not find _() function, even with this code at th=
e<br>
top.<br>
<br>
<br>
<br>
From: James Abbatiello [mailto:<a href=3D"mailto:[email protected]">abbeyj@g=
mail.com</a>]<br>
Sent: Wednesday, January 19, 2011 7:24 PM<br>
To: <a href=3D"mailto:[email protected]">cheeta=
[email protected]</a><br>
Subject: Re: [Cheetahtemplate-discuss] Internationalization with gettext<br=
>
<div><div></div><div class=3D"h5"><br>
I've never used gettext with Cheetah but perhaps including a line like:=
<br>
#from gettext import gettext as _<br>
<br>
at the top of your template might help?<br>
<br>
--<br>
James Abbatiello<br>
On Wed, Jan 19, 2011 at 5:57 PM, Alec Matusis <<a href=3D"mailto:matusis=
@matusis.com">[email protected]</a>> wrote:<br>
We're trying to translate our templates using Python's gettext modu=
le.<br>
<br>
>From reading<br>
<a href=3D"http://www.cheetahtemplate.org/docs/users_guide_html_multipage/t=
ips.gettext.%0Ahtml" target=3D"_blank">http://www.cheetahtemplate.org/docs/=
users_guide_html_multipage/tips.gettext.<br>
html</a><br>
it appears that I need to mark text for translation like this:<br>
<br>
$_("This text will be translated")<br>
or like this<br>
$ngettext("This text will be translated")<br>
<br>
The templates with marked text compile. Running xgettext (or pygettext.py )=
<br>
on the compiled template successfully creates the .pot files, but the files=
<br>
does not contain the marked strings.<br>
<br>
Also, running the template produces the following error:<br>
<br>
=A0File<br>
"/usr/local/lib/python2.4/site-packages/Cheetah-2.4.4-py2.4-linux-i686=
.egg/C<br>
heetah/NameMapper.py", line 246, in valueFromSearchList<br>
=A0 =A0_raiseNotFoundException(key, searchList)<br>
=A0File<br>
"/usr/local/lib/python2.4/site-packages/Cheetah-2.4.4-py2.4-linux-i686=
.egg/C<br>
heetah/NameMapper.py", line 167, in _raiseNotFoundException<br>
=A0 =A0raise NotFound(excString)<br>
NotFound: cannot find '_'<br>
<br>
which means it cannot find _() function.<br>
Can anybody show me how to mark text for translation?<br>
<br>
I am using Cheetah 2.4.4 for these tests. We have Cheetah 0.9.15 in<br>
production, but I believe that 0.9.15 does not have gettext functionality a=
t<br>
all- is that correct?<br>
<br>
<br>
---------------------------------------------------------------------------=
-<br>
--<br>
Protect Your Site and Customers from Malware Attacks<br>
Learn about various malware tactics and how to avoid them. Understand<br>
malware threats, the impact they can have on your business, and how you<br>
can protect your company and customers by using code signing.<br>
<a href=3D"http://p.sf.net/sfu/oracle-sfdevnl" target=3D"_blank">http://p.s=
f.net/sfu/oracle-sfdevnl</a><br>
_______________________________________________<br>
Cheetahtemplate-discuss mailing list<br>
<a href=3D"mailto:[email protected]">Cheetahtem=
[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-dis=
cuss" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/cheeta=
htemplate-discuss</a><br>
<br>
<br>
</div></div></blockquote></div><br>
--000e0cd327141dfcd3049a413992--
--===============1898902015744847227==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
--===============1898902015744847227==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Cheetahtemplate-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
--===============1898902015744847227==--