Exemple #1
0
def enable_pam(portal):
    # Ensure that portal is portal
    portal = api.portal.get()
    # Setup the plone.app.multilingual data
    sms = SetupMultilingualSite(portal)
    sms.setupSite(portal)
    enable_translatable_behavior(portal)
 def setUpPAMFolders(self):
     workflowTool = getToolByName(self.portal, "portal_workflow")
     workflowTool.setDefaultChain('simple_publication_workflow')
     setupTool = SetupMultilingualSite()
     setupTool.setupSite(self.portal)
     transaction.commit()
     return workflowTool
def init_content(context):
    portal = api.portal.get()
    setupTool = SetupMultilingualSite()
    setupTool.setupSite(portal)
    setupTool.move_default_language_content()
    for lang in ['fr', 'en', 'it']:
        create_cover(portal[lang])
def post_install(setup):
    """Post install script"""
    if setup.readDataFile('plonedemosite_default.txt') is None:
        return
    portal = api.portal.get()
    remove_content(portal)
    create_demo_users()
    languages = api.portal.get_registry_record('plone.available_languages')
    setupTool = SetupMultilingualSite()
    setupTool.setupSite(portal)
    for language in languages:
        container = portal[language]

        # Create frontpage for language
        frontpage = create_frontpage(
            portal, container=container, target_language=language)
        container.setDefaultPage('frontpage')
        ILanguage(frontpage).set_language(language)

        # Link the new frontpage as a translation to all existing items
        for lang in languages:
            existing_frontpage = portal[lang].get('frontpage')
            if existing_frontpage:
                ITranslationManager(existing_frontpage).register_translation(
                    language, frontpage)

        # Import zexp for language
        import_zexp(
            setup,
            filename='demo_%s.zexp' % language,
            container=container,
            name='demo',
            update=True,
            publish=True,
        )
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 setUp(self):
        self.portal = self.layer['portal']

        # Setup multilingual site
        language_tool = getToolByName(self.portal, 'portal_languages')
        language_tool.addSupportedLanguage('it')
        language_tool.addSupportedLanguage('de')
        setupTool = SetupMultilingualSite()
        setupTool.setupSite(self.portal)

        # Setup test browser
        self.browser = Browser(self.layer['app'])
        self.browser.handleErrors = False
        self.browser.addHeader(
            'Authorization', 'Basic %s:%s' % (
                SITE_OWNER_NAME, SITE_OWNER_PASSWORD))

        # Create sample document in 'en' and index it into catalog
        self.container = self.portal['en']
        self.content_id = self.container.invokeFactory(
            type_name="Document", id="sampledocument-form")
        self.content = self.container[self.content_id]
        self.content.setLanguage('en')
        notify(ObjectAddedEvent(self.content))

        import transaction
        transaction.commit()
Exemple #7
0
def setupLanguage(context):
    logger("Creating language-dependent content")
    l = context.getSite()
    lu = getToolByName(l, 'portal_languages')
    setupTool = SetupMultilingualSite()
    data = (
        (
            "en",
            u"Rudd-O.com in English",
            u"Linux, free software, voluntaryism and cypherpunk.  Established 1999.",
        ),
        (
            "es",
            u"Rudd-O.com en español",
            u"Linux, software libre, voluntarismo y cypherpunk.  Desde 1999.",
        ),
    )
    for code, title, desc in data:
        if code not in [x[0] for x in lu.listSupportedLanguages()]:
            logger("Adding support for language code %s", code)
            lu.addSupportedLanguage(code)
            setupTool.setupSite(l)
            setupTool.setupLanguageSwitcher()
    for code, title, desc in data:
        l[code].setTitle(title)
        l[code].setDescription(desc)
    logger("Language-dependent content created")
Exemple #8
0
 def setUpPloneSite(self, portal):
     applyProfile(portal, 'plone.app.multilingual:default')
     setRoles(portal, TEST_USER_ID, ['Manager'])
     login(portal, TEST_USER_NAME)
     language_tool = getToolByName(portal, 'portal_languages')
     language_tool.addSupportedLanguage('fr')
     language_tool.addSupportedLanguage('it')
     setup_tool = SetupMultilingualSite()
     setup_tool.setupSite(portal)
Exemple #9
0
 def setUpPloneSite(self, portal):
     applyProfile(portal, 'plone.app.multilingual:default')
     setRoles(portal, TEST_USER_ID, ['Manager'])
     login(portal, TEST_USER_NAME)
     language_tool = getToolByName(portal, 'portal_languages')
     language_tool.addSupportedLanguage('fr')
     language_tool.addSupportedLanguage('it')
     setup_tool = SetupMultilingualSite()
     setup_tool.setupSite(portal)
 def handle_save_action(self, action, data):
     CheckAuthenticator(self.request)
     if form.applyChanges(self.context, self.form_fields, data, self.adapters):
         self.status = _Plone("Changes saved.")
         self._on_save(data)
     else:
         self.status = _Plone("No changes made.")
     setupTool = SetupMultilingualSite()
     output = setupTool.setupSite(self.context)
     self.status += output
    def setUp(self):
        with ploneSite() as portal:
            # Define available languages
            language_tool = getToolByName(portal, 'portal_languages')
            language_tool.addSupportedLanguage('ca')
            language_tool.addSupportedLanguage('es')

            # Setup language root folders
            setupTool = SetupMultilingualSite()
            setupTool.setupSite(portal)
 def setUp(self):
     super(LinkRedirectViewTestCase, self).setUp()
     with api.env.adopt_roles(['Manager']):
         self.subfolder = api.content.create(self.portal, 'Folder',
                                             'subfolder')
         self.link_1 = api.content.create(
             type='Link',
             container=self.subfolder,
             id='link-1',
             title=u'Link 1',
             remoteUrl=u'${portal_url}/assuntos/editoria-a',
         )
         self.link_2 = api.content.create(
             type='Link',
             container=self.subfolder,
             id='link-2',
             title=u'Link 2',
             remoteUrl=u'${navigation_root_url}/assuntos/editoria-b',
         )
         self.link_3 = api.content.create(
             type='Link',
             container=self.subfolder,
             id='link-3',
             title=u'Link 3',
             remoteUrl=u'../../assuntos/editoria-c',
         )
         self.link_4 = api.content.create(
             type='Link',
             container=self.folder,
             id='link-4',
             title=u'Link 4',
             remoteUrl=u'./subfolder',
         )
         portal_setup = api.portal.get_tool('portal_setup')
         portal_setup.runAllImportStepsFromProfile(
             'plone.app.multilingual:default', )
         portal_languages = api.portal.get_tool('portal_languages')
         portal_languages.addSupportedLanguage('en')
         portal_languages.use_request_negotiation = True
         setup_tool = SetupMultilingualSite()
         setup_tool.setupSite(self.portal)
         self.link_5 = api.content.create(
             type='Link',
             container=self.portal['en'],
             id='link-5',
             title=u'Link 5',
             remoteUrl=u'${portal_url}/en/subjects/editorial',
         )
         self.link_6 = api.content.create(
             type='Link',
             container=self.portal,
             id='link-6',
             title=u'Link 6',
             remoteUrl=u'${portal_url}/en/subjects/languages',
         )
    def setUp(self):
        self.portal = self.layer['portal']
        self.portal.error_log._ignored_exceptions = ()
        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')

        setupTool = SetupMultilingualSite()
        setupTool.setupSite(self.portal)
 def handle_save_action(self, action, data):
     CheckAuthenticator(self.request)
     if form.applyChanges(self.context, self.form_fields, data,
                          self.adapters):
         self.status = _Plone("Changes saved.")
         self._on_save(data)
     else:
         self.status = _Plone("No changes made.")
     setupTool = SetupMultilingualSite()
     output = setupTool.setupSite(self.context)
     self.status += output
 def setUp(self):
     self.portal = self.layer['portal']
     self.request = self.layer['request']
     self.language_tool = getToolByName(self.portal, 'portal_languages')
     self.language_tool.addSupportedLanguage('ca')
     self.language_tool.addSupportedLanguage('es')
     setRoles(self.portal, TEST_USER_ID, ['Manager'])
     login(self.portal, TEST_USER_NAME)
     workflowTool = getToolByName(self.portal, "portal_workflow")
     workflowTool.setDefaultChain('simple_publication_workflow')
     setupTool = SetupMultilingualSite()
     setupTool.setupSite(self.portal)
Exemple #16
0
 def setUp(self):
     self.portal = self.layer['portal']
     self.request = self.layer['request']
     self.language_tool = getToolByName(self.portal, 'portal_languages')
     self.language_tool.addSupportedLanguage('ca')
     self.language_tool.addSupportedLanguage('es')
     setRoles(self.portal, TEST_USER_ID, ['Manager'])
     login(self.portal, TEST_USER_NAME)
     workflowTool = getToolByName(self.portal, "portal_workflow")
     workflowTool.setDefaultChain('simple_publication_workflow')
     setupTool = SetupMultilingualSite()
     setupTool.setupSite(self.portal)
Exemple #17
0
    def setUp(self):
        with ploneSite() as portal:
            # Define available languages
            language_tool = getToolByName(portal, "portal_languages")
            language_tool.addSupportedLanguage("ca")
            language_tool.addSupportedLanguage("es")

            # Enable request negotiator
            language_tool.use_request_negotiation = True

            # Setup language root folders
            setupTool = SetupMultilingualSite()
            setupTool.setupSite(portal)
Exemple #18
0
    def test_add_all_supported_languages(self):
        """ There was a language which code is 'id'
            and it broke the root language folder setup process
        """
        language_tool = getToolByName(self.portal, 'portal_languages')
        for lang in AllContentLanguageVocabulary()(self.portal):
            language_tool.addSupportedLanguage(lang.value)

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

        setupTool = SetupMultilingualSite()
        setupTool.setupSite(self.portal)
Exemple #19
0
    def setUp(self):
        with ploneSite() as portal:
            # Define available languages
            language_tool = getToolByName(portal, 'portal_languages')
            language_tool.addSupportedLanguage('ca')
            language_tool.addSupportedLanguage('es')

            # Enable request negotiator
            language_tool.use_request_negotiation = True

            # Setup language root folders
            setupTool = SetupMultilingualSite()
            setupTool.setupSite(portal)
