473,324 Members | 2,501 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,324 software developers and data experts.

i18n

Hello,
I have a problem trying to internationalize a simple file in Python.



the main folder is called "simple"

here is the file:

hello.py
------------------------------------
Expand|Select|Wrap|Line Numbers
  1. import os,sys
  2. import gettext
  3.  
  4. #i18n
  5. pathname = os.path.dirname(sys.argv[0])
  6. localedir = os.path.abspath(pathname) + "\locale"
  7. gettext.install("messages", localedir, unicode=1)
  8.  
  9. print gettext
  10. print pathname
  11. print localdir
  12. print gettext.install("messages", localedir, unicode=1)
  13.  
  14. print _("hello")
  15.  
  16. print _("Nice to meet you")
  17. ---------------------------------------

the result is:

<module 'gettext' from 'C:\Python24\lib\gettext.pyc'>
C:\Documents and Settings\Alex\Bureau\simple
C:\Documents and Settings\Alex\Bureau\simple\locale
None
hello
Nice to meet you

### It looks like it doesn't install anything! but why?






my "messages.po"/"messages.mo" are in folders like these:

\simple\locale\en_GB\LC_MESSAGES
\simple\locale\fr_FR\LC_MESSAGES





###here is an example of my po file

-----------------------------------------------
# French translations for PACKAGE package.
# Copyright (C) 2007 ORGANIZATION
# Alex <EMAIL@ADDRESS>, 2007.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2007-07-19 09:45+Paris, Madrid (heure d'été)\n"
"PO-Revision-Date: 2007-07-19 09:52+0200\n"
"Last-Translator: Alex <EMAIL@ADDRESS>\n"
"Language-Team: French\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CP1252\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"

#: C:\Documents and Settings\Alex\Bureau\simple\hello.py:14
msgid "hello"
msgstr "Salut"

#: C:\Documents and Settings\Alex\Bureau\simple\hello.py:16
msgid "Nice to meet you"
msgstr "Heureux de faire votre connaissance"
---------------------------------------------

(I am runnnig Windows XP)

I am on it for 3 days now , and I don't know what to do.

It would be wondeful if someone could have an idea or advice about this.
thx
Alex
Jul 19 '07 #1
5 2009
ilikepython
844 Expert 512MB
Hello,
I have a problem trying to internationalize a simple file in Python.



the main folder is called "simple"

here is the file:

hello.py
------------------------------------
import os,sys
import gettext

#i18n
pathname = os.path.dirname(sys.argv[0])
localedir = os.path.abspath(pathname) + "\locale"
gettext.install("messages", localedir, unicode=1)

print gettext
print pathname
print localdir
print gettext.install("messages", localedir, unicode=1)

print _("hello")

print _("Nice to meet you")
---------------------------------------


the result is:

<module 'gettext' from 'C:\Python24\lib\gettext.pyc'>
C:\Documents and Settings\Alex\Bureau\simple
C:\Documents and Settings\Alex\Bureau\simple\locale
None
hello
Nice to meet you

### It looks like it doesn't install anything! but why?






my "messages.po"/"messages.mo" are in folders like these:

\simple\locale\en_GB\LC_MESSAGES
\simple\locale\fr_FR\LC_MESSAGES





###here is an example of my po file

-----------------------------------------------
# French translations for PACKAGE package.
# Copyright (C) 2007 ORGANIZATION
# Alex <EMAIL@ADDRESS>, 2007.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2007-07-19 09:45+Paris, Madrid (heure d'été)\n"
"PO-Revision-Date: 2007-07-19 09:52+0200\n"
"Last-Translator: Alex <EMAIL@ADDRESS>\n"
"Language-Team: French\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CP1252\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: pygettext.py 1.5\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"

#: C:\Documents and Settings\Alex\Bureau\simple\hello.py:14
msgid "hello"
msgstr "Salut"

#: C:\Documents and Settings\Alex\Bureau\simple\hello.py:16
msgid "Nice to meet you"
msgstr "Heureux de faire votre connaissance"
---------------------------------------------

(I am runnnig Windows XP)

I am on it for 3 days now , and I don't know what to do.

It would be wondeful if someone could have an idea or advice about this.
thx
Alex
You are printing the return value of gettext.install(), which is None. Is that why you think it is not intalling anything?
Jul 19 '07 #2
You are printing the return value of gettext.install(), which is None. Is that why you think it is not intalling anything?
In fact, it does not change "hello" into "Salut" as it was supposed to do and this is the real problem (and I don't find why it doesn't work...)

Alex
Jul 19 '07 #3
bartonc
6,596 Expert 4TB
As my friend, ilikepython, points out, the fuction
install( domain[, localedir[, unicode [, codeset]]])
does not have a return value, so None is correctly printed. The docs don't say what happens if you leave out the 'codeset' parameter. My guess is that you are missing a step somewhere. I'd study it more myself, if I had the time. I simply don't have the time at the moment.
Jul 19 '07 #4
I finaly did it:


---------------------
Expand|Select|Wrap|Line Numbers
  1. import os,sys
  2. import gettext
  3.  
  4. class toto(object):
  5.  
  6.     def traduction( self ):
  7.  
  8.         #i18n
  9.         pathname = os.path.dirname(sys.argv[0])
  10.         localedir = os.path.abspath(pathname) + "\locale"
  11.  
  12.         gettext.install('messages', localedir, unicode=True)
  13.  
  14.         self.presLan_fr = gettext.translation("messages", localedir, languages=['fr_FR'])
  15.  
  16.         self.presLan_fr.install()
  17.  
  18.         print gettext
  19.         print pathname
  20.         print localedir
  21.         print self.presLan_fr
  22.         print self.presLan_fr.install()
  23.  
  24.         print _("hello")
  25.  
  26.         print _("Nice to meet you")
-----------------------------------------------

that works fine:


>>> a=toto()
>>> a.traduction()
<module 'gettext' from 'C:\Python24\lib\gettext.pyc'>
C:\Documents and Settings\Alex\Bureau\simple
C:\Documents and Settings\Alex\Bureau\simple\locale
<gettext.GNUTranslations instance at 0x012655F8>
None
Salut
Ravi de faire votre connaissance
Jul 20 '07 #5
bartonc
6,596 Expert 4TB
Alright! Now we can see how it's done. Thank you.
Jul 20 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: ProgDario | last post by:
HI, I downloaded and installed the I18N pear package, but the link on the doc referring to the DB is broken. Where can I find the I18N DB? Without it I can't make it work! Thanks in...
4
by: Logan | last post by:
Is it possible to tell the wxPython widgets (e.g. file dialogs) to use another language (instead of English)? Thanks in advance for any hints! -- mailto: logan@phreaker(NoSpam).net
10
by: Albretch | last post by:
.. Can you define the Character Set for particular tables instead of databases? . Which DBMSs would let you do that? . How do you store in a DBMS i18n'ed users' from input, coming over the web...
13
by: Guido Wesdorp | last post by:
Hi! I've just released a JavaScript library to allow internationalizing JavaScript code and/or to do HTML translation from JavaScript. It's a first release, and it doesn't have all the features...
0
by: Laszlo Zsolt Nagy | last post by:
Hello, I wonder if there is a standard for making i18n in Python projects. I have several Python projects that are internationalized. I also have Python packages with i18n. But it is still not...
3
by: Darren Davison | last post by:
Hi, I have a documentation tool based on Java and XSLT that I want to add i18n capability to. There are around 8 stylesheets that process a Source generated by the Java code and some of the...
8
by: Alan J. Flavell | last post by:
OK, I guess I'm about ready to expose this page for public discussion: http://ppewww.ph.gla.ac.uk/~flavell/charset/i18n-weft.html Please concentrate on the content. I'm well aware that my old...
0
by: i18n-bounces | last post by:
Your mail to 'I18n' with the subject Mail Delivery (failure i18n@mova.org) Is being held until the list moderator can review it for approval. The reason it is being held: Post by...
3
by: fyleow | last post by:
I just spent hours trying to figure out why even after I set my SQL table attributes to UTF-8 only garbage kept adding into the database. Apparently you need to execute "SET NAMES 'utf8'" before...
8
by: CptDondo | last post by:
I have a small, embedded app that uses a webserver to serve up pages showing status, etc. Right now all the pages are hard-coded in English. We need to provide multi-lingual support. All of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.