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_translate" order = 5 extra = {"id": "plone-contentmenu-translate"} @property def action(self): return self.context.absolute_url() + "/manage_translations_form" def available(self): if self.disabled(): return False # pragma: no cover elif not ILinguaPloneProductLayer in registered_layers(): return False else: context = self.context mt = getToolByName(context, "portal_membership") can_translate = mt.checkPermission(AddPortalContent, context.getParentNode()) can_set_language = mt.checkPermission(ModifyPortalContent, context) can_delete = mt.checkPermission(DeleteObjects, context.getParentNode()) return can_translate or can_set_language def disabled(self): return False def selected(self): return False
def getMenuItems(self, context, request): """Return menu item entries in a TAL-friendly form.""" menu = [] url = context.absolute_url() lt = getToolByName(context, "portal_languages") mt = getToolByName(context, "portal_membership") can_translate = mt.checkPermission(AddPortalContent, context.getParentNode()) can_set_language = mt.checkPermission(ModifyPortalContent, context) can_delete = mt.checkPermission(DeleteObjects, context.getParentNode()) if not (can_translate or can_set_language or can_delete): return [] langs = self.getUntranslatedLanguages(context) if can_translate: showflags = lt.showFlags() langs = self.getUntranslatedLanguages(context) for (lang_id, lang_name) in langs: icon=showflags and lt.getFlagForLanguageCode(lang_id) or None item={ "title": lang_name, "description": _(u"title_translate_into", default=u"Translate into ${lang_name}", mapping={"lang_name": lang_name}), "action": url+"/@@translate?newlanguage=%s" % lang_id, "selected": False, "icon": icon, "extra": {"id": "translate_into_%s" % lang_id, "separator": None, "class": ""}, "submenu": None, "width": 14, "height": 11, } menu.append(item) if can_set_language or can_delete: menu.append({ "title": _(u"label_manage_translations", default=u"Manage translations..."), "description": u"", "action": url+"/manage_translations_form", "selected": False, "icon": None, "extra": {"id": "_manage_translations", "separator": langs and "actionSeparator" or None, "class": ""}, "submenu": None, }) return menu
def __call__(self): status = IStatusMessage(self.request) self._setCanonicalLanguage(self.context) newlang = self.request["newlanguage"] lt = getToolByName(self.context, "portal_languages") lt.setLanguageCookie(newlang) if self.context.hasTranslation(newlang): status.addStatusMessage( _(u"message_translation_exists", default=u"Translation already exists"), type="info" ) else: self.context.addTranslation(newlang) status.addStatusMessage(_(u"message_translation_created", default=u"Translation created."), type="info") trans = self.context.getTranslation(newlang) return self.request.response.redirect(self.nextUrl(trans))
def __call__(self): status = IStatusMessage(self.request) self._setCanonicalLanguage(self.context) newlang = self.request["newlanguage"] lt = getToolByName(self.context, "portal_languages") lt.setLanguageCookie(newlang) if self.context.hasTranslation(newlang): status.addStatusMessage(_(u"message_translation_exists", default=u"Translation already exists"), type="info") else: self.context.addTranslation(newlang) status.addStatusMessage(_(u"message_translation_created", default=u"Translation created."), type="info") trans = self.context.getTranslation(newlang) return self.request.response.redirect(self.nextUrl(trans))
class IMultiLanguageSelectionSchema(Interface): default_language = Choice( title=_(u"heading_site_language", default=u"Default site language"), description=_(u"description_site_language", default=u"The default language used for the content " u"and the UI of this site."), required=True, vocabulary="LinguaPlone.vocabularies.AllContentLanguageVocabulary") available_languages = Tuple( title=_(u"heading_available_languages", default=u"Available languages"), description=_(u"description_available_languages", default=u"The languages in which the site should be " u"translatable."), required=True, missing_value=set(), value_type=Choice( vocabulary="LinguaPlone.vocabularies.AllContentLanguageVocabulary"))
def __call__(self): status=IStatusMessage(self.request) self._setCanonicalLanguage(self.context) newlang=self.request["newlanguage"] if self.context.hasTranslation(newlang): state=getMultiAdapter((self.context, self.request), name="plone_context_state") status.addStatusMessage(_(u"message_translation_exists", default=u"Translation already exists"), type="error") return self.request.response.redirect(state.view_url()) lt=getToolByName(self.context, "portal_languages") lt.setLanguageCookie(newlang) #Customization for eduCommons to ensure parent Division --> Course --> SubObject's parent folder translated first if self.context.aq_inner.aq_parent.Type() == 'Plone Site': self.context.addTranslation(newlang) trans=self.context.getTranslation(newlang) status.addStatusMessage(_(u"message_translation_created", default=u"Translated created."), type="info") return self.request.response.redirect(self.nextUrl(trans)) else: if self.context.aq_inner.aq_parent.aq_explicit.hasTranslation(newlang): self.context.addTranslation(newlang) trans=self.context.getTranslation(newlang) status.addStatusMessage(_(u"message_translation_created", default=u"Translated created."), type="info") return self.request.response.redirect(self.nextUrl(trans)) else: url = self.context.absolute_url() not_available = '%s/not_available_lang/view?set_language=%s&parentNotTranslated=True' % (url, newlang) return self.request.response.redirect(not_available)
def __call__(self): status=IStatusMessage(self.request) self._setCanonicalLanguage(self.context) newlang=self.request["newlanguage"] if self.context.hasTranslation(newlang): state=getMultiAdapter((self.context, self.request), name="plone_context_state") status.addStatusMessage(_(u"message_translation_exists", default=u"Translation already exists"), type="error") return self.request.response.redirect(state.view_url()) lt=getToolByName(self.context, "portal_languages") lt.setLanguageCookie(newlang) self.context.addTranslation(newlang) trans=self.context.getTranslation(newlang) status.addStatusMessage(_(u"message_translation_created", default=u"Translated created."), type="info") return self.request.response.redirect(self.nextUrl(trans))
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() context_state=getMultiAdapter((context, request), name="plone_context_state") langs=self.getUntranslatedLanguages(context) parent=aq_parent(aq_inner(context)) if ITranslatable.providedBy(parent): parentlangs=parent.getTranslationLanguages() else: parentlangs=[l[0] for l in lt.listSupportedLanguages()] for (lang_id, lang_name) in langs: icon=showflags and lt.getFlagForLanguageCode(lang_id) or None item={ "title" : lang_name, "description" : _(u"title_translate_into", default=u"Translate into ${lang_name}", mapping={"lang_name" : lang_name}), "action" : url+"/@@translate?newlanguage=%s" % 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"label_manage_translations", default=u"Manage translations..."), "description" : _(u"title_manage_translations", default=u""), "action" : url+"/manage_translations_form", "selected" : False, "icon" : None, "extra" : { "id" : "_manage_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"label_language_settings", default=u"Language settings..."), "description" : _(u"title_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") mt = getToolByName(context, "portal_membership") can_translate = mt.checkPermission(AddPortalContent, context.getParentNode()) can_set_language = mt.checkPermission(ModifyPortalContent, context) can_delete = mt.checkPermission(DeleteObjects, context.getParentNode()) # added by JR to check translator group membership so that only members of appropriate group can translate language gt = getToolByName(context, 'portal_groups') groups = gt.getGroupsByUserId( mt.getAuthenticatedMember().getUserName() ) group_ids = [group.getId() for group in groups] if not (can_translate or can_set_language or can_delete): return [] langs = self.getUntranslatedLanguages(context) if can_translate: showflags = lt.showFlags() langs = self.getUntranslatedLanguages(context) for (lang_id, lang_name) in langs: icon=showflags and lt.getFlagForLanguageCode(lang_id) or None item={ "title": lang_name, "description": _(u"title_translate_into", default=u"Translate into ${lang_name}", mapping={"lang_name": lang_name}), "action": url+"/@@translate?newlanguage=%s" % lang_id, "selected": False, "icon": icon, "extra": {"id": "translate_into_%s" % lang_id, "separator": None, "class": ""}, "submenu": None, "width": 14, "height": 11, } translator_group = 'Translators-'+lang_id is_valid_translator_for_lang = translator_group in group_ids if is_valid_translator_for_lang: menu.append(item) translation_manager_group = 'Translation-Managers' is_translation_manager = translation_manager_group in group_ids if is_translation_manager: menu.append({ "title": _(u"label_manage_translations", default=u"Manage translations..."), "description": u"", "action": url+"/manage_translations_form", "selected": False, "icon": None, "extra": {"id": "_manage_translations", "separator": langs and "actionSeparator" or 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") mt = getToolByName(context, "portal_membership") can_translate = mt.checkPermission(AddPortalContent, context.getParentNode()) can_set_language = mt.checkPermission(ModifyPortalContent, context) can_delete = mt.checkPermission(DeleteObjects, context.getParentNode()) # added by JR to check translator group membership so that only members of appropriate group can translate language gt = getToolByName(context, 'portal_groups') groups = gt.getGroupsByUserId( mt.getAuthenticatedMember().getUserName()) group_ids = [group.getId() for group in groups] if not (can_translate or can_set_language or can_delete): return [] langs = self.getUntranslatedLanguages(context) if can_translate: showflags = lt.showFlags() langs = self.getUntranslatedLanguages(context) for (lang_id, lang_name) in langs: icon = showflags and lt.getFlagForLanguageCode(lang_id) or None item = { "title": lang_name, "description": _(u"title_translate_into", default=u"Translate into ${lang_name}", mapping={"lang_name": lang_name}), "action": url + "/@@translate?newlanguage=%s" % lang_id, "selected": False, "icon": icon, "extra": { "id": "translate_into_%s" % lang_id, "separator": None, "class": "" }, "submenu": None, "width": 14, "height": 11, } translator_group = 'Translators-' + lang_id is_valid_translator_for_lang = translator_group in group_ids if is_valid_translator_for_lang: menu.append(item) translation_manager_group = 'Translation-Managers' is_translation_manager = translation_manager_group in group_ids if is_translation_manager: menu.append({ "title": _(u"label_manage_translations", default=u"Manage translations..."), "description": u"", "action": url + "/manage_translations_form", "selected": False, "icon": None, "extra": { "id": "_manage_translations", "separator": langs and "actionSeparator" or None, "class": "" }, "submenu": None, }) return menu
def __call__(self): status=IStatusMessage(self.request) self._setCanonicalLanguage(self.context) newlang=self.request["newlanguage"] curlang=self.context.Language() #generate a flag to utilize machine translation in addTranslation checked = 0 if self.request.has_key('checked'): checked = int(self.request['checked']) machine_xlate = 0 if self.request.has_key('machine_xlate'): machine_xlate = int(self.request['machine_xlate']) if self.context.hasTranslation(newlang): state=getMultiAdapter((self.context, self.request), name="plone_context_state") status.addStatusMessage(_(u"message_translation_exists", default=u"Translation already exists"), type="error") return self.request.response.redirect(state.view_url()) lt=getToolByName(self.context, "portal_languages") lt.setLanguageCookie(newlang) #Send to intermediate page if translation is to Arabic if newlang == 'ar' and curlang == 'en' and checked == 0: url = self.context.absolute_url() xlate = '%s/machine_translate?newlanguage=%s' % (url, newlang) return self.request.response.redirect(xlate) elif newlang == 'en' and curlang == 'ar' and checked == 0: url = self.context.absolute_url() xlate = '%s/machine_translate?newlanguage=%s' % (url, newlang) return self.request.response.redirect(xlate) #Customization for eduCommons to ensure parent Division --> Course --> SubObject's parent folder translated first if self.context.aq_inner.aq_parent.Type() == 'Plone Site': #Machine Translate Title, Description, Categories, Body if machine_xlate == 1: title, description, subjects = self._xlateFields(self.context) if 'text' in self.context.Schema().keys(): text = self._xlateBody(self.context) self.context.addTranslation(newlang, title=title, description=description, text=text, subject=subjects) else: self.context.addTranslation(newlang) trans=self.context.getTranslation(newlang) status.addStatusMessage(_(u"message_translation_created", default=u"Translated created."), type="info") return self.request.response.redirect(self.nextUrl(trans)) else: if self.context.aq_inner.aq_parent.aq_explicit.hasTranslation(newlang): #Machine Translate Title, Description, Categories, Body if machine_xlate == 1: title, description, subjects = self._xlateFields(self.context) if 'text' in self.context.Schema().keys(): text = self._xlateBody(self.context) self.context.addTranslation(newlang, title=title, description=description, text=text, subject=subjects) else: self.context.addTranslation(newlang) trans=self.context.getTranslation(newlang) status.addStatusMessage(_(u"message_translation_created", default=u"Translated created."), type="info") return self.request.response.redirect(self.nextUrl(trans)) else: url = self.context.absolute_url() not_available = '%s/not_available_lang/view?set_language=%s&parentNotTranslated=True' % (url, newlang) return self.request.response.redirect(not_available)