From 18925a19c895c5e054eed574434167b7c50682bf Mon Sep 17 00:00:00 2001 From: David Rousselie Date: Wed, 27 Jun 2007 17:54:00 +0200 Subject: [PATCH] Use short command name for long command namespaces for long command namespaces like "http://jabber.org/protocol/admin#add-user", extract its short name "add-user" to translate its description. darcs-hash:20070627155400-86b55-1a25471f7d6df81af64739bbd5d8b2df839ae269.gz --- src/jcl/jabber/command.py | 10 ++++++++-- src/jcl/jabber/tests/__init__.py | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/jcl/jabber/command.py b/src/jcl/jabber/command.py index 9b0222c..8b82814 100644 --- a/src/jcl/jabber/command.py +++ b/src/jcl/jabber/command.py @@ -20,10 +20,13 @@ ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## +import re + from pyxmpp.jabber.disco import DiscoInfo, DiscoItems, DiscoItem, DiscoIdentity from pyxmpp.jabber.dataforms import Form, Field import jcl +from jcl.lang import Lang from jcl.jabber import DiscoHandler from jcl.model.account import Account @@ -37,14 +40,17 @@ class CommandManager(object): self.component = component self.account_manager = account_manager self.commands = [] + self.command_re = re.compile("([^#]*#)?(.*)") def get_command_desc(self, command_name, lang_class): """Return localized command description""" - command_desc_attribut = "command_" + command_name + match = self.command_re.match(command_name) + short_command_name = match.group(2) + command_desc_attribut = "command_" + short_command_name if hasattr(lang_class, command_desc_attribut): command_desc = getattr(lang_class, command_desc_attribut) else: - command_desc = command_name + command_desc = short_command_name return command_desc def list_commands(self, disco_items, lang_class): diff --git a/src/jcl/jabber/tests/__init__.py b/src/jcl/jabber/tests/__init__.py index 00e163e..068bfa7 100644 --- a/src/jcl/jabber/tests/__init__.py +++ b/src/jcl/jabber/tests/__init__.py @@ -9,6 +9,7 @@ def suite(): suite = unittest.TestSuite() suite.addTest(component.suite()) suite.addTest(feeder.suite()) + suite.addTest(command.suite()) return suite if __name__ == '__main__':