Get rid of a deprecation warning by using the new immutable

i18n Messages. Made DummyEngine work with them.
parent 3d0c2bb1
...@@ -22,17 +22,6 @@ from TALDefs import NAME_RE, TALESError, ErrorInfo ...@@ -22,17 +22,6 @@ from TALDefs import NAME_RE, TALESError, ErrorInfo
from ITALES import ITALESCompiler, ITALESEngine from ITALES import ITALESCompiler, ITALESEngine
from DocumentTemplate.DT_Util import ustr from DocumentTemplate.DT_Util import ustr
IDomain = None
try:
from Zope2.I18n.ITranslationService import ITranslationService
from Zope2.I18n.IDomain import IDomain
except ImportError:
pass
if IDomain is None:
# Before 2.7, or not in Zope
class ITranslationService: pass
class IDomain: pass
class _Default: class _Default:
pass pass
Default = _Default() Default = _Default()
...@@ -234,7 +223,6 @@ class Iterator: ...@@ -234,7 +223,6 @@ class Iterator:
return 1 return 1
class DummyDomain: class DummyDomain:
__implements__ = IDomain
def translate(self, msgid, mapping=None, context=None, def translate(self, msgid, mapping=None, context=None,
target_language=None, default=None): target_language=None, default=None):
...@@ -246,8 +234,10 @@ class DummyDomain: ...@@ -246,8 +234,10 @@ class DummyDomain:
# things back together. # things back together.
# simulate an unknown msgid by returning None # simulate an unknown msgid by returning None
text = msgid
if msgid == "don't translate me": if msgid == "don't translate me":
text = default if default is not None:
text = default
else: else:
text = msgid.upper() text = msgid.upper()
...@@ -257,7 +247,6 @@ class DummyDomain: ...@@ -257,7 +247,6 @@ class DummyDomain:
return cre.sub(repl, text) return cre.sub(repl, text)
class DummyTranslationService: class DummyTranslationService:
__implements__ = ITranslationService
def translate(self, domain, msgid, mapping=None, context=None, def translate(self, domain, msgid, mapping=None, context=None,
target_language=None, default=None): target_language=None, default=None):
......
...@@ -28,7 +28,7 @@ from TAL.TALInterpreter import TALInterpreter ...@@ -28,7 +28,7 @@ from TAL.TALInterpreter import TALInterpreter
from TAL.DummyEngine import DummyEngine, DummyTranslationService from TAL.DummyEngine import DummyEngine, DummyTranslationService
from TAL.TALInterpreter import interpolate from TAL.TALInterpreter import interpolate
from TAL.tests import utils from TAL.tests import utils
from zope.i18nmessageid import MessageID from zope.i18nmessageid import Message
class TestCaseBase(unittest.TestCase): class TestCaseBase(unittest.TestCase):
...@@ -67,10 +67,10 @@ class I18NCornerTestCase(TestCaseBase): ...@@ -67,10 +67,10 @@ class I18NCornerTestCase(TestCaseBase):
def setUp(self): def setUp(self):
self.engine = DummyEngine() self.engine = DummyEngine()
self.engine.setLocal('foo', MessageID('FoOvAlUe', 'default')) self.engine.setLocal('foo', Message('FoOvAlUe', 'default'))
self.engine.setLocal('bar', 'BaRvAlUe') self.engine.setLocal('bar', 'BaRvAlUe')
self.engine.setLocal('raw', ' \tRaW\n ') self.engine.setLocal('raw', ' \tRaW\n ')
self.engine.setLocal('noxlt', MessageID("don't translate me")) self.engine.setLocal('noxlt', Message("don't translate me"))
def _check(self, program, expected): def _check(self, program, expected):
result = StringIO() result = StringIO()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment