473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

gettext again

Hi,
I'm failing to make it work but can't find out what's wrong. Here's what
I do :

================
test.py

import gettext
gettext.install('')

msg = _("Message without accented characters")

print msg
================

Then I do :

xgettext test.py

mv message.po message pot

msginit --> output message.fr_FR@euro

I edit my fr_FR@euro with this text :
msgid "This is a message without accented characters."
msgstr "Message avec caractères accentués : éèàùëêôîaâç"

Then msgfmt fr_FR@euro

Then python test.py shows "Message without accented characters"

How come ? What's wrong with what I am doing ?

Thanks for your help.
Aug 7 '05 #1
13 3911
On Sun, 07 Aug 2005 11:09:14 +0200, cantabile wrote:
Hi,
I'm failing to make it work but can't find out what's wrong. Here's what
I do : [....] How come ? What's wrong with what I am doing ?

Start with this little howto about gettext.
http://childsplay.sourceforge.net/translate-howto.html

And then do this in your test.py:
http://www.python.org/doc/2.4.1/lib/node330.html

You should read the part about gettext in the Python Library Reference
it's really good :-)

Good luck,
Stas Z
Aug 7 '05 #2
stasz a écrit :
On Sun, 07 Aug 2005 11:09:14 +0200, cantabile wrote:

Hi,
I'm failing to make it work but can't find out what's wrong. Here's what
I do :


[....]
How come ? What's wrong with what I am doing ?


Start with this little howto about gettext.
http://childsplay.sourceforge.net/translate-howto.html

And then do this in your test.py:
http://www.python.org/doc/2.4.1/lib/node330.html

You should read the part about gettext in the Python Library Reference
it's really good :-)

Good luck,
Stas Z


Well, I must be dumb, because I did exactly that and it still doesn't
work...

BTW, I have no pygettext module. I asked here and somebody said it was
deprecated and now included in xgettext.
And I've read the Python doc about gettext about ten times, but it seems
quite outdated since it calls pygettext (as staded above)...

I've read the info pages of gettext too (quite a long work).

Here's my test1.py file again :

===========================
import gettext, os, locale

locale.setlocale(locale.LC_ALL)
gettext.install('test1.py', '/usr/share/locale')

msg = _("This is a message without accented characters.")

print msg
===========================

What can I do now ?
Aug 7 '05 #3
On Sun, 07 Aug 2005 21:33:21 +0200, cantabile wrote:
stasz a écrit :
On Sun, 07 Aug 2005 11:09:14 +0200, cantabile wrote:

Hi,
I'm failing to make it work but can't find out what's wrong. Here's what
I do :
[....]
How come ? What's wrong with what I am doing ?


Start with this little howto about gettext.
http://childsplay.sourceforge.net/translate-howto.html

And then do this in your test.py:
http://www.python.org/doc/2.4.1/lib/node330.html

You should read the part about gettext in the Python Library Reference
it's really good :-)

Good luck,
Stas Z


Well, I must be dumb, because I did exactly that and it still doesn't
work...

BTW, I have no pygettext module. I asked here and somebody said it was
deprecated and now included in xgettext.
And I've read the Python doc about gettext about ten times, but it seems
quite outdated since it calls pygettext (as staded above)...

I've read the info pages of gettext too (quite a long work).

Ok, you should use xgettext to create a .po file from your test1.py.
Translate that file and use msgfmt to compile it into a .mo file.
Copy this .mo file to /usr/share/locale/fr/LC_MESSAGES/
Here's my test1.py file again :

===========================
import gettext, os, locale

locale.setlocale(locale.LC_ALL)
gettext.install('test1.py', '/usr/share/locale')

test1.py is wrong, you must give the name of the .mo file.
It must be: gettext.install('test1.mo', '/usr/share/locale')
Assuming you have called the mo file like that.

Stas Z
Aug 7 '05 #4
stasz a écrit :
On Sun, 07 Aug 2005 21:33:21 +0200, cantabile wrote:

stasz a écrit :
On Sun, 07 Aug 2005 11:09:14 +0200, cantabile wrote:

Hi,
I'm failing to make it work but can't find out what's wrong. Here's what
I do :

[....]
How come ? What's wrong with what I am doing ?

Start with this little howto about gettext.
http://childsplay.sourceforge.net/translate-howto.html

And then do this in your test.py:
http://www.python.org/doc/2.4.1/lib/node330.html

