当前位置: 首页>>代码示例>>Python>>正文


Python LanguageSelectorViewlet.languages方法代码示例

本文整理汇总了Python中plone.app.multilingual.browser.selector.LanguageSelectorViewlet.languages方法的典型用法代码示例。如果您正苦于以下问题:Python LanguageSelectorViewlet.languages方法的具体用法?Python LanguageSelectorViewlet.languages怎么用?Python LanguageSelectorViewlet.languages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在plone.app.multilingual.browser.selector.LanguageSelectorViewlet的用法示例。


在下文中一共展示了LanguageSelectorViewlet.languages方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_languages_partially_translated_by_dialog

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import languages [as 别名]
    def test_languages_partially_translated_by_dialog(self):
        self.registry = getUtility(IRegistry)
        self.settings = self.registry.forInterface(
            IMultiLanguageExtraOptionsSchema, prefix="plone")
        self.settings.selector_lookup_translations_policy = 'dialog'

        # Setup content
        self.setUpPartiallyTranslatedContent()

        a_en = self.portal['en']['test-folder']['test-document']

        selector = LanguageSelectorViewlet(a_en, self.request, None, None)
        selector.update()
        selector_languages = selector.languages()

        # Check that EN translation is found
        self.browser.open(selector_languages[0]['url'])
        self.assertEqual(
            self.browser.url,
            a_en.absolute_url()+'?set_language=en'
        )
        # But extra check, because English is the default?
        self.assertIn(u'lang="en"'.encode("utf-8"), self.browser.contents)
        self.assertRegexpMatches(self.browser.contents, r"You\s*are here")

        tgid = selector_languages[1]['url'].split('/')[-2]

        # Check that CA is not yet translated
        self.browser.open(selector_languages[1]['url'])
        self.assertEqual(
            self.browser.url,
            self.portal.absolute_url() +
            NOT_TRANSLATED_YET_TEMPLATE +
            '/' + tgid + '?set_language=ca'
        )
        self.assertIn(
            u'lang="ca"'.encode("utf-8"),
            self.browser.contents
        )

        # Check that ES is not yet translated
        self.browser.open(selector_languages[2]['url'])
        self.assertEqual(
            self.browser.url,
            self.portal.absolute_url() +
            NOT_TRANSLATED_YET_TEMPLATE +
            '/' + tgid + '?set_language=es'
        )
        self.assertIn(
            u'lang="es"'.encode("utf-8"),
            self.browser.contents
        )
开发者ID:albertduran,项目名称:plone.app.multilingual,代码行数:54,代码来源:test_selector.py

示例2: test_selector_data_not_modified_by_viewlet

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import languages [as 别名]
    def test_selector_data_not_modified_by_viewlet(self):
        selector_viewlet = \
            LanguageSelectorViewlet(self.portal, self.request, None, None)
        selector_viewlet.update()
        selector_viewlet_languages = selector_viewlet.languages()

        selector_adapter = \
            LanguageSelector(self.portal, self.request, None, None)
        selector_adapter.update()
        selector_adapter_languages = selector_adapter.languages()

        self.assertNotEquals(selector_adapter_languages,
                             selector_viewlet_languages)
开发者ID:PythonUnited,项目名称:plone.app.multilingual,代码行数:15,代码来源:test_selector.py

