def setUp():
    portal = getSite()
    applyProfile(portal, 'plone.multilingualbehavior:default')

    language_tool = getToolByName(portal, 'portal_languages')
    language_tool.addSupportedLanguage('ca')
    language_tool.addSupportedLanguage('es')

    workflowTool = getToolByName(portal, "portal_workflow")
    workflowTool.setDefaultChain('simple_publication_workflow')

    setupTool = SetupMultilingualSite()
    setupTool.setupSite(portal)

    transaction.commit()

    atdoc = makeContent(portal['en'], 'Document', id='atdoc', title='EN doc')
    atdoc.setLanguage('en')
    atdoc_ca = makeTranslation(atdoc, 'ca')
    atdoc_ca.edit(title="CA doc", language='ca')

    dxdoc = createContentInContainer(portal['en'], "dxdoc", id="dxdoc", title='EN doc')
    ILanguage(dxdoc).set_language('en')
    dxdoc_ca = makeTranslation(dxdoc, 'ca')
    dxdoc_ca.title = "CA doc"
    ILanguage(dxdoc_ca).set_language('ca')

    transaction.commit()
 def setUpFullyTranslatedContent(self):
     wftool = self.setUpPartiallyTranslatedContent()
     document_ca = makeTranslation(self.portal.en.folder.document, 'ca')
     document_ca.edit(title="Foo", language='ca')
     wftool.doActionFor(document_ca, 'publish')
     folder_es = makeTranslation(self.portal.en.folder, 'es')
     folder_es.edit(title="Foo", language='es')
     wftool.doActionFor(folder_es, 'publish')
     document_es = makeTranslation(self.portal.en.folder.document, 'es')
     document_es.edit(title="Foo", language='es')
     wftool.doActionFor(document_es, 'publish')
     transaction.commit()
     return wftool
Esempio n. 3
0
    def test_move_content_proper_language_folder_existing_translation_inside(
            self):

        self.assertTrue(getattr(self.portal, 'en'))

        self.portal.en.invokeFactory('Folder',
                                     'new11',
                                     title=u"An archetypes based folder")
        new11 = self.portal.en['new11']
        new11.invokeFactory('Document',
                            'doc11',
                            title=u"An archetypes based doc")
        doc1_ca = makeTranslation(self.portal.en.new11.doc11, 'ca')
        doc1_ca.edit(title="Foo", language='ca')
        self.assertTrue(self.portal.ca.doc11)
        transaction.commit()

        # Change the content language of the created folder to 'ca'

        multilingualMoveObject(new11, 'ca')
        self.assertTrue(self.portal.ca.new11)
        self.assertTrue(self.portal.ca.new11.doc11)
        self.assertEqual(
            ITranslationManager(self.portal.ca.new11.doc11).get_translations(),
            {'ca': self.portal.ca.new11.doc11})
        self.assertEqual(
            ITranslationManager(doc1_ca).get_translations(), {'ca': doc1_ca})
        self.assertEqual(ILanguage(self.portal.ca.new11).get_language(), 'ca')
        self.assertEqual(
            ILanguage(self.portal.ca.new11.doc11).get_language(), 'ca')
    def test_move_content_proper_language_folder_existing_translation_inside(self):

        self.assertTrue(getattr(self.portal, 'en'))

        self.portal.en.invokeFactory('Folder', 'new11',
                                     title=u"An archetypes based folder")
        new11 = self.portal.en['new11']
        new11.invokeFactory('Document', 'doc11',
                            title=u"An archetypes based doc")
        doc1_ca = makeTranslation(self.portal.en.new11.doc11, 'ca')
        doc1_ca.edit(title="Foo", language='ca')
        self.assertTrue(self.portal.ca.doc11)
        transaction.commit()

        # Change the content language of the created folder to 'ca'

        multilingualMoveObject(new11, 'ca')
        self.assertTrue(self.portal.ca.new11)
        self.assertTrue(self.portal.ca.new11.doc11)
        self.assertEqual(ITranslationManager(
                            self.portal.ca.new11.doc11).get_translations(),
                            {'ca': self.portal.ca.new11.doc11})
        self.assertEqual(ITranslationManager(doc1_ca).get_translations(),
                         {'ca': doc1_ca})
        self.assertEqual(ILanguage(self.portal.ca.new11).get_language(), 'ca')
        self.assertEqual(ILanguage(self.portal.ca.new11.doc11).get_language(),
                         'ca')
Esempio n. 5
0
    def test_universal_link_view(self):
        self.browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD))
        self.browser.addHeader('Accept-Language', 'ca')
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        login(self.portal, TEST_USER_NAME)

        doc1 = makeContent(self.portal, 'Document', id='doc1')
        doc1.setLanguage('en')
        doc1_ca = makeTranslation(doc1, 'ca')
        doc1_ca.edit(title="Foo", language='ca')
        doc1_es = makeTranslation(doc1, 'es')
        doc1_es.edit(title="Foo", language='es')
        transaction.commit()

        self.browser.open(doc1.absolute_url())
        self.browser.getLink("Universal Link").click()
        self.assertEqual(self.browser.url, 'http://nohost/plone/doc1-ca')
