mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 02:49:27 +01:00
supybot.plugins.Babelfish.disabledLanguages ->
supybot.plugins.Babelfish.languages
This commit is contained in:
parent
136ec785b0
commit
2a62e3cd5b
@ -29,6 +29,11 @@
|
|||||||
identifies or joins a channel. These latter variables are, of
|
identifies or joins a channel. These latter variables are, of
|
||||||
course, channel variables.
|
course, channel variables.
|
||||||
|
|
||||||
|
* Added configuration variable
|
||||||
|
supybot.plugins.Babelfish.languages (which replaces the old
|
||||||
|
supybot.plugins.Babelfish.disabledLanguages) for specifying
|
||||||
|
which languages will be translated/spoken.
|
||||||
|
|
||||||
* Fixed bug #863601, plugin BadWords fails on color codes.
|
* Fixed bug #863601, plugin BadWords fails on color codes.
|
||||||
|
|
||||||
* Replaced Sourceforge.{rfe,bug} with Sourceforge.tracker, which
|
* Replaced Sourceforge.{rfe,bug} with Sourceforge.tracker, which
|
||||||
|
9
RELNOTES
9
RELNOTES
@ -1,13 +1,18 @@
|
|||||||
Version 0.77.2
|
Version 0.77.2
|
||||||
|
|
||||||
This is a drop-in replacement for 0.77.1, with one exception. The
|
This is a drop-in replacement for 0.77.1, with two exceptions. The
|
||||||
configuration variable formerly known as
|
configuration variable formerly known as
|
||||||
"supybot.plugins.Services.password" is now known as
|
"supybot.plugins.Services.password" is now known as
|
||||||
"supybot.plugins.Services.NickServ.password", due to the fact that
|
"supybot.plugins.Services.NickServ.password", due to the fact that
|
||||||
there might be different passwords for NickServ and ChanServ (and
|
there might be different passwords for NickServ and ChanServ (and
|
||||||
ChanServ passwords are per-channel, whereas NickServ passwords are
|
ChanServ passwords are per-channel, whereas NickServ passwords are
|
||||||
global). If you're using the Services plugin, you'll need to make
|
global). If you're using the Services plugin, you'll need to make
|
||||||
this change in order to continue identifying with services.
|
this change in order to continue identifying with services. The
|
||||||
|
configuration variable formerly known as
|
||||||
|
"supybot.plugins.Babelfish.disabledLanguages" is now known as
|
||||||
|
"supybot.plugins.Babelfish.languages". The configuration variable now
|
||||||
|
accepts the languages that *will* be translated as opposed to ones
|
||||||
|
that are *not* translated.
|
||||||
|
|
||||||
Version 0.77.1
|
Version 0.77.1
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ Babelfish-related commands.
|
|||||||
|
|
||||||
__revision__ = "$Id$"
|
__revision__ = "$Id$"
|
||||||
|
|
||||||
|
import sets
|
||||||
import random
|
import random
|
||||||
from itertools import imap
|
from itertools import imap
|
||||||
|
|
||||||
@ -51,16 +52,17 @@ class Languages(registry.OnlySomeStrings):
|
|||||||
normalize = staticmethod(str.capitalize)
|
normalize = staticmethod(str.capitalize)
|
||||||
|
|
||||||
class SpaceSeparatedListOfLanguages(registry.SeparatedListOf):
|
class SpaceSeparatedListOfLanguages(registry.SeparatedListOf):
|
||||||
|
List = sets.Set
|
||||||
Value = Languages
|
Value = Languages
|
||||||
def splitter(self, s):
|
def splitter(self, s):
|
||||||
return s.split()
|
return s.split()
|
||||||
joiner = ' '.join
|
joiner = ' '.join
|
||||||
|
|
||||||
conf.registerPlugin('Babelfish')
|
conf.registerPlugin('Babelfish')
|
||||||
conf.registerChannelValue(conf.supybot.plugins.Babelfish, 'disabledLanguages',
|
conf.registerChannelValue(conf.supybot.plugins.Babelfish, 'languages',
|
||||||
SpaceSeparatedListOfLanguages([], """Determines which languages are
|
SpaceSeparatedListOfLanguages(babelfish.available_languages, """Determines
|
||||||
unavailable for translation; valid input is a list of languages separated
|
which languages are available for translation; valid input is a list of
|
||||||
by spaces."""))
|
languages separated by spaces."""))
|
||||||
|
|
||||||
class Babelfish(callbacks.Privmsg):
|
class Babelfish(callbacks.Privmsg):
|
||||||
threaded = True
|
threaded = True
|
||||||
@ -78,10 +80,10 @@ class Babelfish(callbacks.Privmsg):
|
|||||||
def _getLang(self, fromLang, toLang, chan):
|
def _getLang(self, fromLang, toLang, chan):
|
||||||
fromLang = self._abbrevs[fromLang.lower()]
|
fromLang = self._abbrevs[fromLang.lower()]
|
||||||
toLang = self._abbrevs[toLang.lower()]
|
toLang = self._abbrevs[toLang.lower()]
|
||||||
disabled = map(str.lower, self.registryValue('disabledLanguages',chan))
|
languages = map(str.lower, self.registryValue('languages',chan))
|
||||||
if fromLang in disabled:
|
if fromLang not in languages:
|
||||||
fromLang = None
|
fromLang = None
|
||||||
if toLang in disabled:
|
if toLang not in languages:
|
||||||
toLang = None
|
toLang = None
|
||||||
return (fromLang, toLang)
|
return (fromLang, toLang)
|
||||||
|
|
||||||
@ -100,20 +102,24 @@ class Babelfish(callbacks.Privmsg):
|
|||||||
if len(args) >= 2 and args[1] == 'to':
|
if len(args) >= 2 and args[1] == 'to':
|
||||||
args.pop(1)
|
args.pop(1)
|
||||||
(fromLang, toLang, text) = privmsgs.getArgs(args, required=3)
|
(fromLang, toLang, text) = privmsgs.getArgs(args, required=3)
|
||||||
|
chan = msg.args[0]
|
||||||
try:
|
try:
|
||||||
(fromLang, toLang) = self._getLang(fromLang, toLang, msg.args[0])
|
(fromLang, toLang) = self._getLang(fromLang, toLang, chan)
|
||||||
if not fromLang or not toLang:
|
if not fromLang or not toLang:
|
||||||
langs = self.registryValue('disabledLanguages', msg.args[0])
|
langs = self.registryValue('languages', chan)
|
||||||
irc.error('I do not speak %s.' % utils.commaAndify(langs,
|
if not langs:
|
||||||
And='or'))
|
irc.error('I do not speak any other languages.')
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
|
irc.error('I only speak %s.' % utils.commaAndify(langs,
|
||||||
|
And='or'))
|
||||||
|
return
|
||||||
translation = babelfish.translate(text, fromLang, toLang)
|
translation = babelfish.translate(text, fromLang, toLang)
|
||||||
irc.reply(translation)
|
irc.reply(translation)
|
||||||
except (KeyError, babelfish.LanguageNotAvailableError), e:
|
except (KeyError, babelfish.LanguageNotAvailableError), e:
|
||||||
irc.error('%s is not a valid language. Valid languages '
|
irc.error('%s is not a valid language. Valid languages '
|
||||||
'include %s.' %
|
'include %s.' %
|
||||||
# FIXME: Subtract disabledLanguages from these.
|
(e, self.registryValue('languages', chan)))
|
||||||
(e, utils.commaAndify(babelfish.available_languages)))
|
|
||||||
except babelfish.BabelizerIOError, e:
|
except babelfish.BabelizerIOError, e:
|
||||||
irc.error(str(e))
|
irc.error(str(e))
|
||||||
except babelfish.BabelfishChangedError, e:
|
except babelfish.BabelfishChangedError, e:
|
||||||
@ -128,22 +134,27 @@ class Babelfish(callbacks.Privmsg):
|
|||||||
of the languages must be English.
|
of the languages must be English.
|
||||||
"""
|
"""
|
||||||
(fromLang, toLang, text) = privmsgs.getArgs(args, required=3)
|
(fromLang, toLang, text) = privmsgs.getArgs(args, required=3)
|
||||||
|
chan = msg.args[0]
|
||||||
try:
|
try:
|
||||||
(fromLang, toLang) = self._getLang(fromLang, toLang, msg.args[0])
|
(fromLang, toLang) = self._getLang(fromLang, toLang, chan)
|
||||||
if fromLang != 'english' and toLang != 'english':
|
if fromLang != 'english' and toLang != 'english':
|
||||||
irc.error('One language in babelize must be English.')
|
irc.error('One language in babelize must be English.')
|
||||||
return
|
return
|
||||||
if not fromLang or not toLang:
|
if not fromLang or not toLang:
|
||||||
langs = self.registryValue('disabledLanguages', msg.args[0])
|
langs = self.registryValue('languages', chan)
|
||||||
irc.error('I do not speak %s.' % utils.commaAndify(langs,
|
if not langs:
|
||||||
And='or'))
|
irc.error('I do not speak any other languages.')
|
||||||
return
|
return
|
||||||
|
else:
|
||||||
|
irc.error('I only speak %s.' % utils.commaAndify(langs,
|
||||||
|
And='or'))
|
||||||
|
return
|
||||||
translations = babelfish.babelize(text, fromLang, toLang)
|
translations = babelfish.babelize(text, fromLang, toLang)
|
||||||
irc.reply(translations[-1])
|
irc.reply(translations[-1])
|
||||||
except (KeyError, babelfish.LanguageNotAvailableError), e:
|
except (KeyError, babelfish.LanguageNotAvailableError), e:
|
||||||
irc.reply('%s is not a valid language. Valid languages '
|
irc.reply('%s is not a valid language. Valid languages '
|
||||||
'include %s.' %
|
'include %s.' % (e,
|
||||||
(e, utils.commaAndify(babelfish.available_languages)))
|
self.registryValue('languages', chan)))
|
||||||
except babelfish.BabelizerIOError, e:
|
except babelfish.BabelizerIOError, e:
|
||||||
irc.reply(e)
|
irc.reply(e)
|
||||||
except babelfish.BabelfishChangedError, e:
|
except babelfish.BabelfishChangedError, e:
|
||||||
@ -157,12 +168,12 @@ class Babelfish(callbacks.Privmsg):
|
|||||||
is provided, will include English in the list of possible languages.
|
is provided, will include English in the list of possible languages.
|
||||||
"""
|
"""
|
||||||
allowEnglish = privmsgs.getArgs(args, required=0, optional=1)
|
allowEnglish = privmsgs.getArgs(args, required=0, optional=1)
|
||||||
language = random.choice(babelfish.available_languages)
|
languages = self.registryValue('languages', msg.args[0])
|
||||||
disabled = self.registryValue('disabledLanguages', msg.args[0])
|
if not languages:
|
||||||
# XXX: Can this loop forever if disabled == available_languages?
|
irc.error('I can\'t speak any other languages.')
|
||||||
while not allowEnglish and language == 'English' and\
|
language = random.choice(languages)
|
||||||
language not in disabled:
|
while not allowEnglish and language == 'English':
|
||||||
language = random.choice(babelfish.available_languages)
|
language = random.choice(languages)
|
||||||
irc.reply(language)
|
irc.reply(language)
|
||||||
|
|
||||||
Class = Babelfish
|
Class = Babelfish
|
||||||
|
@ -48,25 +48,29 @@ if network:
|
|||||||
|
|
||||||
def testRandomlanguage(self):
|
def testRandomlanguage(self):
|
||||||
self.assertNotError('randomlanguage')
|
self.assertNotError('randomlanguage')
|
||||||
|
try:
|
||||||
|
orig = conf.supybot.plugins.Babelfish.languages()
|
||||||
|
conf.supybot.plugins.Babelfish.languages.setValue([])
|
||||||
|
self.assertError('randomlanguage')
|
||||||
|
finally:
|
||||||
|
conf.supybot.plugins.Babelfish.languages.setValue(orig)
|
||||||
|
|
||||||
def testDisabledLanguages(self):
|
def testDisabledLanguages(self):
|
||||||
dl = conf.supybot.plugins.Babelfish.disabledLanguages
|
langs = conf.supybot.plugins.Babelfish.languages
|
||||||
try:
|
try:
|
||||||
orig = dl()
|
orig = langs()
|
||||||
dl.set("")
|
langs.setValue(['Spanish', 'English'])
|
||||||
self.assertResponse('translate sp en hola', 'hello')
|
self.assertResponse('translate sp en hola', 'hello')
|
||||||
dl.set("Spanish")
|
langs.setValue([])
|
||||||
self.assertRegexp('translate sp en hola', 'do not speak')
|
self.assertRegexp('translate sp en hola', 'do not speak')
|
||||||
self.assertRegexp('translate en sp hola', 'do not speak')
|
self.assertRegexp('translate en sp hola', 'do not speak')
|
||||||
dl.set("Spanish Italian")
|
langs.setValue(['Spanish', 'Italian'])
|
||||||
self.assertRegexp('translate sp en hola', 'do not speak')
|
self.assertRegexp('translate sp en hola', 'only speak')
|
||||||
self.assertRegexp('translate en it hello', 'do not speak')
|
self.assertRegexp('translate en it hello', 'only speak')
|
||||||
self.assertRegexp('translate en it [translate sp en hola]',
|
langs.setValue(['English', 'Italian'])
|
||||||
'do not speak')
|
|
||||||
dl.set("")
|
|
||||||
self.assertResponse('translate en it hello', 'ciao')
|
self.assertResponse('translate en it hello', 'ciao')
|
||||||
finally:
|
finally:
|
||||||
dl.set(' '.join(orig))
|
langs.setValue(orig)
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
Loading…
Reference in New Issue
Block a user