How can I override translations on a plone 4 instance basis
I have a zope instance with many plone sites each for different customers. I want override particular translations such as the date format just for a single plone site without affecting the others. How do I do this?
Tutorials such as http://maurits.vanrees.org/weblog/archive/2010/10/i18n-plone-4#overriding-translations seem to indicate custom translations overri开发者_如何学Gode all sites on a zope instance.
This is how I solved it. It's a bit of a hack solution but it worked for my particular scenario.
As per http://maurits.vanrees.org/weblog/archive/2010/10/i18n-plone-4#overriding-translations I
- created my own locales package.
- overrode the the plonelocales domain just for one particular language variant, in this case en_AU.
- loaded the package in zope via buildout with particular attention to make sure it's the first ZCML slug (not instructions in the blog post incorrectly state it must be the first package in the egg section. This wasn't enough to make it work for me).
- for each site I wanted to switch date formats I went to site setup > Languages and switch the language to "English (Australian)".
The other gotcha is that when releasing and deploying your locales package make sure that you've
- generated the the .mo file first (done for you if you run zope locally)
- and you've used an MANIFEST.in file to tell setuptools to include all .mo files as you shouldn't put .mo files under source control and by default setuptools only includes files under source control.
This does not get me a custom date format for every single site but good enough if the custom date format you want is actually that of the language variant you choose to use.
You can implement your own zope.i18n.interfaces.ITranslationDomain utility which looks up translations in a different place. The normal translation domain utilities stores a list of gettext message catalogs. Those are loaded from mo files on the file system and registered with ZCML.
But you can implement a different translation domain, store it as a persistent utility per site and give it some additional storage to look up messages in.
精彩评论