示例3: test_languages_partially_translated_by_dialog

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import languages [as 别名]
    def test_languages_partially_translated_by_dialog(self):
        self.registry = getUtility(IRegistry)
        self.settings = self.registry.forInterface(IMultiLanguagePolicies)
        self.settings.selector_lookup_translations_policy = 'dialog'

        self.setUpPartiallyTranslatedContent()

        selector = LanguageSelectorViewlet(
            self.portal.en.folder.document,
            self.request,
            None,
            None
        )

        selector.update()
        selector_languages = selector.languages()
        self.browser.open(selector_languages[0]['url'])
        self.assertEqual(
            self.browser.url,
            self.portal.en.folder.document.absolute_url()+'?set_language=en'
        )
        self.assertRegexpMatches(self.browser.contents, r"You\s*are here")
        tgid = selector_languages[1]['url'].split('/')[-2]
        self.browser.open(selector_languages[1]['url'])
        self.assertEqual(
            self.browser.url,
            self.portal.absolute_url() + \
                NOT_TRANSLATED_YET_TEMPLATE + '/' + tgid + '?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,
            self.portal.absolute_url() + \
                NOT_TRANSLATED_YET_TEMPLATE + '/' + tgid + '?set_language=es'
        )
        self.assertIn(
            u'lang="es"'.encode("utf-8"),
            self.browser.contents
        )
开发者ID:khink,项目名称:plone.app.multilingual,代码行数:45,代码来源:test_selector.py

示例4: test_languages_partially_translated_by_closest

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import languages [as 别名]
    def test_languages_partially_translated_by_closest(self):
        self.registry = getUtility(IRegistry)
        self.settings = self.registry.forInterface(
            IMultiLanguageExtraOptionsSchema, prefix="plone")
        self.settings.selector_lookup_translations_policy = 'closest'

        # Setup content
        self.setUpPartiallyTranslatedContent()

        a_en = self.portal['en']['test-folder']['test-document']
        f_ca = self.portal['ca']['test-folder']

        selector = LanguageSelectorViewlet(a_en, self.request, None, None)
        selector.update()
        selector_languages = selector.languages()

        # Check that EN translation is found
        self.browser.open(selector_languages[0]['url'])
        self.assertEqual(
            self.browser.url,
            a_en.absolute_url() + '?set_language=en'
        )
        self.assertIn(u'lang="en"'.encode("utf-8"), self.browser.contents)
        # But extra check, because English is the default?
        self.assertRegexpMatches(self.browser.contents, r"You\s*are here")

        # Check that CA translation is only partial and a parent folder
        # is found
        self.browser.open(selector_languages[1]['url'])
        self.assertEqual(
            self.browser.url,
            f_ca.absolute_url() + '?set_language=ca'
        )
        self.assertIn(u'lang="ca"'.encode("utf-8"), self.browser.contents)

        # Check that ES translation is missing and only the LRF is found
        self.browser.open(selector_languages[2]['url'])
        self.assertEqual(
            self.browser.url,
            self.portal['es'].absolute_url() + '?set_language=es'
        )
        self.assertIn(u'lang="es"'.encode("utf-8"), self.browser.contents)
开发者ID:albertduran,项目名称:plone.app.multilingual,代码行数:44,代码来源:test_selector.py

示例5: test_languages_partially_translated_by_closest

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import languages [as 别名]
    def test_languages_partially_translated_by_closest(self):
        self.registry = getUtility(IRegistry)
        self.settings = self.registry.forInterface(IMultiLanguagePolicies)
        self.settings.selector_lookup_translations_policy = 'closest'
        self.setUpPartiallyTranslatedContent()

        selector = LanguageSelectorViewlet(
            self.portal.en.folder.document,
            self.request,
            None,
            None
        )

        selector.update()
        selector_languages = selector.languages()
        self.browser.open(selector_languages[0]['url'])
        self.assertEqual(
            self.browser.url,
            self.portal.en.folder.document.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,
            self.portal.ca.folder.absolute_url()+'?set_language=ca'
        )
        self.assertIn(
            u"Inici".encode("utf-8"),
            self.browser.contents
        )
        self.browser.open(selector_languages[2]['url'])
        self.assertEqual(
            self.browser.url,
            self.portal.es.absolute_url()+'?set_language=es'
        )
        self.assertIn(
            u"Usted está aquí".encode("utf-8"),
            self.browser.contents
        )
开发者ID:pranjaldaga,项目名称:plone.app.multilingual,代码行数:41,代码来源:test_selector.py

示例6: test_languages_preserve_query

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import languages [as 别名]
    def test_languages_preserve_query(self):
        self.setUpPartiallyTranslatedContent()
        self.registry = getUtility(IRegistry)
        self.request['PATH_INFO'] = '/plone/en/folder/@@search'
        self.request.form['uni'] = u'pres\xd8rved'
        self.request.form['int'] = '1'

        selector = LanguageSelectorViewlet(
            self.portal.en.folder,
            self.request,
            None,
            None
        )
        selector.update()
        selector_languages = selector.languages()
        tgid = selector_languages[2]['url'].split('/')[-3]

        untraslated_url = {
            'closest': self.portal.es.absolute_url() + \
                '?int=1&uni=pres%C3%98rved&set_language=es',
            'dialog': self.portal.absolute_url() + \
                NOT_TRANSLATED_YET_TEMPLATE + '/' + tgid + \
                '?int=1&uni=pres%C3%98rved&set_language=es'
        }
        for policy in ['closest', 'dialog']:
            self.settings = self.registry.forInterface(IMultiLanguagePolicies)
            self.settings.selector_lookup_translations_policy = policy
            transaction.commit()
            selector = LanguageSelectorViewlet(
                self.portal.en.folder,
                self.request,
                None,
                None
            )
            selector.update()
            selector_languages = selector.languages()
            self.browser.open(selector_languages[0]['url'])
            self.assertEqual(
                self.browser.url,
                self.portal.en.folder.absolute_url() + \
                    '/@@search?int=1&uni=pres%C3%98rved&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,
                self.portal.ca.folder.absolute_url() + \
                    '/@@search?int=1&uni=pres%C3%98rved&set_language=ca'
            )
            self.assertIn(
                u'lang="ca"'.encode("utf-8"),
                self.browser.contents
            )
            # Here @@search isn't preserved because we've got the dialog
            self.browser.open(selector_languages[2]['url'])

            self.assertEqual(
                self.browser.url,
                untraslated_url[policy]
            )
            self.assertIn(
                u'lang="es"'.encode("utf-8"),
                self.browser.contents
            )
开发者ID:khink,项目名称:plone.app.multilingual,代码行数:66,代码来源:test_selector.py

示例7: test_languages_preserve_view

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import languages [as 别名]
    def test_languages_preserve_view(self):
        self.setUpPartiallyTranslatedContent()
        self.registry = getUtility(IRegistry)
        self.request['PATH_INFO'] = '/plone/en/folder/@@search'
        self.settings = self.registry.forInterface(IMultiLanguagePolicies)
        self.settings.selector_lookup_translations_policy = 'closest'
        transaction.commit()
        selector = LanguageSelectorViewlet(
            self.portal.en.folder,
            self.request,
            None,
            None
        )
        selector.update()
        selector_languages = selector.languages()
        self.browser.open(selector_languages[0]['url'])
        self.assertEqual(
            self.browser.url,
            self.portal.en.folder.absolute_url()+'/@@search?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,
            self.portal.ca.folder.absolute_url()+'/@@search?set_language=ca'
        )
        self.assertIn(
            u'lang="ca"'.encode("utf-8"),
            self.browser.contents
        )
        # Here @@search isn't preserved because we've gone up a level
        self.browser.open(selector_languages[2]['url'])
        self.assertEqual(
            self.browser.url,
            self.portal.es.absolute_url()+'?set_language=es'
        )
        self.assertIn(
            u'lang="es"'.encode("utf-8"),
            self.browser.contents
        )

        # Shouldn't do for the not-translated-yet thingie when dialog is on
        self.registry = getUtility(IRegistry)
        self.settings = self.registry.forInterface(IMultiLanguagePolicies)
        self.settings.selector_lookup_translations_policy = 'dialog'
        transaction.commit()
        selector = LanguageSelectorViewlet(
            self.portal.en.folder,
            self.request,
            None,
            None
        )
        selector.update()
        selector_languages = selector.languages()
        self.browser.open(selector_languages[0]['url'])
        self.assertEqual(
            self.browser.url,
            self.portal.en.folder.absolute_url()+'/@@search?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,
            self.portal.ca.folder.absolute_url()+'/@@search?set_language=ca'
        )
        self.assertIn(
            u'lang="ca"'.encode("utf-8"),
            self.browser.contents
        )
        # Here @@search isn't preserved because we've got the dialog
        self.browser.open(selector_languages[2]['url'])
        tgid = selector_languages[2]['url'].split('/')[-3]

        self.assertEqual(
            self.browser.url,
            self.portal.absolute_url() + \
                NOT_TRANSLATED_YET_TEMPLATE + '/' + tgid + '?set_language=es'
        )
        self.assertIn(
            u'lang="es"'.encode("utf-8"),
            self.browser.contents
        )
