Question

I have a PloneFormGen custom field-input validator whose user-feedback message I'd like to translate. How can I do this? I use a Python Script as validator, so in the example as given by the documentation...

if 'spam' in value.lower():
    return False
else:
    return "'%s' doesn't seem to have spam. Try again." % value

...how would I change to translate return "'%s' doesn't seem to have spam. Try again." % value to have it return the translated string?

I already have my own locales/de/LC_MESSAGES/myproduct.po file that I already use for translating page templates. I could just extend this file with some msgid and msgstr lines by hand. The validator currently lives as a Python Script in portal_skins/custom/ and was just quickly created Through The Web (TTW) but I could also move it my product if definitely necessary.

I've read http://developer.plone.org/i18n/internationalisation.html, but this page is so overwhelming and referring to all kinds of types and versions that I still do not know how to do it for this very purpose. I use Plone 4.3.

Was it helpful?

Solution

Translation via locale files might be possible, but might require writing a browser view so that you can get access to the message factory machinery.

But if you don't need that you could try simply embedding the translations in the script and testing request.LANGUAGE to determine the response.

if request.LANGUAGE == 'en-us':
    return "Try again yank!"
elif REQUEST.LANGUAGE ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top