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:
parent
c142ea4b29
commit
572836fb45
54
src/Spell.py
54
src/Spell.py
@ -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"
|
||||||
try:
|
else:
|
||||||
#work around gtkspell bug with tv
|
locale_lang_code = lang
|
||||||
tv = gtk.TextView()
|
tested = False
|
||||||
gtkspell.Spell(tv).set_language(lang_code)
|
#we try a hack to get the locale language.
|
||||||
_installed_languages[lang_code] = lang_name
|
for (lang_code, lang_name) in LANGUAGES.items():
|
||||||
except RuntimeError:
|
# if this lang is the current locale:
|
||||||
#FIXME: this does not work anymore since 10/2008!!!
|
if (locale_lang_code == lang_code):
|
||||||
#if pyenchant is installed we can avoid it, otherwise perhaps
|
tested = True
|
||||||
# future gtkspell3 will offer a solution.
|
# if it is english, we know it works:
|
||||||
pass
|
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:
|
||||||
|
#work around gtkspell bug with tv
|
||||||
|
tv = gtk.TextView()
|
||||||
|
gtkspell.Spell(tv).set_language(lang_code)
|
||||||
|
_installed_languages[lang_code] = lang_name
|
||||||
|
print _("Warning: spelling checker language limited to "
|
||||||
|
"locale '%s'; install pyenchant/python-enchant "
|
||||||
|
"for better options.") % lang
|
||||||
|
except:
|
||||||
|
# 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
|
||||||
|
Loading…
Reference in New Issue
Block a user