def resetDefaultPage(self): """Maintain the default page of the site on the language it was defined """ previousDefaultPage = getattr(self.context, self.previousDefaultPageId) languageWrapped = ILanguage(previousDefaultPage, None) # If the previous default page cannot be adapted, do nothing. # This might be the case if it is a Python Script or other non-portal # content if languageWrapped is None: return False language = languageWrapped.get_language() pageId = self.previousDefaultPageId # test language neutral if language == '': language = self.defaultLanguage target = self.folders[language] objects = self.context.manage_cutObjects(pageId) try: target.manage_pasteObjects(objects) except ValueError, exc: # This portal_type may not be allowed. This should not be # fatal, so we only log a warning. logger.warn((u"Could not move default page '{0:s}' j" u"to folder '{1:s}': {2:s}").format( pageId, target.getId(), exc)) return False
def current_language_name(self): """ Get the current language native name """ adapted = ILanguage(self.context) lang_code = adapted.get_language() util = getUtility(IContentLanguageAvailability) data = util.getLanguages(True) lang_info = data.get(lang_code) return lang_info.get('native', None) or lang_info.get('name')
def test_move_content_existing_translation_inside(self): f_ca = createContentInContainer(self.portal['ca'], 'Folder', title=u"Test folder") a_ca = createContentInContainer(self.portal['ca']['test-folder'], 'Document', title=u"Test document") a_en = api.translate(a_ca, 'en') translations = ITranslationManager(self.portal['en'][a_en.id]) self.assertEqual( translations.get_translations(), { 'ca': self.portal['ca'][f_ca.id][a_ca.id], 'en': self.portal['en'][a_ca.id] }) self.assertIn(a_en.id, self.portal['en'].objectIds()) self.assertEqual(a_en, self.portal['en'][a_en.id]) # Change the content language of the created folder to 'en' multilingualMoveObject(f_ca, 'en') self.assertIn(f_ca.id, self.portal['en'].objectIds()) self.assertEqual(f_ca, self.portal['en'][f_ca.id]) self.assertIn(a_ca.id, self.portal['en'][f_ca.id].objectIds()) self.assertEqual(a_ca, self.portal['en'][f_ca.id][a_ca.id]) adapter = ILanguage(self.portal['en'][f_ca.id]) self.assertEqual(adapter.get_language(), 'en') adapter = ILanguage(self.portal['en'][f_ca.id][a_ca.id]) self.assertEqual(adapter.get_language(), 'en') translations = ITranslationManager(self.portal['en'][f_ca.id][a_ca.id]) self.assertEqual(translations.get_translations(), {'en': self.portal['en'][f_ca.id][a_ca.id]}) translations = ITranslationManager(self.portal['en'][a_en.id]) self.assertEqual(translations.get_translations(), {'en': self.portal['en'][a_en.id]})
def test_move_content_existing_translation_inside(self): f_ca = createContentInContainer( self.portal['ca'], 'Folder', title=u"Test folder") a_ca = createContentInContainer( self.portal['ca']['test-folder'], 'Document', title=u"Test document") a_en = api.translate(a_ca, 'en') translations = ITranslationManager(self.portal['en'][a_en.id]) self.assertEqual(translations.get_translations(), {'ca': self.portal['ca'][f_ca.id][a_ca.id], 'en': self.portal['en'][a_ca.id]}) self.assertIn(a_en.id, self.portal['en'].objectIds()) self.assertEqual(a_en, self.portal['en'][a_en.id]) # Change the content language of the created folder to 'en' multilingualMoveObject(f_ca, 'en') self.assertIn(f_ca.id, self.portal['en'].objectIds()) self.assertEqual(f_ca, self.portal['en'][f_ca.id]) self.assertIn(a_ca.id, self.portal['en'][f_ca.id].objectIds()) self.assertEqual(a_ca, self.portal['en'][f_ca.id][a_ca.id]) adapter = ILanguage(self.portal['en'][f_ca.id]) self.assertEqual(adapter.get_language(), 'en') adapter = ILanguage(self.portal['en'][f_ca.id][a_ca.id]) self.assertEqual(adapter.get_language(), 'en') translations = ITranslationManager(self.portal['en'][f_ca.id][a_ca.id]) self.assertEqual(translations.get_translations(), {'en': self.portal['en'][f_ca.id][a_ca.id]}) translations = ITranslationManager(self.portal['en'][a_en.id]) self.assertEqual(translations.get_translations(), {'en': self.portal['en'][a_en.id]})
def test_move_content_proper_language_folder(self): f_ca = createContentInContainer( self.portal['ca'], 'Folder', title=u"Test folder") a_ca = createContentInContainer( self.portal['ca']['test-folder'], 'Document', title=u"Test document") # Change the content language of the created folder to 'es' multilingualMoveObject(f_ca, 'es') self.assertIn(f_ca.id, self.portal['es'].objectIds()) self.assertEqual(f_ca, self.portal['es'][f_ca.id]) self.assertIn(a_ca.id, self.portal['es'][f_ca.id].objectIds()) self.assertEqual(a_ca, self.portal['es'][f_ca.id][a_ca.id]) adapter = ILanguage(self.portal['es'][f_ca.id]) self.assertEqual(adapter.get_language(), 'es') adapter = ILanguage(self.portal['es'][f_ca.id][a_ca.id]) self.assertEqual(adapter.get_language(), 'es')
def test_move_content_proper_language_folder(self): f_ca = createContentInContainer(self.portal['ca'], 'Folder', title=u"Test folder") a_ca = createContentInContainer(self.portal['ca']['test-folder'], 'Document', title=u"Test document") # Change the content language of the created folder to 'es' multilingualMoveObject(f_ca, 'es') self.assertIn(f_ca.id, self.portal['es'].objectIds()) self.assertEqual(f_ca, self.portal['es'][f_ca.id]) self.assertIn(a_ca.id, self.portal['es'][f_ca.id].objectIds()) self.assertEqual(a_ca, self.portal['es'][f_ca.id][a_ca.id]) adapter = ILanguage(self.portal['es'][f_ca.id]) self.assertEqual(adapter.get_language(), 'es') adapter = ILanguage(self.portal['es'][f_ca.id][a_ca.id]) self.assertEqual(adapter.get_language(), 'es')