Esempio n. 6
0
    def test_universal_link_view(self):
        self.browser.addHeader(
            'Authorization',
            'Basic %s:%s' % (TEST_USER_NAME, TEST_USER_PASSWORD))
        self.browser.addHeader('Accept-Language', 'ca')
        setRoles(self.portal, TEST_USER_ID, ['Manager'])
        login(self.portal, TEST_USER_NAME)

        doc1 = makeContent(self.portal, 'Document', id='doc1')
        doc1.setLanguage('en')
        doc1_ca = makeTranslation(doc1, 'ca')
        doc1_ca.edit(title="Foo", language='ca')
        doc1_es = makeTranslation(doc1, 'es')
        doc1_es.edit(title="Foo", language='es')
        transaction.commit()

        self.browser.open(doc1.absolute_url())
        self.browser.getLink("Universal Link").click()
        self.assertEqual(self.browser.url, 'http://nohost/plone/doc1-ca')
    def test_alternates_AT(self):
        atdoc = makeContent(
            self.portal['en'], 'Document', id='atdoc', title='EN doc')
        atdoc.setLanguage('en')
        atdoc_ca = makeTranslation(atdoc, 'ca')
        atdoc_ca.edit(title="CA doc", language='ca')

        transaction.savepoint()

        self._validate_alternates(atdoc)
    def test_alternates_DX(self):
        dxdoc = createContentInContainer(
            self.portal['en'], "dxdoc", id="dxdoc", title='EN doc')
        ILanguage(dxdoc).set_language('en')
        dxdoc_ca = makeTranslation(dxdoc, 'ca')
        dxdoc_ca.title = "CA doc"
        ILanguage(dxdoc_ca).set_language('ca')

        transaction.savepoint()

        self._validate_alternates(dxdoc)
def setUp():
    portal = getSite()
    applyProfile(portal, 'plone.multilingualbehavior:default')

    language_tool = getToolByName(portal, 'portal_languages')
    language_tool.addSupportedLanguage('ca')
    language_tool.addSupportedLanguage('es')

    atdoc = makeContent(portal, 'Document', id='atdoc', title='EN doc')
    atdoc.setLanguage('en')
    atdoc_ca = makeTranslation(atdoc, 'ca')
    atdoc_ca.edit(title="CA doc", language='ca')

    dxdoc = createContentInContainer(portal, "dxdoc", id="dxdoc", title='EN doc')
    ILanguage(dxdoc).set_language('en')
    dxdoc_ca = makeTranslation(dxdoc, 'ca')
    dxdoc_ca.title = "CA doc"
    ILanguage(dxdoc_ca).set_language('ca')

    transaction.commit()
    def test_languages_full_translated_by_closest(self):
        self.registry = getUtility(IRegistry)
        self.settings = self.registry.forInterface(IMultiLanguagePolicies)
        self.settings.selector_lookup_translations_policy = 'closest'

        doc1 = makeContent(self.portal, 'Document', id='doc1')
        doc1.setLanguage('en')
        doc1_ca = makeTranslation(doc1, 'ca')
        doc1_ca.edit(title="Foo", language='ca')
        doc1_es = makeTranslation(doc1, 'es')
        doc1_es.edit(title="Foo", language='es')

        self.selector = LanguageSelectorViewlet(doc1, self.request, None, None)

        self.selector.update()

        self.assertEqual(self.selector.languages(), [{
            'code': u'en',
            u'name': u'English',
            'url': 'http://nohost/plone/doc1?set_language=en',
            'selected': True,
            u'flag': u'/++resource++country-flags/gb.gif',
            'translated': True,
            u'native': u'English'
        }, {
            'code': u'ca',
            u'name': u'Catalan',
            'url': 'http://nohost/plone/doc1-ca?set_language=ca',
            'selected': False,
            u'flag': u'/++resource++language-flags/ca.gif',
            'translated': True,
            u'native': u'Catal\xe0'
        }, {
            'code': u'es',
            u'name': u'Spanish',
            'url': 'http://nohost/plone/doc1-es?set_language=es',
            'selected': False,
            u'flag': u'/++resource++country-flags/es.gif',
            'translated': True,
            u'native': u'Espa\xf1ol'
        }])
    def setUp(self):
        with ploneSite() as portal:
            language_tool = getToolByName(portal, 'portal_languages')
            language_tool.addSupportedLanguage('ca')
            language_tool.addSupportedLanguage('es')

            setupTool = SetupMultilingualSite()
            setupTool.setupSite(portal)

            atdoc = makeContent(
                portal['en'], 'Document', id='atdoc', title='EN doc')
            atdoc.setLanguage('en')
            atdoc_ca = makeTranslation(atdoc, 'ca')
            atdoc_ca.edit(title="CA doc", language='ca')

            dxdoc = createContentInContainer(
                portal['en'], "dxdoc", id="dxdoc", title='EN doc')
            ILanguage(dxdoc).set_language('en')
            dxdoc_ca = makeTranslation(dxdoc, 'ca')
            dxdoc_ca.title = "CA doc"
            ILanguage(dxdoc_ca).set_language('ca')
