class ConnectTranslation(AutoExtensibleForm, Form): schema = IFormFieldProvider(IConnectTranslation) ignoreContext = True label = _(u"label_connect_translation", default=u"Connect translation") description = _( u"long_description_connect_translation", default=u"This form allows you to connect a currently existing " u"translations of the current object.") @button.buttonAndHandler( _(u"connect_translation", default=u"Connect translation")) def handle_add(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return content = data['content'] language = data['language'] ILanguage(content).set_language(language) itm = ITranslationManager(self.context) # the 'register_translation'-method takes content OR # UUID as second parameter. We need to use the UUID # here because otherwise the catalog can't be acquired # and the translation index is not updated itm.register_translation(language, IUUID(content)) return self.request.response.redirect(self.context.absolute_url() + '/modify_translations')
class RemoveTranslationsForm(AutoExtensibleForm, Form): schema = IFormFieldProvider(IRemoveTranslation) ignoreContext = True label = _(u"label_remove_translations", default=u"Remove translations") description = _(u"long_description_remove_translations", default=u"This form allows you to remove the existing " u"translations of the current object. You can " u"just delete the link between the objects " u"or you can delete the object itself.") @button.buttonAndHandler(_(u"unlink selected"), name='unlink') def handle_unlink(self, action): data, errors = self.extractData() manager = ITranslationManager(self.context) if not errors: for language in data['languages']: manager.remove_translation(language) return self.request.response.redirect(self.context.absolute_url() + '/remove_translations') @button.buttonAndHandler(_(u"remove selected"), name='remove') def handle_remove(self, action): data, errors = self.extractData() manager = ITranslationManager(self.context) if not errors: for language in data['languages']: content = manager.get_translation(language) manager.remove_translation(language) aq_parent(content).manage_delObjects([content.getId()]) return self.request.response.redirect(self.context.absolute_url() + '/remove_translations')
def __call__(self): if (self.request.method != 'POST' and not ('field' in self.request.form.keys() and 'lang_source' in self.request.form.keys())): return _("Need a field") else: manager = ITranslationManager(self.context) registry = getUtility(IRegistry) settings = registry.forInterface(IMultiLanguageExtraOptionsSchema) lang_target = ILanguage(self.context).get_language() lang_source = self.request.form['lang_source'] orig_object = manager.get_translation(lang_source) try: question = orig_object.getField( self.request.form['field']).get(orig_object) except AttributeError: return _("Invalid field") if len(question) > 1600: return _("Too long field") data = { 'key': settings.google_translation_key, 'target': lang_target, 'source': lang_source, 'q': question } params = urllib.urlencode(data) url = 'https://www.googleapis.com/language/translate/v2' retorn = urllib.urlopen(url + '?' + params) return retorn.read()
class UpdateLanguageForm(form.SchemaForm): grok.name("update_language") grok.context(ITranslatable) grok.require("cmf.ModifyPortalContent") schema = form.IFormFieldProvider(IUpdateLanguage) ignoreContext = True label = _(u"label_update_language", default=u"Update Language") status = _( u"label_alert_update", default= u"""By updating the content language will trigger its move to the correct language folder in the site's hierarchy""" ) @button.buttonAndHandler(_(u"update_language", default=u"Update Language")) def handle_update(self, action): data, errors = self.extractData() new_object = self.context if not errors: language = data['language'] # We need to move the object to its place!! new_object = multilingualMoveObject(self.context, language) return self.request.response.redirect(new_object.absolute_url() + '?set_language=' + language)
class RemoveTranslationsForm(form.SchemaForm): grok.name("remove_translations") grok.context(ITranslatable) grok.require("plone.app.multilingual.ManageTranslations") schema = form.IFormFieldProvider(IRemoveTranslation) ignoreContext = True label = _(u"label_remove_translations") @button.buttonAndHandler(_(u"unlink selected")) def handle_unlink(self, action): data, errors = self.extractData() manager = ITranslationManager(self.context) if not errors: for language in data['languages']: manager.remove_translation(language) return self.request.response.redirect(self.context.absolute_url() \ + '/remove_translations') @button.buttonAndHandler(_(u"remove selected")) def handle_remove(self, action): data, errors = self.extractData() manager = ITranslationManager(self.context) if not errors: for language in data['languages']: content = manager.get_translation(language) manager.remove_translation(language) aq_parent(content).manage_delObjects([content.getId()]) return self.request.response.redirect(self.context.absolute_url() \ + '/remove_translations')
def __call__(self): if (self.request.method != 'POST' and not ('field' in self.request.form.keys() and 'lang_source' in self.request.form.keys())): return _("Need a field") else: manager = ITranslationManager(self.context) registry = getUtility(IRegistry) settings = registry.forInterface(IMultiLanguageExtraOptionsSchema) lang_target = ILanguage(self.context).get_language() lang_source = self.request.form['lang_source'] orig_object = manager.get_translation(lang_source) try: question = orig_object.getField( self.request.form['field']).get(orig_object) except AttributeError: return _("Invalid field") if len(question) > 1600: return _("Too long field") data = {'key': settings.google_translation_key, 'target': lang_target, 'source': lang_source, 'q': question} params = urllib.urlencode(data) url = 'https://www.googleapis.com/language/translate/v2' retorn = urllib.urlopen(url + '?' + params) return retorn.read()
class AddTranslationsForm(AutoExtensibleForm, Form): schema = IFormFieldProvider(IAddTranslation) ignoreContext = True label = _(u"label_add_translations", default=u"Add translations") description = _( u"long_description_add_translations", default=u"This form allows you to add currently existing " u"objects to be the translations of the current " u"object. You have to manually select both the " u"language and the object." ) @button.buttonAndHandler(_(u"add_translations", default=u"Add translations")) def handle_add(self, action): data, errors = self.extractData() if not errors: content = data['content'] language = data['language'] ITranslationManager(self.context)\ .register_translation(language, content) ILanguage(content).set_language(language) return self.request.response.redirect( self.context.absolute_url() + '/add_translations')
class TranslateSubMenuItem(BrowserSubMenuItem): implements(ITranslateSubMenuItem) title = _(u"label_translate_menu", default=u"Translate") description = _(u"title_translate_menu", default="Manage translations for your content.") submenuId = "plone_contentmenu_multilingual" order = 5 extra = {"id": "plone-contentmenu-multilingual"} @property def action(self): return self.context.absolute_url() + "/add_translations" @memoize def available(self): if not IPloneAppMultilingualInstalled.providedBy(self.request): return False lt = getToolByName(self.context, 'portal_languages', None) if lt is None: return False supported = lt.listSupportedLanguages() if len(supported) < 2: return False return True def selected(self): return False
class IUpdateLanguage(form.Schema): language = schema.Choice( title=_(u"title_available_languages", default=u"Available languages"), description=_( u"description_update_language", default=u"Untranslated languages from the current content"), source=untranslated_languages, required=True, )
class IRemoveTranslation(form.Schema): languages = schema.List( title=_(u"title_languages"), value_type=schema.Choice( title=_(u"title_language", default=u"Language"), source=deletable_languages, ), required=True, ) form.widget(languages='z3c.form.browser.select.SelectFieldWidget')
class IAddTranslation(model.Schema): language = schema.Choice( title=_(u"title_language", default=u"Language"), source=untranslated_languages, required=True, ) content = RelationChoice( title=_(u"content"), vocabulary="plone.app.vocabularies.Catalog", required=True, )
class IAddTranslation(form.Schema): language = schema.Choice( title=_(u"title_language", default=u"Language"), source=untranslated_languages, required=True, ) content = RelationChoice( title=_(u"content"), source=addTranslation, required=True, )
class IAddTranslation(form.Schema): language = schema.Choice( title=_(u"title_language", default=u"Language"), source=untranslated_languages, required=True, ) content = RelationChoice( title=_(u"content"), source=ObjPathSourceBinder({'language': 'all'}), required=True, )
def __call__(self): plone_utils = getToolByName(self.context, "plone_utils") if self.context.__class__ == LanguageRootFolder: self.request.response.redirect(self.context.absolute_url()) return if not IPloneSiteRoot.providedBy(aq_parent(aq_inner(self.context))): plone_utils.addPortalMessage( _(u"folder_to_lrf_not_next_to_root", default=u"Only folders just below the root " u"can be transformed") ) self.request.response.redirect(self.context.absolute_url()) return portal_languages = getToolByName(self.context, "portal_languages") available_languages = portal_languages.getAvailableLanguages() if self.context.id not in available_languages.keys(): plone_utils.addPortalMessage( _(u"folder_to_lrf_id_not_language", default=u"Folder's id is not a valid language code") ) self.request.response.redirect(self.context.absolute_url()) return # Do the transform self.context.__class__ = LanguageRootFolder self.context._p_changed = aq_parent(self.context).p_changed = True self.context.portal_type = 'LRF' # Update content language portal_catalog = getToolByName(self.context, "portal_catalog") search_results = portal_catalog.unrestrictedSearchResults( path='/'.join(self.context.getPhysicalPath())) for brain in search_results: ob = brain._unrestrictedGetObject() language_aware = ILanguage(ob, None) if language_aware is not None: language_aware.set_language(self.context.id) ob.reindexObject(idxs=['Language', 'TranslationGroup']) plone_utils.addPortalMessage( _(u"folder_to_lrf_success", default=u"Folder has been successfully transformed to " u"a language root folder") ) self.request.response.redirect(self.context.absolute_url())
class LP2PAMAfterView(BrowserView): template = ViewPageTemplateFile('templates/cleanup_results.pt') stepinfo = _(u"After migration relation cleanup") def reset_relation_catalog(self): """Sometimes there are dependencies to the ITranslatable interface hidden in the relation catalog. This reset gets rid of them. (Assuming that Products.LinguaPlone is already uninstalled). """ try: catalog = getUtility(ICatalog) except ComponentLookupError: return 0, ['A zc.relation catalog is not present.'] relations = catalog.findRelations() catalog.clear() total = 0 bad = [] for relation in relations: total += 1 try: catalog.index(relation) except KeyError: # If you read this because you wonder why you have many # missing relations, please inform do3cc logger.warning("A relation could not be recreated. You have " "lost relations") bad.append(str(relation.__dict__)) return total, bad def __call__(self): total, bad = self.reset_relation_catalog() self.total = total self.bad = bad return self.template()
class TranslationForm(form.SchemaForm): """ Translation Form """ grok.name('create_translation') grok.context(ITranslatable) grok.require('plone.app.multilingual.ManageTranslations') schema = ICreateTranslation ignoreContext = True @button.buttonAndHandler(_(u'Create')) def handle_create(self, action): data, errors = self.extractData() if not errors: language = data['language'] translation_manager = ITranslationManager(aq_inner(self.context)) if ILanguage(self.context).get_language() == LANGUAGE_INDEPENDENT: language_tool = getToolByName(self.context, 'portal_languages') default_language = language_tool.getDefaultLanguage() ILanguage(self.context).set_language(default_language) translation_manager.update() self.context.reindexObject(idxs='language') translation_manager.add_translation(language) translated = translation_manager.get_translation(language) registry = getUtility(IRegistry) settings = registry.forInterface(IMultiLanguageExtraOptionsSchema) if settings.redirect_babel_view: return self.request.response.redirect( translated.absolute_url() + '/babel_edit?set_language=%s' % language) else: return self.request.response.redirect( translated.absolute_url() + '/edit?set_language=%s' % language)
class LP2PAMView(BrowserView): """View for migrating multilingual catalog from LP to PAM. """ template = ViewPageTemplateFile('templates/migrator-results.pt') stepinfo = _(u"Transfer multilingual catalog information") def __call__(self): pc = getToolByName(self.context, 'portal_catalog') pl = getToolByName(self.context, 'portal_languages') self.results = [] for language_supported in pl.getSupportedLanguages(): translated_objects = pc.searchResults( object_provides=LP_TRANSLATABLE, Language=language_supported) for brain in translated_objects: obj = brain.getObject() if obj.isCanonical(): translations = obj.getTranslations(include_canonical=False) manager = ITranslationManager(obj) if translations: for language in translations.keys(): try: manager.register_translation( language, translations[language][0]) except KeyError: logger.info( '%s already translated to %s: %s' % (obj.id, language, str(manager.get_translations()))) self.results.append(str(manager.get_translations())) logger.info('Finished with transferring catalog information') return self.template()
class TranslateSubMenuItem(BrowserSubMenuItem): title = _(u"label_translate_menu", default=u"Translate") description = _(u"title_translate_menu", default="Manage translations for your content.") submenuId = "plone_contentmenu_multilingual" order = 5 extra = {"id": "plone-contentmenu-multilingual"} @property def action(self): return self.context.absolute_url() + "/add_translations" @property def extra(self): return { 'id': 'plone-contentmenu-multilingual', 'li_class': 'plonetoolbar-multilingual' } @view.memoize def available(self): # Is PAM installed? if not IPloneAppMultilingualInstalled.providedBy(self.request): return False # Do we have portal_languages? lt = getToolByName(self.context, 'portal_languages', None) if lt is None: return False # Do we have multiple languages? supported = lt.listSupportedLanguages() if len(supported) < 2: return False # And now check permissions sm = getSecurityManager() if not sm.checkPermission(ManageTranslations, self.context): return False return True def selected(self): return False
def __call__(self): if (self.request.method != 'POST' and not ('field' in self.request.form.keys() and 'lang_source' in self.request.form.keys())): return _("Need a field") else: manager = ITranslationManager(self.context) registry = getUtility(IRegistry) settings = registry.forInterface(IMultiLanguageExtraOptionsSchema) lang_target = ILanguage(self.context).get_language() lang_source = self.request.form['lang_source'] orig_object = manager.get_translation(lang_source) try: question = orig_object.getField( self.request.form['field']).get(orig_object) except AttributeError: return _("Invalid field") return google_translate(question, settings.google_translation_key, lang_target, lang_source)
class IConnectTranslation(model.Schema): language = schema.Choice( title=_(u"title_language", default=u"Language"), source=untranslated_languages, defaultFactory=request_language, required=True, ) content = RelationChoice( title=_(u"content"), vocabulary="plone.app.multilingual.RootCatalog", required=True, ) if HAS_MOCKUP_240: directives.widget('content', RelatedItemsFieldWidget, pattern_options={ 'basePath': make_relation_root_path, })
def __call__(self): if (self.request.method != 'POST' and not ('field' in self.request.form.keys() and 'lang_source' in self.request.form.keys())): return _("Need a field") else: manager = ITranslationManager(self.context) registry = getUtility(IRegistry) settings = registry.forInterface(IMultiLanguageExtraOptionsSchema) lang_target = ILanguage(self.context).get_language() lang_source = self.request.form['lang_source'] orig_object = manager.get_translation(lang_source) field = self.request.form['field'].split('.')[-1] if hasattr(orig_object, field): question = getattr(orig_object, field, '') if hasattr(question, 'raw'): question = question.raw else: return _("Invalid field") return google_translate(question, settings.google_translation_key, lang_target, lang_source)
class IMultiLanguageExtraOptionsSchema(Interface): """ Interface for language extra options - control panel fieldset """ filter_content = schema.Bool( title=_(u"heading_filter_content", default=u"Filter content by language."), description=_( u"description_filter_content", default=u"Filter using language the content on folder_contents"), default=True, required=False, ) redirect_babel_view = schema.Bool( title=_(u"heading_redirect_babel_view", default=u"Redirect on creation to babel view."), description=_( u"description_redirect_babel_view", default=(u"After creating a new translation redirecto to babel " u"view")), default=True, required=False, ) google_translation_key = schema.TextLine( title=_(u"heading_google_translation_key", default=u"Google Translation API Key"), description=_( u"description_google_translation_key", default=(u"Is a paying API in order to use google translation " u"service")), required=False, )
class TranslateSubMenuItem(BrowserSubMenuItem): implements(ITranslateSubMenuItem) title = _(u"label_translate_menu", default=u"Translate into...") description = _(u"title_translate_menu", default="Manage translations for your content.") submenuId = "plone_contentmenu_multilingual" order = 5 extra = {"id": "plone-contentmenu-multilingual"} @property def action(self): return self.context.absolute_url() + "/add_translations" @memoize def available(self): # this menu is only for ITranslatable, # IPloneAppMultilingualInstalled available return True def selected(self): return False
class AddTranslationsForm(form.SchemaForm): grok.name("add_translations") grok.context(ITranslatable) grok.require("plone.app.multilingual.ManageTranslations") schema = form.IFormFieldProvider(IAddTranslation) ignoreContext = True label = _(u"label_add_translations", default=u"Add translations") @button.buttonAndHandler( _(u"add_translations", default=u"Add translations")) def handle_add(self, action): data, errors = self.extractData() if not errors: content = data['content'] language = data['language'] ITranslationManager(self.context).register_translation(language,\ content) ILanguage(content).set_language(language) return self.request.response.redirect(self.context.absolute_url()\ + '/add_translations')
class ConnectTranslation(AutoExtensibleForm, Form): schema = IFormFieldProvider(IConnectTranslation) ignoreContext = True label = _(u"label_connect_translation", default=u"Connect translation") description = _( u"long_description_connect_translation", default=u"This form allows you to connect a currently existing " u"translations of the current object." ) @button.buttonAndHandler(_(u"connect_translation", default=u"Connect translation")) def handle_add(self, action): data, errors = self.extractData() if not errors: content = data['content'] language = data['language'] ITranslationManager(self.context)\ .register_translation(language, content) ILanguage(content).set_language(language) return self.request.response.redirect( self.context.absolute_url() + '/modify_translations')
class UpdateLanguageForm(form.Form): """ A form to change language """ fields = field.Fields(IUpdateLanguage) ignoreContext = True output = None @button.buttonAndHandler(_(u"update_language", default=u"Update Language")) def handle_update(self, action): data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return new_object = self.context language = data['language'] # We need to move the object to its place!! new_object = multilingualMoveObject(self.context, language) return self.request.response.redirect(new_object.absolute_url() + '?set_language=' + language)
def getMenuItems(self, context, request): """Return menu item entries in a TAL-friendly form. """ try: lang_names = request.locale.displayNames.languages except AttributeError: lang_names = {} menu = [] url = context.absolute_url() lt = getToolByName(context, "portal_languages") site_url = getSite().absolute_url() showflags = lt.showFlags context_id = ITranslationManager(context).tg registry = getUtility(IRegistry) settings = registry.forInterface(IMultiLanguageExtraOptionsSchema, prefix="plone") edit_view = 'babel_edit' if settings.redirect_babel_view else 'edit' # In case is neutral language show set language menu only is_neutral_content = (ILanguage(context).get_language() == LANGUAGE_INDEPENDENT or is_language_independent(context)) shared_folder_url = site_url + '/folder_contents' pc = getToolByName(getSite(), 'portal_catalog') results = pc.unrestrictedSearchResults( portal_type='LIF', Language=ILanguage(context).get_language()) for brain in results: shared_folder_url = brain.getURL() + '/folder_contents' if not is_neutral_content and not INavigationRoot.providedBy(context): menu.append({ "title": _(u"title_babel_edit", default=u"Edit with babel view"), "description": _(u"description_babel_edit", default=u"Edit with the babel_edit"), "action": url + "/" + edit_view, "selected": False, "icon": None, "extra": { "id": "_edit_babel_edit", "separator": None, "class": "", }, "submenu": None, }) if ITranslatable.providedBy(context): contexts = [ context, ] else: contexts = [] prt = aq_parent(context) if is_default_page(prt, context) and ITranslatable.providedBy(prt): contexts.append(prt) for idx, context in enumerate(contexts): url = context.absolute_url() ulangs = untranslated_languages(context) for lang in ulangs: lang_name = lang_names.get(lang.value, lang.title) lang_id = lang.value icon = showflags and lt.getFlagForLanguageCode(lang_id)\ or None item = { "description": _(u"description_translate_into", default=u"Translate into ${lang_name}", mapping={"lang_name": lang_name}), "action": "%s/@@create_translation?language=%s" % (url, lang_id), "selected": False, "icon": icon, "width": "14", "height": "11", "extra": { "id": "translate_into_%s" % lang_id, "separator": None, "class": "contentmenuflags" }, "submenu": None, } item['title'] = idx and _( u'create_translation_folder', default=u"Create ${lang_name} folder", mapping={"lang_name": lang_name}) or _( u'create_translation', default=u"Create ${lang_name}", mapping={"lang_name": lang_name}) menu.append(item) langs = translated_languages(context) urls = translated_urls(context) for lang in langs: if lang.value not in urls.by_token: # omit if translation is not permitted to access. continue lang_name = lang_names.get(lang.value, lang.title) lang_id = lang.value icon = showflags and lt.getFlagForLanguageCode(lang_id)\ or None item = { "description": _(u"description_babeledit_menu", default=u"Babel edit ${lang_name}", mapping={"lang_name": lang_name}), "action": (urls.getTerm(lang_id).title + "/" + edit_view), "selected": False, "icon": icon, "width": "14", "height": "11", "extra": { "id": "babel_edit_%s" % lang_id, "separator": None, "class": "contentmenuflags" }, "submenu": None, } item['title'] = idx and _( u'edit_translation_folder', default=u"Edit ${lang_name} folder", mapping={"lang_name": lang_name}) or _( u'edit_translation', default=u"Edit ${lang_name}", mapping={"lang_name": lang_name}) menu.append(item) item = { "description": _(u"description_add_translations", default=u"Add existing content as translation"), "action": url + "/add_translations", "selected": False, "icon": None, "extra": { "id": "_add_translations", "separator": langs and "actionSeparator" or None, "class": "" }, "submenu": None, } item['title'] = idx and _( u"title_add_translations_folder", default=u"Add translations for folder...") or _( u"title_add_translations", default=u"Add translations...") menu.append(item) item = { "title": _(u"title_remove_translations", default=u"Remove translations..."), "description": _(u"description_remove_translations", default=u"Delete translations or remove the relations"), "action": url + "/remove_translations", "selected": False, "icon": None, "extra": { "id": "_remove_translations", "separator": langs and "actionSeparator" or None, "class": "" }, "submenu": None, } menu.append(item) elif is_neutral_content: menu.append({ "title": _(u"language_folder", default=u"Return to language folder"), "description": _(u"description_language_folder", default=u"Go to the user's browser preferred language " u"related folder"), "action": site_url + '/' + lt.getPreferredLanguage(), "selected": False, "icon": None, "extra": { "id": "_shared_folder", "separator": None, "class": "" }, "submenu": None, }) if not is_neutral_content: menu.append({ "title": _(u"universal_link", default=u"Universal Link"), "description": _(u"description_universal_link", default=u"Universal Language content link"), "action": "%s/@@multilingual-universal-link/%s" % (site_url, context_id), "selected": False, "icon": None, "extra": { "id": "_universal_link", "separator": None, "class": "" }, "submenu": None, }) menu.append({ "title": _(u"shared_folder", default=u"Go to shared folder"), "description": _(u"description_shared_folder", default=u"Show the language shared (neutral language) " u"folder"), "action": shared_folder_url, "selected": False, "icon": None, "extra": { "id": "_shared_folder", "separator": None, "class": "" }, "submenu": None, }) menu.append({ "title": _(u"title_set_language", default=u"Set content language"), "description": _(u"description_set_language", default=u"Set or change the current content language"), "action": url + "/update_language", "selected": False, "icon": None, "extra": { "id": "_set_language", "separator": None, "class": "" }, "submenu": None, }) return menu
def getMenuItems(self, context, request): """Return menu item entries in a TAL-friendly form. """ # Settings site_url = getSite().absolute_url() language_tool = getToolByName(context, "portal_languages") show_flags = language_tool.showFlags try: lang_names = request.locale.displayNames.languages except AttributeError: lang_names = {} registry = getUtility(IRegistry) settings = registry.forInterface(IMultiLanguageExtraOptionsSchema, prefix="plone") if settings.redirect_babel_view: translation_view = 'babel_edit' else: translation_view = 'edit' # Content content = context content_url = context.absolute_url() content_language = ILanguage(content).get_language() content_translatable = not ( content_language == LANGUAGE_INDEPENDENT or is_language_independent(content) or ILanguageRootFolder.providedBy(content) ) content_translated = translated_languages(content) content_untranslated = untranslated_languages(content) content_translation_group = ITG(content, '') if not ITranslatable.providedBy(content): content = None # Folder when content is default page folder = aq_parent(context) if not is_default_page(folder, context): folder = None if folder and ITranslatable.providedBy(folder): # noqa folder_url = folder.absolute_url() folder_language = ILanguage(folder).get_language() folder_translatable = not ( folder_language == LANGUAGE_INDEPENDENT or is_language_independent(folder) or ILanguageRootFolder.providedBy(folder) ) folder_translated = translated_languages(folder) folder_untranslated = untranslated_languages(folder) folder_translation_group = ITG(folder, '') else: folder_url = '' folder_language = '' folder_translatable = False folder_translated = [] folder_untranslated = [] folder_translation_group = '' # Assets folder assets_folder_url = None assets_folder_title = None pc = getToolByName(getSite(), 'portal_catalog') results = pc.unrestrictedSearchResults( portal_type='LIF', Language=ILanguage(context).get_language()) for brain in results: assets_folder_url = brain.getURL() + '/folder_contents' assets_folder_title = safe_unicode(brain.Title) break # Menu items results = [] results_folder = [] results_content = [] if folder_translatable: # Folder translation view lang_name = lang_names.get(folder_language, folder_language) results_folder.append({ "title": _( u'edit_translation', default=u"Edit ${lang_name}", mapping={"lang_name": lang_name} ), "description": _( u"description_babeledit_menu", default=u"Edit {lang_name} with the two-column translation view", # noqa mapping={"lang_name": lang_name} ), "action": folder_url + "/" + translation_view, "selected": False, "icon": None, "extra": { "id": "_edit_folder_babel_edit", "separator": None, "class": "", }, "submenu": None, }) if folder and folder_untranslated and False: # disabled in favor of cut & paste # noqa # Set folder language results_folder.append({ "title": _( u'title_set_language', default=u"Change content language" ), "description": _( u"description_set_language", default=u"Move the translation under another language folder" # noqa ), "action": folder_url + "/update_language", "selected": False, "icon": None, "extra": { "id": "_set_folder_language", "separator": None, "class": "" }, "submenu": None, }) if folder_translatable: for idx, lang in enumerate(folder_untranslated): lang_name = lang_names.get(lang.value, lang.title) lang_id = lang.value icon = show_flags and language_tool.getFlagForLanguageCode(lang_id) or None # noqa results_folder.append({ "title": _( u'create_translation', default=u"Create ${lang_name}", mapping={"lang_name": lang_name} ), "description": _( u"description_translate_into", default=u"Translate into ${lang_name}", mapping={"lang_name": lang_name} ), "action": "%s/@@create_translation?language=%s" % ( folder_url, lang_id), "selected": False, "icon": icon, "width": "14", "height": "11", "extra": {"id": "translate_folder_into_%s" % lang_id, "separator": None, "class": "contentmenuflags"}, "submenu": None, }) urls = translated_urls(folder) for lang in folder_translated: if lang.value not in urls.by_token: # omit if translation is not permitted to access. continue lang_name = lang_names.get(lang.value, lang.title) lang_id = lang.value icon = show_flags and language_tool.getFlagForLanguageCode(lang_id) or None # noqa results_folder.append({ "title": _( u'edit_translation', default=u"Edit ${lang_name}", mapping={"lang_name": lang_name} ), "description": _( u"description_babeledit_menu", default=u"Edit {lang_name} with the two-column translation view", # noqa mapping={"lang_name": lang_name} ), "action": (urls.getTerm(lang_id).title + "/" + translation_view), "selected": False, "icon": icon, "width": "14", "height": "11", "extra": {"id": "babel_edit_%s" % lang_id, "separator": None, "class": "contentmenuflags"}, "submenu": None, }) # Manage folder translations results_folder.append({ "title": _( u"title_modify_translations", default=u"Manage translations" ), "description": _( u"description_modify_translations", default=u"Add or delete translations" ), "action": folder_url + "/modify_translations", "selected": False, "icon": None, "extra": { "id": "_modify_folder_translations", "separator": None, "class": "" }, "submenu": None, }) # Universal link if folder_translation_group: results_folder.append({ "title": _( u"universal_link", default=u"Universal link" ), "description": _( u"description_universal_link", default=u"Universal link to the content in user's preferred language" # noqa ), "action": "%s/@@multilingual-universal-link/%s" % ( site_url, folder_translation_group), "selected": False, "icon": None, "extra": { "id": "_universal_folder_link", "separator": None, "class": "" }, "submenu": None, }) if results_folder: # Folder translation separator results.append({ 'title': _( u'title_translate_current_folder', default=u'Folder translation' ), 'description': '', 'action': None, 'selected': False, 'icon': None, 'extra': {'id': 'translateFolderHeader', 'separator': 'actionSeparator', 'class': 'plone-toolbar-submenu-header'}, 'submenu': None, }) results.extend(results_folder) lang_name = lang_names.get(content_language, content_language) # Content language if content_untranslated and False: # disabled in favor of cut & paste results_content.append({ "title": _( u"title_set_language", default=u"Change content language" ), "description": _( u"description_set_language", default=u"Move the translation under another language folder" # noqa ), "action": content_url + "/update_language", "selected": False, "icon": None, "extra": { "id": "_set_language", "separator": None, "class": "" }, "submenu": None, }) if content_translatable: # Content translation view results_content.append({ "title": _( u'edit_translation', default=u"Edit ${lang_name}", mapping={"lang_name": lang_name} ), "description": _( u"description_babeledit_menu", default=u"Edit {lang_name} with the two-column translation view", # noqa mapping={"lang_name": lang_name} ), "action": content_url + "/" + translation_view, "selected": False, "icon": None, "extra": { "id": "_edit_babel_edit", "separator": None, "class": "", }, "submenu": None, }) if content_translatable: for idx, lang in enumerate(content_untranslated): lang_name = lang_names.get(lang.value, lang.title) lang_id = lang.value icon = show_flags and language_tool.getFlagForLanguageCode(lang_id) or None # noqa results_content.append({ "title": _( u'create_translation', default=u"Create ${lang_name}", mapping={"lang_name": lang_name} ), "description": _( u"description_translate_into", default=u"Translate into ${lang_name}", mapping={"lang_name": lang_name} ), "action": "%s/@@create_translation?language=%s" % ( content_url, lang_id), "selected": False, "icon": icon, "width": "14", "height": "11", "extra": {"id": "translate_into_%s" % lang_id, "separator": None, "class": "contentmenuflags"}, "submenu": None, }) urls = translated_urls(content) for lang in content_translated: if lang.value not in urls.by_token: # omit if translation is not permitted to access. continue lang_name = lang_names.get(lang.value, lang.title) lang_id = lang.value icon = show_flags and language_tool.getFlagForLanguageCode(lang_id) or None # noqa results_content.append({ "title": _( u'edit_translation', default=u"Edit ${lang_name}", mapping={"lang_name": lang_name} ), "description": _( u"description_babeledit_menu", default=u"Edit {lang_name} with the two-column translation view", # noqa mapping={"lang_name": lang_name} ), "action": (urls.getTerm(lang_id).title + "/" + translation_view), "selected": False, "icon": icon, "width": "14", "height": "11", "extra": {"id": "babel_edit_%s" % lang_id, "separator": None, "class": "contentmenuflags"}, "submenu": None, }) # Manage content translations results_content.append({ "title": _(u"title_modify_translations", default=u"Manage translations"), "description": _( u"description_modify_translations", default=u"Add or delete translations" ), "action": content_url + "/modify_translations", "selected": False, "icon": None, "extra": { "id": "_modify_translations", "separator": None, "class": "" }, "submenu": None, }) # Universal link if content_translation_group: results_content.append({ "title": _( u"universal_link", default=u"Universal link" ), "description": _( u"description_universal_link", default=u"Universal link to the content in user's preferred language" # noqa ), "action": "%s/@@multilingual-universal-link/%s" % ( site_url, content_translation_group), "selected": False, "icon": None, "extra": { "id": "_universal_link", "separator": None, "class": "" }, "submenu": None, }) if results_folder and results_content: # Item translations separator results.append({ 'title': _( u'title_translate_current_item', default=u'Item translation' ), 'description': '', 'action': None, 'selected': False, 'icon': None, 'extra': {'id': 'translateItemHeader', 'separator': 'actionSeparator', 'class': ''}, 'submenu': None, }) results.extend(results_content) # Language independent assets folder if assets_folder_url: results.append({ "title": _( u"shared_folder", default=u"Open ${title} folder", mapping={"title": assets_folder_title} ), "description": _( u"description_shared_folder", default=u"Open the language independent assets folder" ), "action": assets_folder_url, "selected": False, "icon": None, "extra": { "id": "_shared_folder", "separator": results and 'actionSeparator' or None, "class": ""}, "submenu": None, }) # User preferred language root folder if not folder_translatable and not content_translatable: results.append({ "title": _( u"language_folder", default=u"Return to language folder" ), "description": _( u"description_language_folder", default=u"Go to the user's browser preferred language " u"related folder" ), "action": site_url + '/' + language_tool.getPreferredLanguage(), # noqa "selected": False, "icon": None, "extra": { "id": "_language_folder", "separator": ( (results and not assets_folder_url) and 'actionSeparator' or None ), "class": "" }, "submenu": None, }) return results
def setUpLanguage(self, code, name): """Create the language folders on top of the site """ doneSomething = False if code == 'id': folderId = 'id-id' else: folderId = str(code) folder = getattr(self.context, folderId, None) wftool = getToolByName(self.context, 'portal_workflow') assets_folder_id = translate(_('assets_folder_id', default='assets'), domain='plone', target_language=folderId) assets_folder_title = translate(_('assets_folder_title', default=u'Assets'), domain='plone', target_language=folderId) if folder is None: _createObjectByType(self.folder_type, self.context, folderId) _createObjectByType(self.folder_type_language_independent, self.context[folderId], assets_folder_id) folder = self.context[folderId] ILanguage(folder).set_language(code) folder.setTitle(name) ILanguage(folder[assets_folder_id]).set_language(code) folder[assets_folder_id].setTitle(assets_folder_title) # This assumes a direct 'publish' transition from the initial state # We are going to check if its private and has publish action for # the out of the box case otherwise don't do anything state = wftool.getInfoFor(folder, 'review_state', None) available_transitions = [ t['id'] for t in wftool.getTransitionsFor(folder) ] if state != 'published' and 'publish' in available_transitions: wftool.doActionFor(folder, 'publish') state = wftool.getInfoFor(folder[assets_folder_id], 'review_state', None) available_transitions = [ t['id'] for t in wftool.getTransitionsFor(folder[assets_folder_id]) ] # noqa if state != 'published' and 'publish' in available_transitions: wftool.doActionFor(folder[assets_folder_id], 'publish') # Exclude folder from navigation (if applicable) adapter = IExcludeFromNavigation(folder, None) if adapter is not None: adapter.exclude_from_nav = True adapter = IExcludeFromNavigation(folder[assets_folder_id], None) if adapter is not None: adapter.exclude_from_nav = True # We've modified the object; reindex. notify(modified(folder)) notify(modified(folder[assets_folder_id])) doneSomething = True logger.info(u"Added '%s' folder: %s" % (code, folderId)) self.folders[code] = folder if not INavigationRoot.providedBy(folder): alsoProvides(folder, INavigationRoot) doneSomething = True logger.info(u"INavigationRoot setup on folder '%s'" % code) return doneSomething
def getMenuItems(self, context, request): """Return menu item entries in a TAL-friendly form.""" menu = [] url = context.absolute_url() lt = getToolByName(context, "portal_languages") portal_state = getMultiAdapter((context, request), name=u'plone_portal_state') portal_url = portal_state.portal_url() showflags = lt.showFlags() context_id = ITranslationManager(context).tg registry = getUtility(IRegistry) settings = registry.forInterface(IMultiLanguageExtraOptionsSchema) edit_view = 'babel_edit' if settings.redirect_babel_view else 'edit' # In case is neutral language show set language menu only if LANGUAGE_INDEPENDENT != ILanguage(context).get_language() and not INavigationRoot.providedBy(context): menu.append({ "title": _(u"title_babel_edit", default=u"Edit with babel view"), "description": _(u"description_babel_edit", default=u"Edit with the babel_edit"), "action": url + "/" + edit_view, "selected": False, "icon": None, "extra": {"id": "_edit_babel_edit", "separator": None, "class": ""}, "submenu": None, }) contexts = [context,] prt = aq_parent(context) if isDefaultPage(prt, context): contexts.append(prt) for idx,context in enumerate(contexts): url = context.absolute_url() langs = untranslated_languages(context) for lang in langs: lang_name = lang.title lang_id = lang.value icon = showflags and lt.getFlagForLanguageCode(lang_id) or None item = { "description": _(u"description_translate_into", default=u"Translate into ${lang_name}", mapping={"lang_name": lang_name}), "action": url + "/@@create_translation?language=%s" % lang_id, "selected": False, "icon": icon, "width": "14", "height": "11", "extra": {"id": "translate_into_%s" % lang_id, "separator": None, "class": "contentmenuflags"}, "submenu": None, } item['title'] = idx and _(u'create_translation_folder', default=u"Create ${lang_name} folder", mapping={"lang_name": lang_name}) \ or _(u'create_translation', default=u"Create ${lang_name}", mapping={"lang_name": lang_name}) menu.append(item) langs = translated_languages(context) urls = translated_urls(context) for lang in langs: if lang not in urls: # omit if translation is not permitted to access. continue lang_name = lang.title lang_id = lang.value icon = showflags and lt.getFlagForLanguageCode(lang_id) or None item = { "description": _(u"description_babeledit_menu", default=u"Babel edit ${lang_name}", mapping={"lang_name": lang_name}), "action": urls.getTerm(lang_id).title + "/" + edit_view, "selected": False, "icon": icon, "width": "14", "height": "11", "extra": {"id": "babel_edit_%s" % lang_id, "separator": None, "class": "contentmenuflags"}, "submenu": None, } item['title'] = idx and _(u'edit_translation_folder', default=u"Edit ${lang_name} folder", mapping={"lang_name": lang_name}) \ or _(u'edit_translation', default=u"Edit ${lang_name}", mapping={"lang_name": lang_name}) menu.append(item) item = { "description": _(u"description_add_translations", default=u"Add existing content as translation"), "action": url + "/add_translations", "selected": False, "icon": None, "extra": {"id": "_add_translations", "separator": langs and "actionSeparator" or None, "class": ""}, "submenu": None, } item['title'] = idx and _(u"title_add_translations_folder", default=u"Add translations for folder...") \ or _(u"title_add_translations", default=u"Add translations...") menu.append(item) item = { "title": _(u"title_remove_translations", default=u"Remove translations..."), "description": _( u"description_remove_translations", default=u"Delete translations or remove the relations"), "action": url + "/remove_translations", "selected": False, "icon": None, "extra": {"id": "_remove_translations", "separator": langs and "actionSeparator" or None, "class": ""}, "submenu": None, } menu.append(item) elif LANGUAGE_INDEPENDENT == ILanguage(context).get_language(): menu.append({ "title": _(u"language_folder", default=u"Return to language folder"), "description": _( u"description_language_folder", default=u"Go to the user's browser preferred language related folder"), "action": portal_url + '/' + lt.getPreferredLanguage(), "selected": False, "icon": None, "extra": {"id": "_shared_folder", "separator": None, "class": ""}, "submenu": None, }) if LANGUAGE_INDEPENDENT != ILanguage(context).get_language(): menu.append({ "title": _(u"universal_link", default=u"Universal Link"), "description": _( u"description_universal_link", default=u"Universal Language content link"), "action": portal_url + "/@@multilingual-universal-link/" + context_id, "selected": False, "icon": None, "extra": {"id": "_universal_link", "separator": None, "class": ""}, "submenu": None, }) menu.append({ "title": _(u"shared_folder", default=u"Go to shared folder"), "description": _( u"description_shared_folder", default=u"Show the language shared (neutral language) folder"), "action": portal_url + '/' + SHARED_NAME, "selected": False, "icon": None, "extra": {"id": "_shared_folder", "separator": None, "class": ""}, "submenu": None, }) menu.append({ "title": _(u"title_set_language", default=u"Set content language"), "description": _(u"description_set_language", default=u"Set or change the current content language"), "action": url + "/update_language", "selected": False, "icon": None, "extra": {"id": "_set_language", "separator": None, "class": ""}, "submenu": None, }) return menu
def setUpLanguage(self, code, name): """Create the language folders on top of the site """ doneSomething = False if code == 'id': folderId = 'id-id' else: folderId = str(code) folder = getattr(self.context, folderId, None) wftool = getToolByName(self.context, 'portal_workflow') assets_folder_id = translate(_('assets_folder_id', default='assets'), domain='plone', target_language=folderId) assets_folder_title = translate(_('assets_folder_title', default=u'Assets'), domain='plone', target_language=folderId) if folder is None: _createObjectByType(self.folder_type, self.context, folderId) _createObjectByType(self.folder_type_language_independent, self.context[folderId], assets_folder_id) folder = self.context[folderId] ILanguage(folder).set_language(code) folder.setTitle(name) ILanguage(folder[assets_folder_id]).set_language(code) folder[assets_folder_id].setTitle(assets_folder_title) # This assumes a direct 'publish' transition from the initial state # We are going to check if its private and has publish action for # the out of the box case otherwise don't do anything state = wftool.getInfoFor(folder, 'review_state', None) available_transitions = [t['id'] for t in wftool.getTransitionsFor(folder)] if state != 'published' and 'publish' in available_transitions: wftool.doActionFor(folder, 'publish') state = wftool.getInfoFor(folder[assets_folder_id], 'review_state', None) available_transitions = [t['id'] for t in wftool.getTransitionsFor(folder[assets_folder_id])] # noqa if state != 'published' and 'publish' in available_transitions: wftool.doActionFor(folder[assets_folder_id], 'publish') # Exclude folder from navigation (if applicable) adapter = IExcludeFromNavigation(folder, None) if adapter is not None: adapter.exclude_from_nav = True adapter = IExcludeFromNavigation(folder[assets_folder_id], None) if adapter is not None: adapter.exclude_from_nav = True # We've modified the object; reindex. notify(modified(folder)) notify(modified(folder[assets_folder_id])) doneSomething = True logger.info(u"Added '%s' folder: %s" % (code, folderId)) self.folders[code] = folder if not INavigationRoot.providedBy(folder): alsoProvides(folder, INavigationRoot) doneSomething = True logger.info(u"INavigationRoot setup on folder '%s'" % code) return doneSomething
class IMultiLanguageExtraOptionsSchema(ILanguageSchema): """ Interface for language extra options - control panel fieldset """ model.fieldset( 'multilingual', label=_(u'Multilingual', default=u'Multilingual'), fields=[ 'filter_content', 'redirect_babel_view', 'bypass_languageindependent_field_permission_check', 'buttons_babel_view_up_to_nr_translations', 'google_translation_key', 'selector_lookup_translations_policy' ], ) filter_content = schema.Bool( title=_(u"heading_filter_content", default=u"Filter content by language."), description=_( u"description_filter_content", default=u"Filter using language the content on folder_contents"), default=True, required=False, ) redirect_babel_view = schema.Bool( title=_(u"heading_redirect_babel_view", default=u"Redirect on creation to babel view."), description=_( u"description_redirect_babel_view", default=(u"After creating a new translation redirecto to babel " u"view")), default=True, required=False, ) bypass_languageindependent_field_permission_check = schema.Bool( title=_(u"heading_bypass_languageindependent_field_permission_check", default=u"Bypass language independent field permission check"), description=_( u"description_bypass_languageindependent_field_permission_check", default=u"When updating an object with language independent the " u"field will be synced to all target languages. That can " u"produce Unauthorized error messages because if the " u"editor of the canonical object is not allowed to update " u"the target language objects. Enabling this bypasses " u"this permission check. This could also be dangerous, so " u"think about possible security issues before enabling " u"this."), default=False, required=False, ) buttons_babel_view_up_to_nr_translations = schema.Int( title=_(u"heading_buttons_babel_view_up_to_nr_translations", default=u"Use buttons in the bable view for up to how many " u"translations?"), description=_( u"description_buttons_babel_view_up_to_nr_translations", default=u"When there are many translations for an item, the " u"number of displayed buttons for them might get too " u"large to fit inside the template. Choose here from " u"which number onwards a drop-down menu will be displayed " u"instead of buttons. Zero means that buttons will always " u"be used."), default=7, required=False, ) google_translation_key = schema.TextLine( title=_(u"heading_google_translation_key", default=u"Google Translation API Key"), description=_( u"description_google_translation_key", default=u"Is a paying API in order to use google translation " u"service"), required=False, ) selector_lookup_translations_policy = schema.Choice( title=_(u"heading_selector_lookup_translations_policy", default=u"The policy used to determine how the lookup for " u"available translations will be made by the language " u"selector."), description=_(u"description_selector_lookup_translations_policy", default=u"The default language used for the content " u"and the UI of this site."), required=True, vocabulary=selector_policies)
class ITG(Interface): """Abstract representation of a Translation Group (TG). Adapt an object to this interface to obtain its UUID. Adaptation will fail if the object does not have a TG (yet). """ class IPloneAppMultilingualInstalled(Interface): """ layer """ selector_policies = SimpleVocabulary( [SimpleTerm(value=u'closest', title=_(u'Search for closest translation in parent\'s content ' u'chain.')), SimpleTerm(value=u'dialog', title=_(u'Show user dialog with information about the ' u'available translations.'))] ) class IMultiLanguageExtraOptionsSchema(ILanguageSchema): """ Interface for language extra options - control panel fieldset """ model.fieldset( 'multilingual', label=_(u'Multilingual', default=u'Multilingual'), fields=[ 'filter_content',
class ITG(Interface): """Abstract representation of a Translation Group (TG). Adapt an object to this interface to obtain its UUID. Adaptation will fail if the object does not have a TG (yet). """ class IPloneAppMultilingualInstalled(Interface): """ layer """ selector_policies = SimpleVocabulary([ SimpleTerm(value=u'closest', title=_(u'Search for closest translation in parent\'s content ' u'chain.')), SimpleTerm(value=u'dialog', title=_(u'Show user dialog with information about the ' u'available translations.')) ]) class IMultiLanguageExtraOptionsSchema(ILanguageSchema): """ Interface for language extra options - control panel fieldset """ model.fieldset( 'multilingual', label=_(u'Multilingual', default=u'Multilingual'), fields=[ 'filter_content', 'redirect_babel_view',
def getMenuItems(self, context, request): """Return menu item entries in a TAL-friendly form. """ try: lang_names = request.locale.displayNames.languages except AttributeError: lang_names = {} menu = [] url = context.absolute_url() lt = getToolByName(context, "portal_languages") site_url = getSite().absolute_url() showflags = lt.showFlags context_id = ITranslationManager(context).tg registry = getUtility(IRegistry) settings = registry.forInterface(IMultiLanguageExtraOptionsSchema, prefix="plone") edit_view = 'babel_edit' if settings.redirect_babel_view else 'edit' # In case is neutral language show set language menu only is_neutral_content = ( ILanguage(context).get_language() == LANGUAGE_INDEPENDENT or is_language_independent(context) ) shared_folder_url = site_url + '/folder_contents' pc = getToolByName(getSite(), 'portal_catalog') results = pc.unrestrictedSearchResults( portal_type='LIF', Language=ILanguage(context).get_language()) for brain in results: shared_folder_url = brain.getURL() + '/folder_contents' if not is_neutral_content and not INavigationRoot.providedBy(context): menu.append({ "title": _( u"title_babel_edit", default=u"Edit with babel view" ), "description": _( u"description_babel_edit", default=u"Edit with the babel_edit" ), "action": url + "/" + edit_view, "selected": False, "icon": None, "extra": { "id": "_edit_babel_edit", "separator": None, "class": "", }, "submenu": None, }) if ITranslatable.providedBy(context): contexts = [context, ] else: contexts = [] prt = aq_parent(context) if isDefaultPage(prt, context) and ITranslatable.providedBy(prt): contexts.append(prt) for idx, context in enumerate(contexts): url = context.absolute_url() ulangs = untranslated_languages(context) for lang in ulangs: lang_name = lang_names.get(lang.value, lang.title) lang_id = lang.value icon = showflags and lt.getFlagForLanguageCode(lang_id)\ or None item = { "description": _( u"description_translate_into", default=u"Translate into ${lang_name}", mapping={"lang_name": lang_name} ), "action": "%s/@@create_translation?language=%s" % ( url, lang_id), "selected": False, "icon": icon, "width": "14", "height": "11", "extra": {"id": "translate_into_%s" % lang_id, "separator": None, "class": "contentmenuflags"}, "submenu": None, } item['title'] = idx and _( u'create_translation_folder', default=u"Create ${lang_name} folder", mapping={"lang_name": lang_name} ) or _( u'create_translation', default=u"Create ${lang_name}", mapping={"lang_name": lang_name} ) menu.append(item) langs = translated_languages(context) urls = translated_urls(context) for lang in langs: if lang.value not in urls.by_token: # omit if translation is not permitted to access. continue lang_name = lang_names.get(lang.value, lang.title) lang_id = lang.value icon = showflags and lt.getFlagForLanguageCode(lang_id)\ or None item = { "description": _( u"description_babeledit_menu", default=u"Babel edit ${lang_name}", mapping={"lang_name": lang_name} ), "action": (urls.getTerm(lang_id).title + "/" + edit_view), "selected": False, "icon": icon, "width": "14", "height": "11", "extra": {"id": "babel_edit_%s" % lang_id, "separator": None, "class": "contentmenuflags"}, "submenu": None, } item['title'] = idx and _( u'edit_translation_folder', default=u"Edit ${lang_name} folder", mapping={"lang_name": lang_name} ) or _( u'edit_translation', default=u"Edit ${lang_name}", mapping={"lang_name": lang_name} ) menu.append(item) item = { "description": _( u"description_add_translations", default=u"Add existing content as translation"), "action": url + "/add_translations", "selected": False, "icon": None, "extra": { "id": "_add_translations", "separator": langs and "actionSeparator" or None, "class": "" }, "submenu": None, } item['title'] = idx and _( u"title_add_translations_folder", default=u"Add translations for folder..." ) or _( u"title_add_translations", default=u"Add translations..." ) menu.append(item) item = { "title": _( u"title_remove_translations", default=u"Remove translations..." ), "description": _( u"description_remove_translations", default=u"Delete translations or remove the relations" ), "action": url + "/remove_translations", "selected": False, "icon": None, "extra": { "id": "_remove_translations", "separator": langs and "actionSeparator" or None, "class": "" }, "submenu": None, } menu.append(item) elif is_neutral_content: menu.append({ "title": _( u"language_folder", default=u"Return to language folder" ), "description": _( u"description_language_folder", default=u"Go to the user's browser preferred language " u"related folder" ), "action": site_url + '/' + lt.getPreferredLanguage(), "selected": False, "icon": None, "extra": { "id": "_shared_folder", "separator": None, "class": "" }, "submenu": None, }) if not is_neutral_content: menu.append({ "title": _( u"universal_link", default=u"Universal Link" ), "description": _( u"description_universal_link", default=u"Universal Language content link" ), "action": "%s/@@multilingual-universal-link/%s" % ( site_url, context_id), "selected": False, "icon": None, "extra": { "id": "_universal_link", "separator": None, "class": "" }, "submenu": None, }) menu.append({ "title": _( u"shared_folder", default=u"Go to shared folder" ), "description": _( u"description_shared_folder", default=u"Show the language shared (neutral language) " u"folder" ), "action": shared_folder_url, "selected": False, "icon": None, "extra": { "id": "_shared_folder", "separator": None, "class": ""}, "submenu": None, }) menu.append({ "title": _( u"title_set_language", default=u"Set content language" ), "description": _( u"description_set_language", default=u"Set or change the current content language" ), "action": url + "/update_language", "selected": False, "icon": None, "extra": { "id": "_set_language", "separator": None, "class": "" }, "submenu": None, }) return menu
def getMenuItems(self, context, request): """Return menu item entries in a TAL-friendly form.""" menu = [] url = context.absolute_url() lt = getToolByName(context, "portal_languages") showflags = lt.showFlags() langs = untranslated_languages(context) for lang in langs: lang_name = lang.title lang_id = lang.value icon = showflags and lt.getFlagForLanguageCode(lang_id) or None item = { "title": lang_name, "description": _(u"description_translate_into", default=u"Translate into ${lang_name}", mapping={"lang_name": lang_name}), "action": url + "/@@create_translation?form.widgets.language"\ "=%s&form.buttons.create=1" % lang_id, "selected": False, "icon": icon, "extra": {"id": "translate_into_%s" % lang_id, "separator": None, "class": ""}, "submenu": None, } menu.append(item) menu.append({ "title": _(u"title_add_translations", default=u"Add translations..."), "description": _(u"description_add_translations", default=u""), "action": url + "/add_translations", "selected": False, "icon": None, "extra": {"id": "_add_translations", "separator": langs and "actionSeparator" or None, "class": ""}, "submenu": None, }) menu.append({ "title": _(u"title_remove_translations", default=u"Remove translations..."), "description": _(u"description_remove_translations", default=u"Delete translations or remove the relations"), "action": url + "/remove_translations", "selected": False, "icon": None, "extra": {"id": "_remove_translations", "separator": langs and "actionSeparator" or None, "class": ""}, "submenu": None, }) site = getUtility(ISiteRoot) mt = getToolByName(context, "portal_membership") if mt.checkPermission(ManagePortal, site): portal_state = getMultiAdapter((context, request),\ name="plone_portal_state") menu.append({ "title": _(u"title_language_settings", default=u"Language settings..."), "description": _(u"description_language_settings", default=u""), "action": portal_state.portal_url() + \ "/@@language-controlpanel", "selected": False, "icon": None, "extra": {"id": "_language_settings", "separator": None, "class": ""}, "submenu": None, }) return menu
def getMenuItems(self, context, request): """Return menu item entries in a TAL-friendly form.""" menu = [] url = context.absolute_url() lt = getToolByName(context, "portal_languages") portal_state = getMultiAdapter((context, request), name=u'plone_portal_state') portal_url = portal_state.portal_url() showflags = lt.showFlags() context_id = IUUID(context) # In case is neutral language show set language menu only if LANGUAGE_INDEPENDENT != ILanguage(context).get_language() and not INavigationRoot.providedBy(context): menu.append({ "title": _(u"title_babel_edit", default=u"Edit with babel view"), "description": _(u"description_babel_edit", default=u"Edit with the babel_edit"), "action": url + "/babel_edit", "selected": False, "icon": None, "extra": {"id": "_edit_babel_edit", "separator": None, "class": ""}, "submenu": None, }) langs = untranslated_languages(context) for lang in langs: lang_name = lang.title lang_id = lang.value icon = showflags and lt.getFlagForLanguageCode(lang_id) or None item = { "title": _(u"Create") + " " + lang_name, "description": _(u"description_translate_into", default=u"Translate into ${lang_name}", mapping={"lang_name": lang_name}), "action": url + "/@@create_translation?form.widgets.language"\ "=%s&form.buttons.create=1" % lang_id, "selected": False, "icon": icon, "extra": {"id": "translate_into_%s" % lang_id, "separator": None, "class": ""}, "submenu": None, } menu.append(item) langs = translated_languages(context) urls = translated_urls(context) for lang in langs: lang_name = lang.title lang_id = lang.value icon = showflags and lt.getFlagForLanguageCode(lang_id) or None item = { "title": _(u"Edit") + " " + lang_name, "description": _(u"description_babeledit_menu", default=u"Babel edit ${lang_name}", mapping={"lang_name": lang_name}), "action": urls.getTerm(lang_id).title + "/babel_edit", "selected": False, "icon": icon, "extra": {"id": "babel_edit_%s" % lang_id, "separator": None, "class": ""}, "submenu": None, } menu.append(item) menu.append({ "title": _(u"title_add_translations", default=u"Add translations..."), "description": _(u"description_add_translations", default=u"Add existing content as translation"), "action": url + "/add_translations", "selected": False, "icon": None, "extra": {"id": "_add_translations", "separator": langs and "actionSeparator" or None, "class": ""}, "submenu": None, }) menu.append({ "title": _(u"title_remove_translations", default=u"Remove translations..."), "description": _( u"description_remove_translations", default=u"Delete translations or remove the relations"), "action": url + "/remove_translations", "selected": False, "icon": None, "extra": {"id": "_remove_translations", "separator": langs and "actionSeparator" or None, "class": ""}, "submenu": None, }) elif LANGUAGE_INDEPENDENT == ILanguage(context).get_language(): menu.append({ "title": _(u"language_folder", default=u"Return to language folder"), "description": _( u"description_shared_folder", default=u"Go to the user's browser preferred language related folder"), "action": portal_url + '/' + lt.getPreferredLanguage(), "selected": False, "icon": None, "extra": {"id": "_shared_folder", "separator": None, "class": ""}, "submenu": None, }) if LANGUAGE_INDEPENDENT != ILanguage(context).get_language(): menu.append({ "title": _(u"universal_link", default=u"Universal Link"), "description": _( u"description_universal_link", default=u"Universal Language content link"), "action": portal_url + "/multilingual-universal-link?uid=" + context_id, "selected": False, "icon": None, "extra": {"id": "_universal_link", "separator": None, "class": ""}, "submenu": None, }) menu.append({ "title": _(u"shared_folder", default=u"Go to shared folder"), "description": _( u"description_shared_folder", default=u"Show the language shared (neutral language) folder"), "action": portal_url + '/' + SHARED_NAME, "selected": False, "icon": None, "extra": {"id": "_shared_folder", "separator": None, "class": ""}, "submenu": None, }) menu.append({ "title": _(u"title_set_language", default=u"Set content language"), "description": _(u"description_add_translations", default=u"Set or change the current content language"), "action": url + "/update_language", "selected": False, "icon": None, "extra": {"id": "_set_language", "separator": None, "class": ""}, "submenu": None, }) return menu
def getMenuItems(self, context, request): """Return menu item entries in a TAL-friendly form.""" menu = [] url = context.absolute_url() lt = getToolByName(context, "portal_languages") showflags = lt.showFlags() langs = untranslated_languages(context) for lang in langs: lang_name = lang.title lang_id = lang.value icon = showflags and lt.getFlagForLanguageCode(lang_id) or None item = { "title": lang_name, "description": _(u"description_translate_into", default=u"Translate into ${lang_name}", mapping={"lang_name": lang_name}), "action": url + "/@@create_translation?form.widgets.language"\ "=%s&form.buttons.create=1" % lang_id, "selected": False, "icon": icon, "extra": {"id": "translate_into_%s" % lang_id, "separator": None, "class": ""}, "submenu": None, } menu.append(item) langs = translated_languages(context) urls = translated_urls(context) for lang in langs: lang_name = lang.title lang_id = lang.value icon = showflags and lt.getFlagForLanguageCode(lang_id) or None item = { "title": lang_name, "description": _(u"description_babeledit_menu", default=u"Babel edit ${lang_name}", mapping={"lang_name": lang_name}), "action": urls.getTerm(lang_id).title + "/babel_edit", "selected": False, "icon": icon, "extra": {"id": "babel_edit_%s" % lang_id, "separator": None, "class": ""}, "submenu": None, } menu.append(item) menu.append({ "title": _(u"title_add_translations", default=u"Add translations..."), "description": _(u"description_add_translations", default=u""), "action": url + "/add_translations", "selected": False, "icon": None, "extra": {"id": "_add_translations", "separator": langs and "actionSeparator" or None, "class": ""}, "submenu": None, }) menu.append({ "title": _(u"title_remove_translations", default=u"Remove translations..."), "description": _( u"description_remove_translations", default=u"Delete translations or remove the relations"), "action": url + "/remove_translations", "selected": False, "icon": None, "extra": {"id": "_remove_translations", "separator": langs and "actionSeparator" or None, "class": ""}, "submenu": None, }) site = getUtility(ISiteRoot) mt = getToolByName(context, "portal_membership") if mt.checkPermission(ManagePortal, site): portal_state = getMultiAdapter((context, request),\ name="plone_portal_state") menu.append({ "title": _(u"title_language_settings", default=u"Language settings..."), "description": _(u"description_language_settings", default=u""), "action": portal_state.portal_url() + \ "/@@language-controlpanel", "selected": False, "icon": None, "extra": {"id": "_language_settings", "separator": None, "class": ""}, "submenu": None, }) return menu