开发者ID:khink,项目名称:plone.app.multilingual,代码行数:84,代码来源:test_selector.py

示例8: TestLanguageSelectorBasics

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import languages [as 别名]
class TestLanguageSelectorBasics(unittest.TestCase):

    layer = PLONEAPPMULTILINGUAL_FUNCTIONAL_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        self.portal.error_log._ignored_exceptions = ()
        self.request = self.layer['request']
        self.browser = Browser(self.layer['app'])
        self.browser.handleErrors = False
        self.portal_url = self.portal.absolute_url()
        self.language_tool = getToolByName(self.portal, 'portal_languages')
        self.language_tool.addSupportedLanguage('ca')
        self.language_tool.addSupportedLanguage('es')

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

    def test_available(self):
        self.selector.update()
        self.assertEquals(self.selector.available(), True)

    def test_available_no_tool(self):
        self.selector.update()
        self.selector.tool = None
        self.assertEquals(self.selector.available(), False)

    def test_original_selector_data_not_modified_by_viewlet(self):
        self.selector.update()
        multilingual_lang_info = self.selector.languages()
        original_selector = LanguageSelector(self.portal,
                            self.request, None, None)
        original_selector.update()
        original_lang_info = original_selector.languages()

        self.assertNotEquals(original_lang_info, multilingual_lang_info)

    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'
#.........这里部分代码省略.........
开发者ID:khink,项目名称:plone.app.multilingual,代码行数:103,代码来源:test_selector.py

示例9: assertFullyTranslatedPages

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import languages [as 别名]
    def assertFullyTranslatedPages(self):
        a = createContentInContainer(
            self.portal['en'], 'Document', title=u"Test document")

        a_ca = api.translate(a, 'ca')
        a_ca.setTitle(u"Test Document (CA)")

        a_es = api.translate(a, 'es')
        a_es.setTitle(u"Test Document (ES)")

        wftool = getToolByName(self.portal, 'portal_workflow')
        wftool.doActionFor(a, 'publish')
        wftool.doActionFor(a_ca, 'publish')
        wftool.doActionFor(a_es, 'publish')

        notify(ObjectModifiedEvent(a))
        notify(ObjectModifiedEvent(a_ca))
        notify(ObjectModifiedEvent(a_es))

        selector_viewlet =\
            LanguageSelectorViewlet(a, self.request, None, None)
        selector_viewlet.update()
        selector_viewlet_languages = selector_viewlet.languages()

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

        transaction.commit()

        self.browser.open(selector_viewlet_languages[0]['url'])
        self.assertEqual(self.browser.url,
                         a.absolute_url() + '?set_language=en')
        self.assertRegexpMatches(self.browser.contents, r"You\s*are here")

        self.browser.open(selector_viewlet_languages[1]['url'])
        self.assertEqual(self.browser.url,
                         a_ca.absolute_url() + '?set_language=ca')

        self.assertIn(u'lang="ca"'.encode("utf-8"), self.browser.contents)

        self.browser.open(selector_viewlet_languages[2]['url'])
        self.assertEqual(self.browser.url,
                         a_es.absolute_url() + '?set_language=es')
        self.assertIn(u'lang="es"'.encode("utf-8"), self.browser.contents)