def install_pam(setup=None):
    """Run this Plone 4.3.x
    Install pam - we still use Archetypes, so also archetypes.multilingual
    """
    qi = api.portal.get_tool('portal_quickinstaller')
    portal = api.portal.get()

    if not qi.isProductInstalled('plone.app.multilingual'):
        qi.installProduct('plone.app.multilingual')
        qi.installProduct('archetypes.multilingual')
        from plone.app.multilingual.browser.setup import SetupMultilingualSite
        ml_setup_tool = SetupMultilingualSite()
        ml_setup_tool.setupSite(portal)
    def setUp(self):
        self.portal = self.layer["portal"]
        self.request = self.layer["request"]
        alsoProvides(self.request, IPloneAppMultilingualInstalled)
        language_tool = getToolByName(self.portal, "portal_languages")
        language_tool.addSupportedLanguage("ca")
        language_tool.addSupportedLanguage("es")

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

        setupTool = SetupMultilingualSite()
        setupTool.setupSite(self.portal)
    def setUp(self):
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        alsoProvides(self.request, IPloneAppMultilingualInstalled)
        language_tool = getToolByName(self.portal, 'portal_languages')
        language_tool.addSupportedLanguage('ca')
        language_tool.addSupportedLanguage('es')

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

        setupTool = SetupMultilingualSite()
        setupTool.folder_type = 'dxfolder'
        setupTool.setupSite(self.portal)

        self.a_ca = makeContent(self.portal.ca, 'dxdoc', id='a_ca')
    def test_type_of_language_folders(self):
        """The created objects have to be 'Language Root Folder'."""
        all_langs = AllContentLanguageVocabulary()(self.portal)
        for lang in all_langs:
            self.language_tool.addSupportedLanguage(lang.value)

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

        setup_tool = SetupMultilingualSite()
        setup_tool.setupSite(self.portal)

        for lang in all_langs.by_value.keys():
            if lang == 'id':
                self.assertEqual(self.portal.get('id-id').portal_type, 'LRF')
            else:
                self.assertEqual(self.portal.get(lang).portal_type, 'LRF')
    def test_type_of_language_folders(self):
        """The created objects have to be 'Language Root Folder'."""
        all_langs = AllContentLanguageVocabulary()(self.portal)
        for lang in all_langs:
            self.language_tool.addSupportedLanguage(lang.value)

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

        setup_tool = SetupMultilingualSite()
        setup_tool.setupSite(self.portal)

        for lang in all_langs.by_value.keys():
            if lang == 'id':
                self.assertEqual(self.portal.get('id-id').portal_type, 'LRF')
            else:
                self.assertEqual(self.portal.get(lang).portal_type, 'LRF')
    def setUp(self):
        super(TestMultilingualButton, self).setUp()
        self.grant('Manager')

        self.language_tool = getToolByName(self.portal, 'portal_languages')
        for lang in self.supported_languages:
            self.language_tool.addSupportedLanguage(lang)

        pam_setup_tool = SetupMultilingualSite()
        pam_setup_tool.setupSite(self.portal)

        self._set_lang('de')
        self.button = getMultiAdapter(
            (self.portal, self.request),
            IMobileButton,
            name='multilanguage-mobile-button'
        )
    def testRelocatorOfMisplacedContent(self):
        self.a_en = makeContent(self.portal, 'Folder', id='a_en')
        self.a_en.edit(language='en')
        self.a_1_1_ca = makeContent(self.a_en, 'Folder', id='a_1_1_ca')
        self.a_1_1_ca.edit(language='ca')
        self.a_2_1_en = makeContent(self.a_1_1_ca, 'Document', id='a_2_1_en')
        self.a_2_1_en.edit(language='en')
        self.a_2_2_ca = makeContent(self.a_1_1_ca, 'Document', id='a_2_2_ca')
        self.a_2_2_ca.edit(language='ca')
        self.a_1_2_en = makeContent(self.a_en, 'Folder', id='a_1_2_en')
        self.a_1_2_en.edit(language='en')

        self.b_ca = makeContent(self.portal, 'Folder', id='b_ca')
        self.b_ca.edit(language='ca')
        self.b_1_1_en = makeContent(self.b_ca, 'Folder', id='b_1_1_en')
        self.b_1_1_en.edit(language='en')
        self.b_2_1_en = makeContent(self.b_1_1_en, 'Document', id='b_2_1_en')
        self.b_2_1_en.edit(language='en')
        self.b_2_1_ca = makeTranslation(self.b_2_1_en, 'ca')
        transaction.commit()
        self.b_2_1_ca.edit(id='b_2_1_ca', language='ca')

        relocator_view = getMultiAdapter((self.portal, self.request),
                                          name='relocate-content')
        relocator_view.step1andstep2()

        self.assertTrue(getattr(self.portal, 'b_1_1_en', False))
        self.assertTrue(getattr(self.portal, 'a_1_1_ca', False))
        self.assertEqual(self.a_en.objectIds(), ['a_1_2_en', 'a_2_1_en'])
        self.assertEqual(self.a_en.b_1_1_en.objectIds(), ['b_2_1_en'])
        self.assertEqual(self.b_ca.objectIds(), ['b_2_1_ca'])
        self.assertEqual(self.b_ca.a_1_1_ca.objectIds(), ['a_2_2_ca'])

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

        relocator_view.step3()

        # Test that the resultant Plone site is 'clean'
        rlfs = [rlf for rlf in self.portal.objectIds() if ITranslatable.providedBy(getattr(self.portal, rlf))]
        self.assertEqual(rlfs, ['en', 'ca', 'shared'])
    def testRelocator(self):
        self.doc5 = makeContent(self.portal, 'Document', id='doc5')
        self.doc5.setLanguage('en')
        self.doc5_ca = makeTranslation(self.doc5, 'ca')
        self.doc5_ca.edit(title="Foo", language='ca')
        self.doc5_es = makeTranslation(self.doc5, 'es')
        self.doc5_es.edit(title="Foo", language='es')
        workflowTool = getToolByName(self.portal, "portal_workflow")
        workflowTool.setDefaultChain('simple_publication_workflow')
        setupTool = SetupMultilingualSite()
        setupTool.setupSite(self.portal)

        relocator_view = getMultiAdapter((self.portal, self.request),
                                          name='relocateContentByLanguage')
        relocator_view()

        self.assertTrue(getattr(self.portal.en, 'doc5', False))
        self.assertTrue(getattr(self.portal.es, 'doc5-es', False))
        self.assertTrue(getattr(self.portal.ca, 'doc5-ca', False))
    def setup_languages(self, item):
        if not HAS_MULTILINGUAL:
            raise MultilingalInflateException(
                "Defined multilingal content but plone.app.multilingual is "
                "not installed")

        self._validate_languages(item['_multilingual'])

        multilingual_setup = SetupMultilingualSite()
        multilingual_setup.setupSite(self.context)

        contents = deepcopy(item['_contents'])
        self._recursive_create_translation_group(contents)

        for lang_code in item['_multilingual']:
            lang_contents = deepcopy(contents)
            self._recursive_set_language(lang_contents, lang_code)

            yield {'_path': os.path.join(lang_code, item.get('_path', '').lstrip('/')),
                   '_children': lang_contents}
    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')
    def handleSave(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        # We need to check if the default language is in available languages
        if 'default_language' in data and 'available_languages' in data and \
                data['default_language'] not in data['available_languages']:
            IStatusMessage(self.request).addStatusMessage(
                _(u"Default language not in available languages"), "error")

            # e = Invalid(_(u"Default language not in available languages"))
            # raise WidgetActionExecutionError('default_language', e)
            return

        self.applyChanges(data)

        setupTool = SetupMultilingualSite()
        output = setupTool.setupSite(self.context)
        self.status += output
    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'
        }])
    def test_all_supported_languages(self):
        """There was a language which code is 'id'.
        This broke the root language folder setup process.
        To get rid of that the folder is 'id-id'.
        """
        all_langs = AllContentLanguageVocabulary()(self.portal)
        for lang in all_langs:
            self.language_tool.addSupportedLanguage(lang.value)

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

        setup_tool = SetupMultilingualSite()
        setup_tool.setupSite(self.portal)

        portal_objects = self.portal.objectIds()

        for lang in all_langs.by_value.keys():
            if lang == 'id':
                self.assertIn('id-id', portal_objects)
            else:
                self.assertIn(lang, portal_objects)
    def handleSave(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        # We need to check if the default language is in available languages
        if 'default_language' in data and 'available_languages' in data and \
                data['default_language'] not in data['available_languages']:
            IStatusMessage(self.request).addStatusMessage(
                _(u"Default language not in available languages"),
                "error")

            # e = Invalid(_(u"Default language not in available languages"))
            # raise WidgetActionExecutionError('default_language', e)
            return

        self.applyChanges(data)

        setupTool = SetupMultilingualSite()
        output = setupTool.setupSite(self.context)
        self.status += output
    def test_all_supported_languages(self):
        """There was a language which code is 'id'.
        This broke the root language folder setup process.
        To get rid of that the folder is 'id-id'.
        """
        all_langs = AllContentLanguageVocabulary()(self.portal)
        for lang in all_langs:
            self.language_tool.addSupportedLanguage(lang.value)

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

        setup_tool = SetupMultilingualSite()
        setup_tool.setupSite(self.portal)

        portal_objects = self.portal.objectIds()

        for lang in all_langs.by_value.keys():
            if lang == 'id':
                self.assertIn('id-id', portal_objects)
            else:
                self.assertIn(lang, portal_objects)
Exemple #35
0
    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'}
        ])
    def setup_languages(self, item):
        if not HAS_MULTILINGUAL:
            raise MultilingalInflateException(
                "Defined multilingal content but plone.app.multilingual is "
                "not installed")

        self._validate_languages(item['_multilingual'])

        multilingual_setup = SetupMultilingualSite()
        multilingual_setup.setupSite(self.context)

        contents = deepcopy(item['_contents'])
        self._recursive_create_translation_group(contents)

        for lang_code in item['_multilingual']:
            lang_contents = deepcopy(contents)
            self._recursive_set_language(lang_contents, lang_code)

            yield {
                '_path': os.path.join(lang_code,
                                      item.get('_path', '').lstrip('/')),
                '_children': lang_contents
            }
    def setup_languages(self, item):
        if not HAS_MULTILINGUAL:
            raise MultilingalInflateException(
                "Defined multilingal content but plone.app.multilingual is "
                "not installed")

        self._validate_languages(item['_multilingual'])

        multilingual_setup = SetupMultilingualSite()
        multilingual_setup.setupSite(self.context)

        contents = deepcopy(item['_contents'])
        self._recursive_create_translation_group(contents)

        for lang_code in item['_multilingual']:
            lang_contents = deepcopy(contents)
            self._recursive_set_language(lang_contents, lang_code)

            subitem = {'_path': lang_code,
                       '_children': lang_contents}
            if '_properties' in item:
                subitem['_properties'] = deepcopy(item['_properties'])
            yield subitem