Esempio n. 12
0
    def test_languages_full_translated_by_closest(self):
        self.registry = getUtility(IRegistry)
        self.settings = self.registry.forInterface(IMultiLanguagePolicies)
        self.settings.selector_lookup_translations_policy = 'closest'

        doc1 = makeContent(self.portal, 'Document', id='doc1')
        doc1.setLanguage('en')
        doc1_ca = makeTranslation(doc1, 'ca')
        doc1_ca.edit(title="Foo", language='ca')
        doc1_es = makeTranslation(doc1, 'es')
        doc1_es.edit(title="Foo", language='es')

        self.selector = LanguageSelectorViewlet(doc1,
                            self.request, None, None)

        self.selector.update()

        self.assertEqual(self.selector.languages(), [
            {'code': u'en',
             u'name': u'English',
             'url': 'http://nohost/plone/doc1?set_language=en',
             'selected': True,
             u'flag': u'/++resource++country-flags/gb.gif',
             'translated': True,
             u'native': u'English'},
             {'code': u'ca',
              u'name': u'Catalan',
              'url': 'http://nohost/plone/doc1-ca?set_language=ca',
              'selected': False,
              u'flag': u'/++resource++language-flags/ca.gif',
              'translated': True,
              u'native': u'Catal\xe0'},
              {'code': u'es',
              u'name': u'Spanish',
              'url': 'http://nohost/plone/doc1-es?set_language=es',
              'selected': False,
              u'flag': u'/++resource++country-flags/es.gif',
              'translated': True,
              u'native': u'Espa\xf1ol'}
        ])
 def setUpPartiallyTranslatedContent(self):
     wftool = self.setUpPAMFolders()
     folder = makeContent(self.portal.en, 'Folder', id='folder')
     folder.setLanguage('en')
     wftool.doActionFor(folder, 'publish')
     document = makeContent(folder, 'Document', id='document')
     document.setLanguage('en')
     wftool.doActionFor(document, 'publish')
     folder_ca = makeTranslation(folder, 'ca')
     folder_ca.edit(title="Foo", language='ca')
     wftool.doActionFor(folder_ca, 'publish')
     transaction.commit()
     return wftool
    def assertFullyTranslatedPages(self):
        doc1 = makeContent(self.portal, 'Document', id='doc1')
        doc1.setLanguage('en')
        doc1_tg = ITG(doc1)
        doc1_ca = makeTranslation(doc1, 'ca')
        doc1_ca.edit(title="Foo", language='ca')
        doc1_es = makeTranslation(doc1, 'es')
        doc1_es.edit(title="Foo", language='es')

        self.selector = LanguageSelectorViewlet(doc1,
                            self.request, None, None)

        self.selector.update()
        selector_languages = self.selector.languages()
        self.assertEqual(selector_languages, [
            {
                'code': u'en',
                u'name': u'English',
                'url': SELECTOR_VIEW_TEMPLATE % {
                    'url': self.portal_url,
                    'tg': doc1_tg,
                    'lang': 'en',
                    'query': '?set_language=en'
                },
                'selected': True,
                u'flag': u'/++resource++country-flags/gb.gif',
                'translated': True,
                u'native': u'English'
            },
            {
                'code': u'ca',
                u'name': u'Catalan',
                'url': SELECTOR_VIEW_TEMPLATE % {
                    'url': self.portal_url,
                    'tg': doc1_tg,
                    'lang': 'ca',
                    'query': '?set_language=ca'
                },
                'selected': False,
                u'flag': u'/++resource++language-flags/ca.gif',
                'translated': True,
                u'native': u'Catal\xe0'
            },
            {
                'code': u'es',
                u'name': u'Spanish',
                'url': SELECTOR_VIEW_TEMPLATE % {
                    'url': self.portal_url,
                    'tg': doc1_tg,
                    'lang': 'es',
                    'query': '?set_language=es'
                },
                'selected': False,
                u'flag': u'/++resource++country-flags/es.gif',
                'translated': True,
                u'native': u'Espa\xf1ol'
            }
        ])

        self.browser.open(selector_languages[0]['url'])
        self.assertEqual(
            self.browser.url,
            doc1.absolute_url() + '?set_language=en'
        )
        self.assertRegexpMatches(self.browser.contents, r"You\s*are here")
        self.browser.open(selector_languages[1]['url'])
        self.assertEqual(
            self.browser.url,
            doc1_ca.absolute_url() + '?set_language=ca'
        )
        self.assertIn(
            u'lang="ca"'.encode("utf-8"),
            self.browser.contents
        )
        self.browser.open(selector_languages[2]['url'])
        self.assertEqual(
            self.browser.url,
            doc1_es.absolute_url() + '?set_language=es'
        )
        self.assertIn(
            u'lang="es"'.encode("utf-8"),
            self.browser.contents
        )