plugin lang detect: added a parameter to (de)activate the detection
This commit is contained in:
parent
2368e68c37
commit
90f8473b99
1 changed files with 25 additions and 3 deletions
|
|
@ -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 @@ PLUGIN_INFO = {
|
|||
"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 @@ class LangDetect(object):
|
|||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue