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


Python selector.LanguageSelectorViewlet类代码示例

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


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

示例1: languages

    def languages(self):
        context = aq_inner(self.context)

        ls = LanguageSelector(context, self.request, None, None)
        ls.update()
        results = ls.languages()

        supported_langs = [v['code'] for v in results]
        missing = set([str(c) for c in supported_langs])

        lsv = LanguageSelectorViewlet(context, self.request, None, None)
        translations = lsv._translations(missing)

        # We want to see the babel_view
        append_path = ('', 'babel_view',)
        non_viewable = set()
        for data in results:
            code = str(data['code'])
            data['translated'] = code in translations.keys()

            appendtourl = '/'.join(append_path)

            if data['translated']:
                trans, direct, has_view_permission = translations[code]
                if not has_view_permission:
                    # shortcut if the user cannot see the item
                    non_viewable.add((data['code']))
                    continue
                data['url'] = trans.absolute_url() + appendtourl
            else:
                non_viewable.add((data['code']))

        # filter out non-viewable items
        results = [r for r in results if r['code'] not in non_viewable]
        return results
开发者ID:adam139,项目名称:plone.app.multilingual,代码行数:35,代码来源:babel_view.py

示例2: test_selector_viewlet_is_available_but_tool_is_not

 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())
开发者ID:plone,项目名称:plone.app.multilingual,代码行数:7,代码来源:test_selector.py

示例3: test_languages_partially_translated_by_dialog

    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,代码行数:52,代码来源:test_selector.py

示例4: test_selector_data_not_modified_by_viewlet

    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,代码行数:13,代码来源:test_selector.py

示例5: test_languages_partially_translated_by_dialog

    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,代码行数:43,代码来源:test_selector.py

示例6: setUp

    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)
开发者ID:adam139,项目名称:devplone422,代码行数:10,代码来源:test_selector.py

示例7: test_languages_partially_translated_by_closest

    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,代码行数:42,代码来源:test_selector.py

示例8: setUp

    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)
开发者ID:khink,项目名称:plone.app.multilingual,代码行数:13,代码来源:test_selector.py

示例9: test_languages_partially_translated_by_closest

    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,代码行数:39,代码来源:test_selector.py

示例10: assertSiteRoot

    def assertSiteRoot(self):
        self.selector_viewlet = LanguageSelectorViewlet(
            self.portal, self.request, None, None)
        self.selector_viewlet.update()
        selector_languages = self.selector_viewlet.languages()

        transaction.commit()

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

        # Check CA root
        self.assertEqual(
            selector_languages[1]['url'],
            (self.portal.absolute_url()
             + '/@@multilingual-selector/notg/ca?set_language=ca')
        )
        self.browser.open(selector_languages[1]['url'])
        self.assertIn(
            u'lang="ca"'.encode("utf-8"),
            self.browser.contents
        )

        # Check ES root
        self.browser.open(selector_languages[2]['url'])
        self.assertEqual(
            selector_languages[2]['url'],
            (self.portal.absolute_url()
             + '/@@multilingual-selector/notg/es?set_language=es')
        )
        self.assertIn(
            u'lang="es"'.encode("utf-8"),
            self.browser.contents
        )
开发者ID:PythonUnited,项目名称:plone.app.multilingual,代码行数:44,代码来源:test_selector.py

示例11: test_languages_full_translated_by_closest

    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'}
        ])
开发者ID:adam139,项目名称:devplone422,代码行数:40,代码来源:test_selector.py

示例12: test_site_root

 def test_site_root(self):
     for policy in ['closest', 'dialog']:
         self.registry = getUtility(IRegistry)
         self.settings = self.registry.forInterface(IMultiLanguagePolicies)
         self.settings.selector_lookup_translations_policy = policy
         transaction.commit()
         self.selector = LanguageSelectorViewlet(
             self.portal,
             self.request,
             None,
             None
         )
         self.selector.update()
         selector_languages = self.selector.languages()
         self.browser.open(selector_languages[0]['url'])
         #self.assertEqual(
         #    self.browser.url,
         #    self.portal.absolute_url()+'?set_language=en'
         #)
         self.assertRegexpMatches(self.browser.contents, r"You\s*are here")
         self.assertEqual(
             selector_languages[1]['url'],
             self.portal.absolute_url()+'/@@multilingual-selector/notg/ca?set_language=ca'
         )
         self.browser.open(selector_languages[1]['url'])
         self.assertIn(
             u'lang="ca"'.encode("utf-8"),
             self.browser.contents
         )
         self.browser.open(selector_languages[2]['url'])
         self.assertEqual(
             selector_languages[2]['url'],
             self.portal.absolute_url()+'/@@multilingual-selector/notg/es?set_language=es'
         )
         self.assertIn(
             u'lang="es"'.encode("utf-8"),
             self.browser.contents
         )
开发者ID:khink,项目名称:plone.app.multilingual,代码行数:38,代码来源:test_selector.py

示例13: test_languages_root_folders_by_dialog

    def test_languages_root_folders_by_dialog(self):
        self.registry = getUtility(IRegistry)
        self.settings = self.registry.forInterface(IMultiLanguagePolicies)
        self.settings.selector_lookup_translations_policy = 'dialog'

        workflowTool = getToolByName(self.portal, "portal_workflow")
        workflowTool.setDefaultChain('simple_publication_workflow')
        setupTool = SetupMultilingualSite()
        setupTool.setupSite(self.portal)

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

        self.selector.update()

        self.assertEqual(self.selector.languages(), [
            {'code': u'en',
             u'name': u'English',
             'url': 'http://nohost/plone/en?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/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/es?set_language=es',
             'selected': False,
             u'flag': u'/++resource++country-flags/es.gif',
             'translated': True,
             u'native': u'Espa\xf1ol'}
        ])
开发者ID:adam139,项目名称:devplone422,代码行数:38,代码来源:test_selector.py

示例14: test_selector_viewlet_is_available

 def test_selector_viewlet_is_available(self):
     selector_viewlet = \
         LanguageSelectorViewlet(self.portal, self.request, None, None)
     selector_viewlet.update()
     self.assertTrue(selector_viewlet.available())
开发者ID:PythonUnited,项目名称:plone.app.multilingual,代码行数:5,代码来源:test_selector.py

示例15: test_languages_preserve_view

    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,代码行数:82,代码来源:test_selector.py


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