From Inkscape Wiki
Revision as of 21:49, 11 April 2007 by YajRcn (talk | contribs)
Jump to navigation Jump to search


It is often desireable to spell check text nodes in an inkscape document.

The stable release of inkscape currently (0.41) does not support this. You will have to open the xml in a text editor and search and spell check the text nodes there.

The code in CVS (0.42pre) has support for spell check in that it marks misspelled words in the "Text" tab in the "Text and Font" dialog if you compile with WITH_GTKSPELL. It will then use gtkspell to check the text nodes. gtkspell seems to pick its language according to LC_MESSAGES. Thus, if you have LC_MESSAGES=fr_FR.UTF-8 in your environment it will presumably use "fr_FR" for spelling.

The desired solution is for inkscape to use the xml:lang attribute of the text node to do the spell checking against the proper language.


There are two ways to implement this:

  1. allow one language per text element
  2. allow any number of languages per text element in that you let the user select a region in the text and define a language for that.

There are two parts to an implementation:

  1. an user interface to be able to set the xml:lang attribute for a text node
  2. make sure gtkspell makes use of this information for spell checking

User interface changes

One language per text element

If you allow only one language per text element the ui is fairly straight forward. The Text and Font dialog would contain an element to specify the language for the current text element.

The global language setting (the default language if you like) could be set in the Page tab of the document preferences dialog.

Multiple languages per text element

If you allow setting the language for any selection of text you could maybe use a combo box or a combo box entry in the text tool bar where you could specify the language for the current selection (or for the current text element if there is no selection). This would also show the current language setting of the selected text element or the selected region.

The global setting would again be in the document preferences dialog

Which languages in the combo box

The question is which languages should the user be able to choose from in the combo box? This question has an impact on the widget choice: for given small set of languages the combo box makes most sense. For a big number of languages the combo box entry might make more sense. There is basically two arguments:

  • The user should only be able to choose from the installed dictionaries. Anything else doesn't make sense as she cannot do spell check for other languages anyway.
  • The user should be able to choose from any existing language because this is a requirement for inkscape to claim to be a conforming svg authoring tool! (see http://www.w3.org/TR/WAI-WEBCONTENT/#gl-abbreviated-and-foreign)

The combo box entry is not nice as it might confuse novice users (too much choice, possibility of non-valid entry) however to be conforming we probably need a combo box entry. Gtk 2.6 has an improved GtkComboBox which can handle trees, so the languages could be set up in a tree where the first level would be the first character of the language (this should allow us to handle the many languages case gracefully without having to resort to manual entry of e.g. de_CH).


A more tricky part would be to allow for some kind of inheritance where you specify a default language and have the possibility to override this in specific text nodes. I would suggest to leave this feature out for now.

Code changes

The second point seems to be fairly straight forward. There are some comments and a todo on how to do this in src/dialogs/text-edit.cpp (search for WITH_GTKSPELL) where it says:

           /* todo: Use computed xml:lang attribute of relevant element, if present, to specify the
              language (either as 2nd arg of gtkspell_new_attach, or with explicit
              gtkspell_set_language call in; see advanced.c example in gtkspell docs).
              sp_text_edit_dialog_read_selection looks like a suitable place. */

However it might be more desireable to set the GtkTextTags in sp_text_edit_dialog_read_selection. According to pjrm this seems to have the desired effect.

It seems that pjrm has basically hacked up a solution for the second part but has apparently hit a bug in gtkspell where it apparently ignores the language info from language GtkTextTag's in preference to querying locale (see the second irc log for all the details).

irc log

Here is the log of the chat on irc:

(11:15:23) egli: but I was wondering if there was a way to spell check the text objects?
(11:17:06) egli: or in case it was not built in I was wondering how complicated it would be to add
(11:18:02) SkoZombie: If you go to "Text and Font" and click on "Text" then it'll hilite possibly mispelt words
(11:18:15) SkoZombie: but i'm runnong the latest CVS version, 0.41 (latest stable) might be different
(11:18:27) egli: hm, let me check
(11:21:26) egli: you are talking about the "Text" tab in the "Text and Font" Dialog, right? It doesn't hilight any words despite the fact that they are in german :-/. Yes this is 0.41
(11:23:16) egli: I presume the UI should have a possibility to specify the language of a text object.
(11:23:36) egli: I guess I'll need to check out CVS
(11:23:41) egli: thanks SkoZombie
(11:23:43) SkoZombie: it must be a 0.42pre feature
(11:23:59) SkoZombie: sorry i can't be of more help, but yes, a spell checker would be a nice addition :)
(11:24:32) egli: I'll see if I find time to look into it
(11:28:28) ^-: [pjrm] spell checking may depend on having gtkspell and possibly related libraries installed.
(11:28:38) ^-: [pjrm] and aspell
(11:28:57) ^-: [pjrm] Is there any message on standard error?
(11:30:30) ^-: [pjrm] gtkspell seems to pick its language according to LC_MESSAGES.  Thus, I have LC_MESSAGES=fr_FR.UTF-8 in my environment, and I get “gtkspell error: aspell: No word lists can be found for the language "fr_FR".” on stderr when I open the Text