Re: [gDesklets] gettext



Jonathan MERCIER wrote:
> hi!
> i wantcreate a control for gettext someone can helpme please:
> 
> from libdesklets.controls import Control
> 
> from IGettext import IGettext
> 
> import gettext
> 
> class Gettext(Control, IGettext):
> 
>     def __init__(self):
> 
>     self.local_path = os.path.realpath(os.path.dirname(sys.argv[0]))
> 
>     langs = []
> 
>     lc, encoding = locale.getdefaultlocale()
>     if (lc):
>         langs = [lc]
> 
>     language = os.environ.get('LANGUAGE', None)
>     if (language):
>         langs += language.split(":")
>     langs += ["en_US", "fr_FR"]
> 
>     gettext.bindtextdomain(APP_NAME, self.local_path)
>     gettext.textdomain(APP_NAME)
> 
>     self.lang = gettext.translation(APP_NAME, self.local_path,
>         languages=langs, fallback = True)
> 
>     self.__tr = self.lang.gettext
> 
>      Control.__init__(self)
> 
>     tr        = property(__get_tr, __set_tr, doc = "Traduct the text to
> local language.\nuse, tr(\"text to translate\")")
> 
> 
> def get_class(): return Gettext

What's your question?  Off the bat it looks to me like you don't have
anything in the __init__() function, you don't have Gettext.__get_tr()
or __set_tr() functions, and the control is not initialized properly
(Control.__init__(self) should be in __init__()).  Mostly due to
improper spacing it looks like on my end.  Also, you'll need an
IGettext.py providing the interface like:

from libdesklets.controls import Interface, Permission

class IGettext(Interface):

    tr = Permission.READWRITE

And on a stylistic note, you probably shouldn't have the '\nuse,
tr(\"text to translate\")")' text.  It should be obvious from the
description and name of each property how they're used.  And since you
only have property interfaces, you'll need to set the text one way and
read it another (I'm not saying you couldn't use 'tr' for both, just
wanted to point out that you won't be able to use it as your doc
string indicates).

--
Joe


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]