You should read the part about gettext in the Python Library Reference
it's really good :-)

Good luck,
Stas Z


Well, I must be dumb, because I did exactly that and it still doesn't
work...

BTW, I have no pygettext module. I asked here and somebody said it was
deprecated and now included in xgettext.
And I've read the Python doc about gettext about ten times, but it seems
quite outdated since it calls pygettext (as staded above)...

I've read the info pages of gettext too (quite a long work).


Ok, you should use xgettext to create a .po file from your test1.py.
Translate that file and use msgfmt to compile it into a .mo file.
Copy this .mo file to /usr/share/locale/fr/LC_MESSAGES/

Here's my test1.py file again :

===========================
import gettext, os, locale

locale.setlocale(locale.LC_ALL)
gettext.install('test1.py', '/usr/share/locale')


test1.py is wrong, you must give the name of the .mo file.
It must be: gettext.install('test1.mo', '/usr/share/locale')
Assuming you have called the mo file like that.

Stas Z


Well, I did this exactly... and still no go.

Is this sequence correct :
1° xgettext test1.py
2° mv messages.po messages.pot
3° msginit
4° Translate msgstr"" in fr***@euro.po file
5° msgfmt -o test1.mo fr***@euro.po
6° cp test1.mo /usr/share/locale/LC_MESSAGES
7° python test1.py
This is what I did, without success. Must be bewitched :((
Aug 8 '05 #5
On Mon, 08 Aug 2005 02:56:35 +0200, cantabile wrote:
stasz a écrit :
On Sun, 07 Aug 2005 21:33:21 +0200, cantabile wrote:

stasz a écrit :

On Sun, 07 Aug 2005 11:09:14 +0200, cantabile wrote:

>Hi,
>I'm failing to make it work but can't find out what's wrong. Here's what
>I do :

[....]
>How come ? What's wrong with what I am doing ?

Start with this little howto about gettext.
http://childsplay.sourceforge.net/translate-howto.html

And then do this in your test.py:
http://www.python.org/doc/2.4.1/lib/node330.html

You should read the part about gettext in the Python Library Reference
it's really good :-)

Good luck,
Stas Z

Well, I must be dumb, because I did exactly that and it still doesn't
work...

BTW, I have no pygettext module. I asked here and somebody said it was
deprecated and now included in xgettext.
And I've read the Python doc about gettext about ten times, but it seems
quite outdated since it calls pygettext (as staded above)...

I've read the info pages of gettext too (quite a long work).


Ok, you should use xgettext to create a .po file from your test1.py.
Translate that file and use msgfmt to compile it into a .mo file.
Copy this .mo file to /usr/share/locale/fr/LC_MESSAGES/

Here's my test1.py file again :

===========================
import gettext, os, locale

locale.setlocale(locale.LC_ALL)
gettext.install('test1.py', '/usr/share/locale')


test1.py is wrong, you must give the name of the .mo file.
It must be: gettext.install('test1.mo', '/usr/share/locale')
Assuming you have called the mo file like that.

Stas Z


Well, I did this exactly... and still no go.

Is this sequence correct :
1° xgettext test1.py
2° mv messages.po messages.pot
3° msginit
4° Translate msgstr"" in fr***@euro.po file
5° msgfmt -o test1.mo fr***@euro.po
6° cp test1.mo /usr/share/locale/LC_MESSAGES
7° python test1.py
This is what I did, without success. Must be bewitched :((

Your steps seems alright.
Just a thought; you do start test1.py from a fr_FR@euro
environment do you?
I mean in a xterm do: export LANG=fr_FR@euro
And then start test1.py from there.

Stas

Aug 8 '05 #6
stasz a écrit :
Your steps seems alright.
Just a thought; you do start test1.py from a fr_FR@euro
environment do you?
I mean in a xterm do: export LANG=fr_FR@euro
And then start test1.py from there.

Stas


Whoooot ! Working at last, after three days... It wasn't the LANG param
which is fr_FR@euro allright. I inadvertantly suppressed the '.mo' part
of gettext.install(test1.mo') and it just worked.
I guess gettext was looking for a 'test1.mo.mo' file or something.

Anyways, you made my day my friend !
Many many thanks !
Aug 8 '05 #7
BTW stasz,
Maybe you'll have still some time for the following question. Trying my
luck :))

Suppose I have several units (.py files), say test.py test1.py tets2.py
, test.py being my main file.
I've read I can import gettext and install in the main unit. Then, must
I create .po files for each unit or is there a way to make a single .po
file for the whole app. ?
Aug 8 '05 #8
On Mon, 08 Aug 2005 17:01:21 +0200, cantabile wrote:
stasz a écrit : Whoooot ! Working at last, after three days... It wasn't the LANG param [...] Anyways, you made my day my friend !
Many many thanks !

Your welcome :-)

Stas

Aug 8 '05 #9
On Mon, 08 Aug 2005 17:39:34 +0200, cantabile wrote:
BTW stasz,
Maybe you'll have still some time for the following question. Trying my
luck :))

