Localisation

François Granger fgranger at alussinan.org
Sun Jan 13 17:37:31 EST 2002


Martin v. Loewis <martin at v.loewis.de> wrote:

> fgranger at alussinan.org (=?ISO-8859-1?Q?Fran=E7ois_Granger?=) writes:
> 
> > I do a program which need lists of strings. These strings will be
> > different according to the choosen language.
> 
> I'd recommend to use gettext for that, see
> 
> http://www.python.org/doc/current/lib/module-gettext.html

Sorry, I was not precise enought. In fact it is a structure where there
are a mix of texts and integers in tuple format.

I try to import them directly as variables.

>From fr.comp.python, I got the following code wich is close to what I
want (and need just a little clean up):

import string

def my_import(name):
    mod = __import__(name)
    components = string.split(name, '.')
    for comp in components[1:]:
        mod = getattr(mod, comp)
    return mod

language = "FR"
modulePath = "lang.%s" % language
mod = my_import(modulePath)

wordNumeralMap = getattr(mod, "wordNumeralMap")
print wordNumeralMap


-- 
rmd> Ouaip, plus bete que ca, ca s'arrose deux fois par semaine.
pH> C'est pas gentil pour les plantes. Elles, elles  peuvent être
pH> décoratives, utiles et comestibles.
- trouvé sur Usenet



More information about the Python-list mailing list