changeset 2011:d95a6d553bec

plugin lang detect: added a parameter to (de)activate the detection
author Goffi <goffi@goffi.org>
date Sun, 17 Jul 2016 19:43:30 +0200
parents d2144d04065e
children 53587e738aca
files src/plugins/plugin_exp_lang_detect.py
diffstat 1 files changed, 25 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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 <http://www.gnu.org/licenses/>.
 
-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 = """
+    <params>
+    <individual>
+    <category name="{category_name}">
+        <param name="{name}" label="{label}" type="bool" value="true" />
+    </category>
+    </individual>
+    </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