开发者ID:PythonUnited,项目名称:plone.app.multilingual,代码行数:84,代码来源:test_selector.py

示例10: assertLanguagesPreserveQuery

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import languages [as 别名]
    def assertLanguagesPreserveQuery(self, policy):

        self.setUpPartiallyTranslatedContent()
        self.request['PATH_INFO'] = '/plone/en/test-folder/@@search'
        self.request.form['uni'] = u'pres\xd8rved'
        self.request.form['int'] = '1'

        f_en = self.portal['en']['test-folder']
        f_ca = self.portal['ca']['test-folder']

        selector = LanguageSelectorViewlet(f_en, self.request, None, None)
        selector.update()
        selector_languages = selector.languages()

        tgid = selector_languages[2]['url'].split('/')[-3]
        untranslated_url = {
            'closest': (self.portal['es'].absolute_url()
                        + '?int=1&uni=pres%C3%98rved&set_language=es'),
            'dialog': (self.portal.absolute_url()
                       + NOT_TRANSLATED_YET_TEMPLATE + '/' + tgid
                       + '?int=1&uni=pres%C3%98rved&set_language=es')
        }

        transaction.commit()

        # Check EN
        self.browser.open(selector_languages[0]['url'])
        self.assertEqual(
            self.browser.url,
            (f_en.absolute_url()
             + '/@@search?int=1&uni=pres%C3%98rved&set_language=en')
        )
        self.assertIn(
            u'lang="en"'.encode("utf-8"),
            self.browser.contents
        )
        self.assertRegexpMatches(self.browser.contents, r"You\s*are here")

        # Check CA
        self.browser.open(selector_languages[1]['url'])
        self.assertEqual(
            self.browser.url,
            (f_ca.absolute_url()
             + '/@@search?int=1&uni=pres%C3%98rved&set_language=ca')
        )
        self.assertIn(
            u'lang="ca"'.encode("utf-8"),
            self.browser.contents
        )

        # Check ES
        self.browser.open(selector_languages[2]['url'])
        # Here @@search isn't preserved because we've got the dialog
        self.assertEqual(
            self.browser.url,
            untranslated_url[policy]
        )
        self.assertIn(
            u'lang="es"'.encode("utf-8"),
            self.browser.contents
        )
开发者ID:PythonUnited,项目名称:plone.app.multilingual,代码行数:63,代码来源:test_selector.py

