# HG changeset patch # User Goffi # Date 1468777410 -7200 # Node ID d95a6d553becd4f99eebbb3b833a460a3dc55786 # Parent d2144d04065e368decbc4e5513125275c3eb59dd plugin lang detect: added a parameter to (de)activate the detection diff -r d2144d04065e -r d95a6d553bec src/plugins/plugin_exp_lang_detect.py --- a/src/plugins/plugin_exp_lang_detect.py Sun Jul 17 17:59:14 2016 +0200 +++ b/src/plugins/plugin_exp_lang_detect.py Sun Jul 17 19:43:30 2016 +0200 @@ -17,7 +17,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from sat.core.i18n import _ +from sat.core.i18n import _, D_ from sat.core.log import getLogger log = getLogger(__name__) from sat.core import exceptions @@ -41,12 +41,29 @@ "description": _("""Detect and set message language when unknown""") } +CATEGORY = D_(u"Misc") +NAME = u"lang_detect" +LABEL = D_(u"language detection") +PARAMS = """ + + + + + + + + """.format(category_name=CATEGORY, + name=NAME, + label=_(LABEL), + ) + class LangDetect(object): def __init__(self, host): log.info(_(u"Language detection plugin initialization")) self.host = host + host.memory.updateParams(PARAMS) host.trigger.add("MessageReceived", self.MessageReceivedTrigger) host.trigger.add("messageSend", self.MessageSendTrigger) @@ -60,9 +77,14 @@ def MessageReceivedTrigger(self, client, message_elt, post_treat): """ Check if source is linked and repeat message, else do nothing """ - post_treat.addCallback(self.addLanguage) + + lang_detect = self.host.memory.getParamA(NAME, CATEGORY, profile_key=client.profile) + if lang_detect: + post_treat.addCallback(self.addLanguage) return True def MessageSendTrigger(self, client, data, pre_xml_treatments, post_xml_treatments): - self.addLanguage(data) + lang_detect = self.host.memory.getParamA(NAME, CATEGORY, profile_key=client.profile) + if lang_detect: + self.addLanguage(data) return True