Spelling

Provide abstracted access to a range of spellchecking backends. Also provides word suggestions. The API is inspired by enchant, but other backends can be added that implement the same API.

Spelling currently require python-enchant for all platform, except OSX, where a native implementation exist.

>>> from kivy.core.spelling import Spelling
>>> s = Spelling()
>>> s.list_languages()
['en', 'en_CA', 'en_GB', 'en_US']
>>> s.select_language('en_US')
>>> s.check('helo')
[u'hole', u'help', u'helot', u'hello', u'halo', u'hero', u'hell', u'held',
 u'helm', u'he-lo']
class kivy.core.spelling.SpellingBase(language=None)

Bases: object

Base class for all spelling providers. Supports some abstract methods for checking words and getting suggestions.

check(word)

If word is a valid word in self._language, return True.

Parameters :
word : str

The word to check. If the word is a valid word in the currently active language, True is returned. If the word shouldn’t be checked, return None (e.g. for ‘’).

list_languages()

Return a list of all languages supported by the registered languages. E.g.: [‘en’, ‘en_GB’, ‘en_US’, ‘de’, ...]

select_language(language)

From the set of registered languages, select the first language for language.

Parameters :
language : str

Language identifier. Needs to be one of the options returned by list_languages(). Sets the language used for spell checking and word suggestions.

suggest(fragment)

For a given fragment (i.e., part of a word or a word by itself), provide corrections (fragment may be misspelled) or completions as a list of strings.

Parameters :
fragment : str

The word fragment to get suggestions/corrections for. E.g.: ‘foo’ might become ‘of’, ‘food’ or ‘foot’.

class kivy.core.spelling.NoSuchLangError

Bases: exceptions.Exception

Exception to be raised when a specific language could not be found.

class kivy.core.spelling.NoLanguageSelectedError

Bases: exceptions.Exception

Exception to be raised when a language-using method is called but no language was selected prior to the call.