org.freedesktop.enchant

## Class Enchant

- Object
- - org.gnome.glib.Glib
  - - org.freedesktop.enchant.Enchant

-     public final class Enchant
      extends Glib

  Get a handle to an Enchant dictionary for spell checking.

  Enchant is not itself a spell checking library; it is, rather a facade to various common spelling mechanisms. It provides a simple and sufficient API for doing spelling operations. Which actual back-end provider will be employed depends on the system and user "ordering" files.

  ## Usage

  Enchant is straight-forward to use. For possibly misspelled `word`, you can do

       Enchant.init();

       dict = Enchant.requestDictionary("en_CA");

       if (dict.check(word)) {
           return "Spelled correctly!";
       } else {
           possibles = dict.suggest(word);

           str.append("The word ");
           str.append(word);
           str.append(" was misspelled. You could correct it with one of:\n"

           for (i = 0; i < possibles.length; i++) {
               str.append(possibles[i]);
               str.append('\n');
           }

           return str.toString();
       }

  Since:
    4.0.14
  Author:
    Andrew Cowie
  See Also:
    Enchant home page

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `existsDictionary(String lang)` Does a dictionary exist for the given "language"?
    `static void` | `init()`
    `static String[]` | `listDictionaries()` Get a list of available dictionaries as known to Enchant.
    `static Dictionary` | `requestDictionary(String lang)` Get a Dictionary for the specified language.
    `static Dictionary` | `requestPersonalWordList(String filename)` Get a Dictionary for the specified personal word list.

    - ### Methods inherited from class org.gnome.glib.Glib

      `formatSizeForDisplay, getProgramName, getRealName, getSystemConfigDirs, getSystemDataDirs, getUserCacheDir, getUserConfigDir, getUserDataDir, getUserName, getUserSpecialDir, idleAdd, markupEscapeText, reloadUserSpecialDirsCache, setProgramName`

    - ### Methods inherited from class Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### existsDictionary

          public static boolean existsDictionary(String lang)

      Does a dictionary exist for the given "language"?

      Languages are indicated in a locale-like form; while you can use just the language code `en`, specifying a specific language variant such as `"en_UK"` or `"fr_CA"` is preferred.

      Since:
        4.0.17

    - #### init

          public static void init()

      Since:
        4.0.14

    - #### listDictionaries

          public static String[] listDictionaries()

      Get a list of available dictionaries as known to Enchant. This returns an unsorted array of Strings of the form:

           en
           en_AU
           en_CA
           en_GB
           en_US
           en_ZA
           es
           fr_BE
           fr_CA
           fr_CH
           fr_FR
           fr_LU
           fr_MC

      (that was the list on a computer with English, French, and Spanish dictionaries installed via packages `language-support-en`, `language-support-fr`, `language-support-es` respectively on, in this case, Ubuntu Linux).

      You don't necessarily need to callt this function. You can test for the existance of a dictionary with `Enchant.existsDictionary()`, or even just get on directly with loading a dictionary with `requestDictionary()`.

      If you are using the results of this funciton to create a list in a user interface, you'll probably want to present the language and country names translated. Use `Internationalization.translateLanguageName()` and `Internationalization.translateCountryName()` although you'll have to look up the proper ISO 639 and ISO 3166 names in `/usr/share/xml/iso-codes/iso_{639,3166}.xml` first.

      Since:
        4.0.17

    - #### requestDictionary

          public static Dictionary requestDictionary(String lang)

      Get a Dictionary for the specified language.

      See `existsDictionary()` for discussion of valid language values. You probably want to call that if you're considering user input values.

      Returns `null` if no suitable dictionary was found.

      Since:
        4.0.14

    - #### requestPersonalWordList

          public static Dictionary requestPersonalWordList(String filename)
                                                    throws FileNotFoundException

      Get a Dictionary for the specified personal word list.

      Word lists are simple files with one word per line. By creating a Dictionary of a personal word list you can add words to a file that is independent of a normal spelling engine back-end.

      Throws:
        `FileNotFoundException`
      Since:
        4.0.14