===================
Schema translations
===================

>>> import zope.interface
>>> import zope.schema
>>> from zope.annotation.interfaces import IAttributeAnnotatable
>>> class IFoo(zope.interface.Interface):
...     text = zope.schema.Text(title=u'foo text')
>>> class Foo(object):
...     zope.interface.implements(IFoo)
...     text = u'original'
>>> foo = Foo()

Direct translation
==================

>>> from gocept.schematranslation.translation import Translation
>>> t = Translation()
>>> bar = t.translate(foo, IFoo, lang='en')
Traceback (most recent call last):
KeyError: 'clsid'
>>> IFoo.setTaggedValue('clsid', 'foo')

>>> bar = t.translate(foo, IFoo, lang='en')
Traceback (most recent call last):
TypeError: ('Could not adapt', <Foo object at 0x...>,
            <InterfaceClass zope.annotation.interfaces.IAnnotations>)
>>> zope.interface.classImplements(Foo, IAttributeAnnotatable)

>>> bar = t.translate(foo, IFoo)
>>> bar is foo
True

>>> bar = t.translate(foo, IFoo, lang='en')
>>> IFoo.providedBy(bar)
True
>>> bar is foo
False

>>> bar.text
u'original'
>>> bar.text = u'english'
>>> bar.text
u'english'
>>> foo.text
u'original'


Translation interfaces
======================

>>> IEnglishFoo = t.interface(IFoo, lang='en')
>>> IEnglishFoo
<InterfaceClass gocept.schematranslation.translation.__generated__.__builtin__.IFooEN>
>>> IEnglishFoo.extends(IFoo)
True

>>> foo_en = IEnglishFoo(foo)
>>> foo_en
<gocept.schematranslation.translation.TranslatedObject object at 0x...>
>>> IEnglishFoo.providedBy(foo_en)
True
>>> IFoo.providedBy(foo_en)
True

>>> foo_en.text
u'english'
