Browse Source

Improve ultilingual dictionary capabilities

Add the ability to search for a definition in a specific language
tags/v0.2
Riamse 10 years ago
parent
commit
d09d5304f9
1 changed files with 6 additions and 0 deletions
  1. +6
    -0
      earwigbot/commands/dictionary.py

+ 6
- 0
earwigbot/commands/dictionary.py View File

@@ -51,6 +51,9 @@ class Dictionary(Command):
except exceptions.SiteNotFoundError: except exceptions.SiteNotFoundError:
site = self.bot.wiki.add_site(project="wiktionary", lang=lang) 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) page = site.get_page(term, follow_redirects=True)
try: try:
entry = page.get() entry = page.get()
@@ -67,6 +70,9 @@ class Dictionary(Command):


result = [] result = []
for lang, section in sorted(languages.items()): 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) definition = self.get_definition(section, level)
result.append(u"({0}) {1}".format(lang, definition)) result.append(u"({0}) {1}".format(lang, definition))
return u"; ".join(result) return u"; ".join(result)


Loading…
Cancel
Save