Exemple #38
0
def setupMultilingual(context):
    if context.readDataFile('osha.hwccontent.txt') is None:
        return
    portal = context.getSite()

    setupTool = SetupMultilingualSite()
    setupTool.setupSite(portal)

    setupTool.setupSharedFolder()
def post_install(setup):
    """Post install script"""
    if setup.readDataFile('plonedemosite_default.txt') is None:
        return
    portal = api.portal.get()
    remove_content(portal)
    create_demo_users()
    languages = api.portal.get_registry_record('plone.available_languages')
    setupTool = SetupMultilingualSite()
    setupTool.setupSite(portal)
    for language in languages:
        container = portal[language]

        # Create frontpage for language
        frontpage = create_frontpage(
            portal, container=container, target_language=language)
        container.setDefaultPage('frontpage')
        ILanguage(frontpage).set_language(language)

        # Link the new frontpage as a translation to all existing items
        for lang in languages:
            existing_frontpage = portal[lang].get('frontpage')
            if existing_frontpage:
                ITranslationManager(existing_frontpage).register_translation(
                    language, frontpage)

        # Import zexp for language
        import_zexp(
            setup,
            filename='demo_%s.zexp' % language,
            container=container,
            name='demo',
            update=True,
            publish=True,
        )

    default_language = api.portal.get_registry_record('plone.default_language')
    default_lang_folder = portal.get(default_language)
    demo_folder = default_lang_folder.get(IMPORTED_FOLDER_ID)
    for language in languages:
        if language == default_language:
            continue
        lang_folder = portal.get(language)
        lang_demo_folder = lang_folder.get(IMPORTED_FOLDER_ID)
        if not lang_demo_folder:
            continue

        # link demo-folders
        link_translations(obj=demo_folder, translation=lang_demo_folder, language=language)  # noqa

        translated = []
        for obj1_id, obj1 in demo_folder.contentItems():
            # try to find a possible translation
            for obj2_id, obj2 in lang_demo_folder.contentItems():
                if obj2_id in translated:
                    continue
                # link the first item with the same portal_type
                if obj1.portal_type == obj2.portal_type:
                    link_translations(obj=obj1, translation=obj2, language=language)
                    translated.append(obj2_id)
                    break