示例11: TestLanguageSelectorBasics

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import languages [as 别名]
class TestLanguageSelectorBasics(unittest.TestCase):

    layer = PAM_FUNCTIONAL_TESTING

    def setUp(self):
        # Set test variables
        self.portal = self.layer['portal']
        self.portal_url = self.portal.absolute_url()
        self.request = self.layer['request']

        # Setup testbrowser
        self.browser = Browser(self.layer['app'])
        self.browser.handleErrors = False

    def test_selector_viewlet_is_available(self):
        selector_viewlet = \
            LanguageSelectorViewlet(self.portal, self.request, None, None)
        selector_viewlet.update()
        self.assertTrue(selector_viewlet.available())

    def test_selector_viewlet_is_available_but_tool_is_not(self):
        selector_viewlet = \
            LanguageSelectorViewlet(self.portal, self.request, None, None)
        selector_viewlet.update()
        selector_viewlet.tool = None
        self.assertFalse(selector_viewlet.available())

    def test_selector_data_not_modified_by_viewlet(self):
        selector_viewlet = \
            LanguageSelectorViewlet(self.portal, self.request, None, None)
        selector_viewlet.update()
        selector_viewlet_languages = selector_viewlet.languages()

        selector_adapter = \
            LanguageSelector(self.portal, self.request, None, None)
        selector_adapter.update()
        selector_adapter_languages = selector_adapter.languages()

        self.assertNotEquals(selector_adapter_languages,
                             selector_viewlet_languages)

    def assertFullyTranslatedPages(self):
        a = createContentInContainer(
            self.portal['en'], 'Document', title=u"Test document")

        a_ca = api.translate(a, 'ca')
        a_ca.setTitle(u"Test Document (CA)")

        a_es = api.translate(a, 'es')
        a_es.setTitle(u"Test Document (ES)")

        wftool = getToolByName(self.portal, 'portal_workflow')
        wftool.doActionFor(a, 'publish')
        wftool.doActionFor(a_ca, 'publish')
        wftool.doActionFor(a_es, 'publish')

        notify(ObjectModifiedEvent(a))
        notify(ObjectModifiedEvent(a_ca))
        notify(ObjectModifiedEvent(a_es))

        selector_viewlet =\
            LanguageSelectorViewlet(a, self.request, None, None)
        selector_viewlet.update()
        selector_viewlet_languages = selector_viewlet.languages()

        self.assertEqual(selector_viewlet_languages, [{
            'code': u'en',
            u'flag': u'/++resource++country-flags/gb.gif',
            u'name': u'English',
            u'native': u'English',
            'url': SELECTOR_VIEW_TEMPLATE % {
                'url': self.portal_url,
                'tg': ITG(a),
                'lang': 'en',
                'query': '?set_language=en'
            },
            'selected': True,
            'translated': True,
        }, {
            'code': u'ca',
            u'flag': u'/++resource++language-flags/ca.gif',
            u'name': u'Catalan',
            u'native': u'Catal\xe0',
            'url': SELECTOR_VIEW_TEMPLATE % {
                'url': self.portal_url,
                'tg': ITG(a),
                'lang': 'ca',
                'query': '?set_language=ca'
            },
            'selected': False,
            'translated': True,
        }, {
            'code': u'es',
            u'flag': u'/++resource++country-flags/es.gif',
            u'name': u'Spanish',
            u'native': u'Espa\xf1ol',
            'url': SELECTOR_VIEW_TEMPLATE % {
                'url': self.portal_url,
                'tg': ITG(a),
                'lang': 'es',
#.........这里部分代码省略.........
开发者ID:PythonUnited,项目名称:plone.app.multilingual,代码行数:103,代码来源:test_selector.py

示例12: test_languages_preserve_view

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import languages [as 别名]
    def test_languages_preserve_view(self):
        self.registry = getUtility(IRegistry)
        self.settings = self.registry.forInterface(IMultiLanguageExtraOptionsSchema, prefix="plone")
        self.settings.selector_lookup_translations_policy = 'closest'

        self.setUpPartiallyTranslatedContent()

        f_en = self.portal['en']['test-folder']
        f_en = self.portal['en']['test-folder']
        f_ca = self.portal['ca']['test-folder']

        self.request['PATH_INFO'] = '/plone/en/test-folder/contact-info'

        selector = LanguageSelectorViewlet(f_en, self.request, None, None)
        selector.update()
        selector_languages = selector.languages()

        transaction.commit()

        # Check EN
        self.browser.open(selector_languages[0]['url'])
        self.assertEqual(
            self.browser.url,
            f_en.absolute_url()+'/contact-info?set_language=en'
        )
        self.assertIn(
            u'lang="en"'.encode("utf-8"),
            self.browser.contents
        )
        self.assertRegexpMatches(self.browser.contents, r"You\s*are here")

        # Check CA
        self.browser.open(selector_languages[1]['url'])
        self.assertEqual(
            self.browser.url,
            f_ca.absolute_url()+'/contact-info?set_language=ca'
        )
        self.assertIn(
            u'lang="ca"'.encode("utf-8"),
            self.browser.contents
        )

        # Check ES
        self.browser.open(selector_languages[2]['url'])
        # Here @@search isn't preserved because we've gone up a level
        self.assertEqual(
            self.browser.url,
            self.portal.es.absolute_url()+'?set_language=es'
        )
        self.assertIn(
            u'lang="es"'.encode("utf-8"),
            self.browser.contents
        )

        # Shouldn't do for the not-translated-yet thingie when dialog is on
        self.registry = getUtility(IRegistry)
        self.settings = self.registry.forInterface(IMultiLanguageExtraOptionsSchema, prefix="plone")
        self.settings.selector_lookup_translations_policy = 'dialog'

        selector = LanguageSelectorViewlet(f_en, self.request, None, None)
        selector.update()
        selector_languages = selector.languages()

        transaction.commit()

        # Check EN
        self.browser.open(selector_languages[0]['url'])
        self.assertEqual(
            self.browser.url,
            f_en.absolute_url()+'/contact-info?set_language=en'
        )
        self.assertIn(
            u'lang="en"'.encode("utf-8"),
            self.browser.contents
        )
        self.assertRegexpMatches(self.browser.contents, r"You\s*are here")

        # Check CA
        self.browser.open(selector_languages[1]['url'])
        self.assertEqual(
            self.browser.url,
            f_ca.absolute_url()+'/contact-info?set_language=ca'
        )
        self.assertIn(
            u'lang="ca"'.encode("utf-8"),
            self.browser.contents
        )

        # Check ES
        self.browser.open(selector_languages[2]['url'])
        # Here @@search isn't preserved because we've got the dialog
        tgid = selector_languages[2]['url'].split('/')[-3]
        self.assertEqual(
            self.browser.url,
            self.portal.absolute_url() +
            NOT_TRANSLATED_YET_TEMPLATE +
            '/' + tgid + '?set_language=es'
        )
        self.assertIn(
            u'lang="es"'.encode("utf-8"),
#.........这里部分代码省略.........
开发者ID:AnneGilles,项目名称:plone.app.multilingual,代码行数:103,代码来源:test_selector.py

示例13: TestLanguageSelectorBasics

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import languages [as 别名]
class TestLanguageSelectorBasics(unittest.TestCase):

    layer = PAM_FUNCTIONAL_TESTING

    def setUp(self):
        # Set test variables
        self.portal = self.layer['portal']
        self.portal_url = self.portal.absolute_url()
        self.request = self.layer['request']
        alsoProvides(self.layer['request'], IPloneAppMultilingualInstalled)

        # Setup testbrowser
        self.browser = Browser(self.layer['app'])
        self.browser.handleErrors = False

    def test_selector_viewlet_is_available(self):
        selector_viewlet = LanguageSelectorViewlet(
            self.portal, self.request, None, None
        )
        selector_viewlet.update()
        self.assertTrue(selector_viewlet.available())

    def test_selector_viewlet_is_available_but_tool_is_not(self):
        selector_viewlet = LanguageSelectorViewlet(
            self.portal, self.request, None, None
        )
        selector_viewlet.update()
        selector_viewlet.tool = None
        self.assertFalse(selector_viewlet.available())

    def test_selector_data_not_modified_by_viewlet(self):
        selector_viewlet = LanguageSelectorViewlet(
            self.portal, self.request, None, None
        )
        selector_viewlet.update()
        selector_viewlet_languages = selector_viewlet.languages()

        selector_adapter = LanguageSelector(
            self.portal, self.request, None, None
        )
        selector_adapter.update()
        selector_adapter_languages = selector_adapter.languages()

        self.assertNotEquals(
            selector_adapter_languages, selector_viewlet_languages
        )

    def assertFullyTranslatedPages(self):
        a = createContentInContainer(
            self.portal['en'], 'Document', title=u"Test document"
        )

        a_ca = api.translate(a, 'ca')
        a_ca.setTitle(u"Test Document (CA)")

        a_es = api.translate(a, 'es')
        a_es.setTitle(u"Test Document (ES)")

        wftool = getToolByName(self.portal, 'portal_workflow')
        wftool.doActionFor(a, 'publish')
        wftool.doActionFor(a_ca, 'publish')
        wftool.doActionFor(a_es, 'publish')

        notify(ObjectModifiedEvent(a))
        notify(ObjectModifiedEvent(a_ca))
        notify(ObjectModifiedEvent(a_es))

        selector_viewlet = LanguageSelectorViewlet(a, self.request, None, None)
        selector_viewlet.update()
        selector_viewlet_languages = selector_viewlet.languages()

        self.assertEqual(
            selector_viewlet_languages,
            [
                {
                    'code': u'en',
                    u'flag': u'/++resource++country-flags/gb.gif',
                    u'name': u'English',
                    u'native': u'English',
                    'url': SELECTOR_VIEW_TEMPLATE
                    % {
                        'url': self.portal_url,
                        'tg': ITG(a),
                        'lang': 'en',
                        'query': '?set_language=en',
                    },
                    'selected': True,
                    'translated': True,
                },
                {
                    'code': u'ca',
                    u'flag': u'/++resource++language-flags/ca.gif',
                    u'name': u'Catalan',
                    u'native': u'Catal\xe0',
                    'url': SELECTOR_VIEW_TEMPLATE
                    % {
                        'url': self.portal_url,
                        'tg': ITG(a),
                        'lang': 'ca',
                        'query': '?set_language=ca',
#.........这里部分代码省略.........
开发者ID:plone,项目名称:plone.app.multilingual,代码行数:103,代码来源:test_selector.py

示例14: TestLanguageSelectorBasics

# 需要导入模块: from plone.app.multilingual.browser.selector import LanguageSelectorViewlet [as 别名]
# 或者: from plone.app.multilingual.browser.selector.LanguageSelectorViewlet import languages [as 别名]
class TestLanguageSelectorBasics(unittest.TestCase):

    layer = PLONEAPPMULTILINGUAL_INTEGRATION_TESTING

    def setUp(self):
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        self.portal_url = self.portal.absolute_url()
        self.language_tool = getToolByName(self.portal, 'portal_languages')
        self.language_tool.addSupportedLanguage('ca')
        self.language_tool.addSupportedLanguage('es')

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

    def test_available(self):
        self.selector.update()
        self.assertEquals(self.selector.available(), True)

    def test_available_no_tool(self):
        self.selector.update()
        self.selector.tool = None
        self.assertEquals(self.selector.available(), False)

    def test_original_selector_data_not_modified_by_viewlet(self):
        self.selector.update()
        multilingual_lang_info = self.selector.languages()
        original_selector = LanguageSelector(self.portal,
                            self.request, None, None)
        original_selector.update()
        original_lang_info = original_selector.languages()

        self.assertNotEquals(original_lang_info, multilingual_lang_info)

    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 test_languages_partially_translated_by_dialog(self):
        self.registry = getUtility(IRegistry)
        self.settings = self.registry.forInterface(IMultiLanguagePolicies)
        self.settings.selector_lookup_translations_policy = 'dialog'

        p1 = makeContent(self.portal, 'Document', id='partial')
        p1.setLanguage('en')
        p1_ca = makeTranslation(p1, 'ca')
        p1_ca.edit(title="Foo ca", language='ca')

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

        self.selector.update()

        self.assertEqual(self.selector.languages(), [
            {'code': u'en',
             u'name': u'English',
             'url': 'http://nohost/plone/partial?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',
#.........这里部分代码省略.........
开发者ID:adam139,项目名称:devplone422,代码行数:103,代码来源:test_selector.py


注:本文中的plone.app.multilingual.browser.selector.LanguageSelectorViewlet.languages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。