From d09d5304f9cb606f188be207340f5549a4dfbb11 Mon Sep 17 00:00:00 2001 From: Riamse Date: Sun, 21 Sep 2014 20:38:08 -0700 Subject: [PATCH] Improve ultilingual dictionary capabilities Add the ability to search for a definition in a specific language --- earwigbot/commands/dictionary.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/earwigbot/commands/dictionary.py b/earwigbot/commands/dictionary.py index 6223461..d22c5c9 100644 --- a/earwigbot/commands/dictionary.py +++ b/earwigbot/commands/dictionary.py @@ -51,6 +51,9 @@ class Dictionary(Command): except exceptions.SiteNotFoundError: site = self.bot.wiki.add_site(project="wiktionary", lang=lang) + multilingual = "#" in term + if multilingual: + lang_requested = term[term.find("#")+1:] page = site.get_page(term, follow_redirects=True) try: entry = page.get() @@ -67,6 +70,9 @@ class Dictionary(Command): result = [] for lang, section in sorted(languages.items()): + if multilingual: + if lang == lang_requested: + return u"({0}) {1}".format(lang, definition) definition = self.get_definition(section, level) result.append(u"({0}) {1}".format(lang, definition)) return u"; ".join(result)