[Checkins] SVN: zope.i18n/trunk/ Feature: Re-use existing
translation domains when registering new ones. This allows
multiple packages to register translations in the same
domain. If the same message exists in multiple catalogs the
one registered first will take precedence. As an example this
allows the messages from the zope domain to be spread across
distinct files in various packages.
Hanno Schlichting
plone at hannosch.info
Sat Apr 26 05:24:18 EDT 2008
Log message for revision 85753:
Feature: Re-use existing translation domains when registering new ones. This allows multiple packages to register translations in the same domain. If the same message exists in multiple catalogs the one registered first will take precedence. As an example this allows the messages from the zope domain to be spread across distinct files in various packages.
Changed:
U zope.i18n/trunk/CHANGES.txt
A zope.i18n/trunk/src/zope/i18n/tests/locale2/
D zope.i18n/trunk/src/zope/i18n/tests/locale2/en/LC_MESSAGES/__init__.py
U zope.i18n/trunk/src/zope/i18n/tests/locale2/en/LC_MESSAGES/zope-i18n.mo
U zope.i18n/trunk/src/zope/i18n/tests/locale2/en/LC_MESSAGES/zope-i18n.po
D zope.i18n/trunk/src/zope/i18n/tests/locale2/en/__init__.py
U zope.i18n/trunk/src/zope/i18n/tests/test_zcml.py
U zope.i18n/trunk/src/zope/i18n/zcml.py
-=-
Modified: zope.i18n/trunk/CHANGES.txt
===================================================================
--- zope.i18n/trunk/CHANGES.txt 2008-04-26 09:22:31 UTC (rev 85752)
+++ zope.i18n/trunk/CHANGES.txt 2008-04-26 09:24:18 UTC (rev 85753)
@@ -5,6 +5,11 @@
3.4.1 (unreleased)
------------------
+- Feature: Re-use existing translation domains when registering new ones.
+ This allows multiple packages to register translations in the same domain.
+ If the same message exists in multiple catalogs the one registered first
+ will take precedence.
+
- Feature: Recursive translations of message strings with mappings
(https://bugs.launchpad.net/zope3/+bug/210177), thanks to Hermann
Himmelbauer for the inital patch.
Copied: zope.i18n/trunk/src/zope/i18n/tests/locale2 (from rev 85741, zope.i18n/trunk/src/zope/i18n/tests/locale)
Deleted: zope.i18n/trunk/src/zope/i18n/tests/locale2/en/LC_MESSAGES/__init__.py
===================================================================
--- zope.i18n/trunk/src/zope/i18n/tests/locale/en/LC_MESSAGES/__init__.py 2008-04-26 07:46:02 UTC (rev 85741)
+++ zope.i18n/trunk/src/zope/i18n/tests/locale2/en/LC_MESSAGES/__init__.py 2008-04-26 09:24:18 UTC (rev 85753)
@@ -1,2 +0,0 @@
-#
-# This file is necessary to make this directory a package.
Modified: zope.i18n/trunk/src/zope/i18n/tests/locale2/en/LC_MESSAGES/zope-i18n.mo
===================================================================
(Binary files differ)
Modified: zope.i18n/trunk/src/zope/i18n/tests/locale2/en/LC_MESSAGES/zope-i18n.po
===================================================================
--- zope.i18n/trunk/src/zope/i18n/tests/locale/en/LC_MESSAGES/zope-i18n.po 2008-04-26 07:46:02 UTC (rev 85741)
+++ zope.i18n/trunk/src/zope/i18n/tests/locale2/en/LC_MESSAGES/zope-i18n.po 2008-04-26 09:24:18 UTC (rev 85753)
@@ -1,15 +1,14 @@
msgid ""
msgstr ""
"Project-Id-Version: Zope 3\n"
-"PO-Revision-Date: 2002/06/13\n"
+"PO-Revision-Date: 2008/04/26\n"
"Last-Translator: Zope 3 contributors\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=ISO-8859-1\n"
"Content-Transfer-Encoding: 8bit\n"
-msgid "New Domain"
-msgstr "New Domain"
+msgid "Additional message"
+msgstr "Additional message translated"
msgid "New Language"
-msgstr "New Language"
-
+msgstr "New Language translated differently"
Deleted: zope.i18n/trunk/src/zope/i18n/tests/locale2/en/__init__.py
===================================================================
--- zope.i18n/trunk/src/zope/i18n/tests/locale/en/__init__.py 2008-04-26 07:46:02 UTC (rev 85741)
+++ zope.i18n/trunk/src/zope/i18n/tests/locale2/en/__init__.py 2008-04-26 09:24:18 UTC (rev 85753)
@@ -1,2 +0,0 @@
-#
-# This file is necessary to make this directory a package.
Modified: zope.i18n/trunk/src/zope/i18n/tests/test_zcml.py
===================================================================
--- zope.i18n/trunk/src/zope/i18n/tests/test_zcml.py 2008-04-26 09:22:31 UTC (rev 85752)
+++ zope.i18n/trunk/src/zope/i18n/tests/test_zcml.py 2008-04-26 09:24:18 UTC (rev 85753)
@@ -51,6 +51,39 @@
self.assertEquals(util._catalogs,
{'test': ['test'], 'en': [unicode(path)]})
+ def testRegisterDistributedTranslations(self):
+ self.assert_(zope.component.queryUtility(ITranslationDomain) is None)
+ xmlconfig.string(
+ template % '''
+ <configure package="zope.i18n.tests">
+ <i18n:registerTranslations directory="locale" />
+ </configure>
+ ''', self.context)
+ xmlconfig.string(
+ template % '''
+ <configure package="zope.i18n.tests">
+ <i18n:registerTranslations directory="locale2" />
+ </configure>
+ ''', self.context)
+ path1 = os.path.join(os.path.dirname(zope.i18n.tests.__file__),
+ 'locale', 'en', 'LC_MESSAGES', 'zope-i18n.mo')
+ path2 = os.path.join(os.path.dirname(zope.i18n.tests.__file__),
+ 'locale2', 'en', 'LC_MESSAGES', 'zope-i18n.mo')
+ util = zope.component.getUtility(ITranslationDomain, 'zope-i18n')
+ self.assertEquals(util._catalogs,
+ {'test': ['test', 'test'],
+ 'en': [unicode(path1), unicode(path2)]})
+
+ msg = util.translate(u'Additional message', target_language='en')
+ self.assertEquals(msg, u'Additional message translated')
+
+ msg = util.translate(u'New Domain', target_language='en')
+ self.assertEquals(msg, u'New Domain translated')
+
+ msg = util.translate(u'New Language', target_language='en')
+ self.assertEquals(msg, u'New Language translated')
+
+
def test_suite():
return unittest.makeSuite(DirectivesTest)
Modified: zope.i18n/trunk/src/zope/i18n/zcml.py
===================================================================
--- zope.i18n/trunk/src/zope/i18n/zcml.py 2008-04-26 09:22:31 UTC (rev 85752)
+++ zope.i18n/trunk/src/zope/i18n/zcml.py 2008-04-26 09:24:18 UTC (rev 85753)
@@ -25,6 +25,7 @@
from zope.i18n.testmessagecatalog import TestMessageCatalog
from zope.i18n.translationdomain import TranslationDomain
from zope.i18n.interfaces import ITranslationDomain
+from zope.component import queryUtility
from zope.component.zcml import utility
class IRegisterTranslationsDirective(Interface):
@@ -56,7 +57,10 @@
# Now create TranslationDomain objects and add them as utilities
for name, langs in domains.items():
- domain = TranslationDomain(name)
+ # Try to get an existing domain and add catalogs to it
+ domain = queryUtility(ITranslationDomain, name)
+ if domain is None:
+ domain = TranslationDomain(name)
for lang, file in langs.items():
domain.addCatalog(GettextMessageCatalog(lang, name, file))
More information about the Checkins
mailing list