Exemple #40
0
    def render(self):
        portal = api.portal.get()
        pc = api.portal.get_tool(name="portal_catalog")

        lrfs = pc.searchResults(portal_type="LRF")
        original_lrfs_ids = [lang.id for lang in lrfs]

        # Disable constrains
        pt = api.portal.get_tool('portal_types')
        pt['Plone Site'].filter_content_types = False
        PS_ALLOWED = pt['Plone Site'].allowed_content_types
        pt['Plone Site'].allowed_content_types = PS_ALLOWED + ('LRF',)
        pt['LRF'].global_allow = True
        pt['LIF'].global_allow = True
        LRF_ALLOWED = pt['LRF'].allowed_content_types
        pt['LRF'].allowed_content_types = LRF_ALLOWED + ('LIF', 'BannerContainer', 'Logos_Container')

        for lrf in lrfs:
            api.content.rename(obj=lrf.getObject(), new_id='{}_old'.format(lrf.id))

        setupTool = SetupMultilingualSite()
        setupTool.setupSite(self.context, False)

        for old_lrf in original_lrfs_ids:
            # If a 'media' folder exists, delete it as we are going to put it
            # back later
            if portal[old_lrf + '_old'].get('media', False):
                api.content.delete(obj=portal[old_lrf + '_old']['media'])
            if portal[old_lrf].get('media', False):
                api.content.delete(obj=portal[old_lrf]['media'])

            for obj in portal[old_lrf + '_old'].objectIds():
                # Only to contentish objects as the original LRF is leaking root
                # objects
                if portal[old_lrf + '_old'].get(obj, False):
                    origin = portal[old_lrf + '_old'][obj].id
                    api.content.move(source=portal[old_lrf + '_old'][obj], target=portal[old_lrf])
                    print '{} ==> {}'.format(origin, portal[old_lrf])

        # Assert things are moved correctly and no object remains in old folders
        for old_lrf in original_lrfs_ids:
            assert not portal[old_lrf + '_old'].get(obj, False)

        # If so, delete original LRFs
        for old_lrf in original_lrfs_ids:
            api.content.delete(obj=portal[old_lrf + '_old'])

        # Rename original 'shared' folder
        if portal.get('shared', False):
            api.content.rename(obj=portal['shared'], new_id='shared_old')

        # Put back 'shared' folder
        # for lrf in lrfs:
        #     api.content.create(container=portal[lrf.id], type='LIF', id='shared')
        #     portal[lrf.id]['shared'].title = 'Fitxers compartits'
        #     if lrf == 'es':
        #         portal[lrf.id]['shared'].title = 'Ficheros compartidos'
        #     if lrf == 'en':
        #         portal[lrf.id]['shared'].title = 'Shared files'

        # Move shared folder content
        # if portal.get('shared', False):
        #     for obj_id in portal['shared']:
        #         api.content.move(source=portal['shared'][obj_id], target=portal['ca']['shared'])
        #         print '{} ==> {}'.format(obj_id, portal['ca']['shared'].id)

        # Put back constrains
        pt['Plone Site'].filter_content_types = True
        pt['Plone Site'].allowed_content_types = PS_ALLOWED
        pt['LRF'].global_allow = False
        pt['LIF'].global_allow = False
        pt['LRF'].allowed_content_types = LRF_ALLOWED

        # Finally, clear and rebuild catalog
        pc.clearFindAndRebuild()
Exemple #41
0
def init_pam(tool):
    """After installation run setup to create LRF and LIF."""
    setup_tool = SetupMultilingualSite()
    setup_tool.setupSite(getSite())
 def set_move_content_to_language_folder(self, value):
     if value:
         SetupMultilingualSite(self.context).move_default_language_content()
 def set_set_default_language(self, value):
     if value:
         SetupMultilingualSite(self.context).set_default_language_content()
Exemple #44
0
def init_pam(tool):
    """After installation run setup to create LRF and LIF."""
    setup_tool = SetupMultilingualSite()
    setup_tool.setupSite(getSite())
 def set_available_languages(self, value):
     languages = [str(l) for l in value]
     self.context.supported_langs = languages
     setupTool = SetupMultilingualSite()
     setupTool.setupSite(self.context)