Suppose I have several units (.py files), say test.py test1.py tets2.py
, test.py being my main file.
I've read I can import gettext and install in the main unit. Then, must
I create .po files for each unit or is there a way to make a single .po
file for the whole app. ?

Yes there is.

As a reminder, make sure that you install gettext in the namespace
of your toplevel module.
What I mean is this:

test1.py imports test2.py and test3.py
test2.py imports test4.py

Now you have to place the gettext.install call in test1.py and
then the other modules can access it.
If you place the gettext call in, for example, test2.py then only
test2.py and test4.py have access to it.
So when it don't work as you expect make sure to check if every
module has access to the "_" from gettext.

So now for your question about one po/mo file for multiple
modules.
I use this file for a project of mine it also includes some
explanation in case I forget it myself :-)
<shameless plug>
The project is called "Guido van Robot".
http://gvr.sf.net
</shameless plug>

The files mentioned inside this file are used in the above project
and serve as an example in this case.
You could replace the files with your own to try it.
The file itself is called "FilesForTrans" so you could put this
file together with your test modules inside a directory and follow
the instructions in side "FilesForTrans".

Stas Z
Contents of "FilesForTrans"
---- cut here ---------
## These files contain i18n strings
## Use: xgettext -f ./FilesForTrans -p /tmp
## The message.po will be located in /tmp
## Now do: msgmerge ./po/nl/gvr.po /tmp/messages.po > /tmp/new_nl.po
## compile the .po to mo (place the .po after editing in ./po/nl/)
## msgfmt ./po/nl/gvr.po -o ./locale/nl/LC_MESSAGES/gvr.mo

gvr.py
gvrparser.py
world.py
worldMap.py
Editorwindows.py

Aug 8 '05 #10
Ok, I'll try that.
Thanks again Stasz !
Aug 9 '05 #11
stas a écrit :
As a reminder, make sure that you install gettext in the namespace
of your toplevel module.
What I mean is this:

test1.py imports test2.py and test3.py
test2.py imports test4.py

Now you have to place the gettext.install call in test1.py and
then the other modules can access it.
If you place the gettext call in, for example, test2.py then only
test2.py and test4.py have access to it.
So when it don't work as you expect make sure to check if every
module has access to the "_" from gettext.

Noticed something :
I must import test2.py AFTER gettext.install('test1') and even then, if
test3.py imports test2.py, messages won't be translated in test3.py. I
have to import test3.py in test1.py too.
Is this normal behaviour or is there something I'm missing (again) ?

PS : your project looks nice !
Aug 9 '05 #12
On Tue, 09 Aug 2005 23:59:26 +0200, cantabile wrote:
stas a écrit :
As a reminder, make sure that you install gettext in the namespace
of your toplevel module.
[....] Noticed something :
I must import test2.py AFTER gettext.install('test1') and even then, if
test3.py imports test2.py, messages won't be translated in test3.py. I
have to import test3.py in test1.py too.
Is this normal behaviour or is there something I'm missing (again) ? Hmm, perhaps I missed something, namespaces can be sometimes hard
to get right.
Let's see:

test1 imports and installs gettext.
Now test1 holds the gettext reference.
test1 imports test2 and test3 and 'inherits' test1 namespace
test2 and test3 have access to test1 namespace and the gettext.

So in (pseudo) Python code test1 would looks like this:

import gettext
gettext.install(test)# assuming test.mo holds all the strings
import test2, test3

