473,662 Members | 2,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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@e uro

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 3936
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.setlocal e(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.setlocal e(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.setloc ale(locale.LC_A LL)
gettext.insta ll('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.setlo cale(locale.LC_ ALL)
gettext.inst all('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 "FilesForTr ans" 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 "FilesForTr ans"
---- 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.p y

Aug 8 '05 #10

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

Similar topics

0
1913
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 to create messages.mo and messages.po files. I've created all directories under a 'locale' root directory
1
3625
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 0.14.1, will using PHP's gettext support along with the GNU gettext utilities work properly? For example, I've seen references to the translated strings in .mo files not always being what appears
1
1288
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 localization to its liking, mine will change it again upon (re)loading, and everyone is happy, as far as I'm concirned :) The problem I'm facing now is this:
14
2612
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 gettext.install() to install the special _ function inside Python builtin. Other modules, taken from a general purpose collection of Python modules, also support internationalisation and doctest testing. For example:
1
2154
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 comments can be captured into the .po (.pot?) file for translators' benefit: /* Comment right before the gettext call, obviously in C */ printf(_("Apparently ambiguous string to translate"));
0
1287
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 should be working. Here follows a minimal example that should be working, but isn't (gettext and msgfmt are the normal GNU gettext tools): $ cat foo.php #! /usr/bin/php <?php bindtextdomain($argv, $_ENV);
1
3240
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 right. * http://docs.python.org/lib/node738.html Here's what I finally came up with as the simplest instructions, suitable for an "overview of Python programming" class: Start with the venerable "Hello, World!" program ... slightly modified
6
2021
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 & properties import gettext fr = gettext.translation('i18n_test', './translations',
2
4420
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 apt-get install php-gettext apt-get install php5-cli apt-get install php5 php5-common
0
8857
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8546
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7367
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5654
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1752
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.