Further hacking to make testing locales faster, but still work in a limited fashion when pyenchant is not installed

svn: r13560
This commit is contained in:
Doug Blank 2009-11-12 02:58:33 +00:00
parent c142ea4b29
commit 572836fb45

View File

@ -172,7 +172,6 @@ class Spell(object):
"""Attach a gtkspell instance to the passed TextView instance. """Attach a gtkspell instance to the passed TextView instance.
""" """
lang = locale.getlocale()[0] lang = locale.getlocale()[0]
_installed_languages = {'off': _('None')} _installed_languages = {'off': _('None')}
if HAVE_ENCHANT and HAVE_GTKSPELL: if HAVE_ENCHANT and HAVE_GTKSPELL:
@ -194,19 +193,46 @@ class Spell(object):
_installed_languages[language] = " ".join(name.split('_')) _installed_languages[language] = " ".join(name.split('_'))
elif not HAVE_ENCHANT and HAVE_GTKSPELL: elif not HAVE_ENCHANT and HAVE_GTKSPELL:
#we try a hack to get the languages. We do this by trying all # if lang is None, default to en:
#languages we know of. if lang == None:
for lang_code, lang_name in LANGUAGES.items(): locale_lang_code = "en"
else:
locale_lang_code = lang
tested = False
#we try a hack to get the locale language.
for (lang_code, lang_name) in LANGUAGES.items():
# if this lang is the current locale:
if (locale_lang_code == lang_code):
tested = True
# if it is english, we know it works:
if locale_lang_code == "en":
_installed_languages[locale_lang_code] = lang_name
print _("Warning: spelling checker language limited to "
"locale '%s'; install pyenchant/python-enchant "
"for better options.") % "en"
elif locale.getlocale()[1] == "UTF8":
# Only worked with UTF8 versions of language.
# But, we need to test it:
try: try:
#work around gtkspell bug with tv #work around gtkspell bug with tv
tv = gtk.TextView() tv = gtk.TextView()
gtkspell.Spell(tv).set_language(lang_code) gtkspell.Spell(tv).set_language(lang_code)
_installed_languages[lang_code] = lang_name _installed_languages[lang_code] = lang_name
except RuntimeError: print _("Warning: spelling checker language limited to "
#FIXME: this does not work anymore since 10/2008!!! "locale '%s'; install pyenchant/python-enchant "
#if pyenchant is installed we can avoid it, otherwise perhaps "for better options.") % lang
# future gtkspell3 will offer a solution. except:
pass # FIXME: this does not work anymore since 10/2008!!!
# if pyenchant is installed we can avoid it, otherwise
# perhaps future gtkspell3 will offer a solution.
print _("Warning: spelling checker disabled; "
"install pyenchant/python-enchant to enable.")
# if we matched, we're done looking
break
if not tested:
# if we didn't see a match on lang, then there is no spell check
print _("Warning: spelling checker disabled; "
"install pyenchant/python-enchant to enable.")
def __init__(self, textview): def __init__(self, textview):
self.textview = textview self.textview = textview