Gregor Horvath schrieb:
> 
> The problem is that as long as I understand there is one message.mo file
> for a TG project. This includes the costum messages of a TG Project. Now
> I have a FormEncode.mo for the Formencode validators messages (and
> probably another Validators.mo or similar for TG's validators). How can
> I merge those files, or how can TG's translation function be instructed
> to use all *.mo files instead just the messages.mo?
> 
> Is there a mechansim I am not aware of or has this to be done?
> 

I checked the TG source and did not find a standard way, except that it
is possible to give the domain (and with it the filename
                     ) to the gettext function.

Therefore it is possible to create a message.mo file for the costum
messages of a specific TG Project (no change in this process), and in
the same directory (locales) a FormEncode.mo which includes the
translations of the standard FormEncode messages and a TG.mo for TG's
standard validator messages.
TG should install FormEncode.mo and TG.mo automatically with tg-admin
quickstart.

To enable this there must be a way of telling FormEncode to call TG's
gettext function with the argument domain=FormEncode (so the
FormEncode.mo file is used for translation instead of the standard
messages.mo)

I therefore propose a new class attribute: formencode.Validator.gettextargs
For standalone FormEncode this attribute is {}. (Because standard
gettext function does not allow additional parameters)

<formencode.api.py>
class Validator(declarative.Declarative):
  [....]
  gettextargs = {}
  [...]

  def message(self, msgName, state, **kw):
        #determine translation function
        try:
            trans = state._
        except AttributeError:
            try:
                import __builtin__
                trans = __builtin__._
            except AttributeError:
                trans = _stdtrans

        try:
            return trans(self._messages[msgName], **self.gettextargs) % kw
        except KeyError, e:
            raise KeyError(
                "Key not found (%s) for %r=%r %% %r (from: %s)"
                % (e, msgName, self._messages.get(msgName), kw,
                   ', '.join(self._messages.keys())))

</formencode.api.py>


TG has to setup this argument in turbogears.validators.py:

<turbogears.validators.py>
....
from formencode.validators import *
....

Validator.gettextargs = {'domain':'FormEncode'}

</turbogears.validators.py>



Is this concept OK?

The protoype works.
If it's OK I am going to make a patch to TG's trunk and apply the
changes to http://svn.colorstudy.com/FormEncode/branches/gettext-enabled/

--
Greg



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to