Another approach would be to place the whole gettext install stuff
in a separate module wrapped in a function which can be imported
by every module that wants language support.
(That's the approach I always use)

Contents of utils.py
(Code is not tested, it's to show the principals)

import locale, gettext
def set_gettext(mo_location='/usr/share/locale'):
locale.setlocale(locale.LC_ALL)
gettext.install('test1', mo_location)

Now in your modules you could do this:

In test1.py:
from utils import set_gettext
set_gettext()# remember gettext.install installs '_' in the
# current namespace, in this case test1.
import test2, test 3

In test4.py
from utils import set_gettext
set_gettext()
.....
.....

Now test1 and test2 get their gettext from test1 while test4 import
gettext from utils.py which installs the same mo file as it did in
test1, test2 and test3.
PS : your project looks nice !

Thanks.

BTW, the principal of gettext in utils.py is also implemented in
the gvr project, so you have a real life example there :-)

Stas

Aug 10 '05 #13
stasz a écrit :
On Tue, 09 Aug 2005 23:59:26 +0200, cantabile wrote:

stas a écrit :

As a reminder, make sure that you install gettext in the namespace
of your toplevel module.


[....]
Noticed something :
I must import test2.py AFTER gettext.install('test1') and even then, if
test3.py imports test2.py, messages won't be translated in test3.py. I
have to import test3.py in test1.py too.
Is this normal behaviour or is there something I'm missing (again) ?


Hmm, perhaps I missed something, namespaces can be sometimes hard
to get right.
Let's see:

test1 imports and installs gettext.
Now test1 holds the gettext reference.
test1 imports test2 and test3 and 'inherits' test1 namespace
test2 and test3 have access to test1 namespace and the gettext.

So in (pseudo) Python code test1 would looks like this:

import gettext
gettext.install(test)# assuming test.mo holds all the strings
import test2, test3

Another approach would be to place the whole gettext install stuff
in a separate module wrapped in a function which can be imported
by every module that wants language support.
(That's the approach I always use)

Contents of utils.py
(Code is not tested, it's to show the principals)

import locale, gettext
def set_gettext(mo_location='/usr/share/locale'):
locale.setlocale(locale.LC_ALL)
gettext.install('test1', mo_location)

Now in your modules you could do this:

In test1.py:
from utils import set_gettext
set_gettext()# remember gettext.install installs '_' in the
# current namespace, in this case test1.
import test2, test 3

In test4.py
from utils import set_gettext
set_gettext()
....
....

Now test1 and test2 get their gettext from test1 while test4 import
gettext from utils.py which installs the same mo file as it did in
test1, test2 and test3.

PS : your project looks nice !


Thanks.

BTW, the principal of gettext in utils.py is also implemented in
the gvr project, so you have a real life example there :-)

Stas

Thanks for the explanation, very clear, as usual.
Cheers :)
Aug 10 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Daniel CAUSSE | last post by:
Hello, I'm testing gettext on my website but it doesn't work. phpinfo returns correct informations: configure command => '--with-gettext=/usr' GetText Support => enabled I have no problem...
1
by: Dave Patton | last post by:
Can someone point me to a definitive source for the answers to the following two questions: 1) In an environment with Redhat Linux 2.4.21-27.0.1, Apache 1.3.31, PHP 4.3.10, and GNU gettext...
1
by: evanescent.lurker | last post by:
Hi gang, I was thinking about further localization of my app. There is a problem with gettext since it is not thread aware, but I don't mind it, since if any other page changes the...
14
by: Pierre Rouleau | last post by:
I have a problem writing self-testable modules using doctest when these modules have internationalized strings using gettext _('...'). - The main module of an application (say app.py) calls...
1
by: Terry Hancock | last post by:
I'm looking at the gettext module for the first time and learning how to write internationalized code in Python. Naturally, I also looked at the original Gnu gettext manual, which mentions that...
0
by: redhog | last post by:
I can not get gettext to work at all under PHP. I run ubuntu 6.06.1 LTS, and the php5 package there announces that it supports gettext. Also, php -i sais gettext GetText Support =enabled, so it...
1
by: James T. Dennis | last post by:
You'd think that using things like gettext would be easy. Superficially it seems well documented in the Library Reference(*). However, it can be surprisingly difficult to get the external details...
6
by: =?iso-8859-1?B?QW5kcuk=?= | last post by:
I've encountered a problem using gettext with properties while using a Python interpreter. Here's a simple program that illustrate the problem. ============== # i18n_test.py: test of gettext &...
2
by: paolob | last post by:
Hi to all, I'm running php 5.2.5 on Debian etch, with apache 2.0.56. I need to include, in php.ini, gettext.so library but I didn't find anything. I've already install: apt-get install gettext...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.