TX Spell .NET for Windows Forms

Hyphenation Lists

Topic

A hyphenation list holds the rules by which the words of one language are divided at the end of a line. TX Spell .NET reads these rules from the hyphenation dictionaries of the open source Hunspell project, the same kind of files that OpenOffice uses. Find out where the files come from, how TX Spell .NET chooses one for a text, and how to load and adjust a list in code.

What a Hyphenation List Is

A hyphenation list is a text file of patterns for one language. Its name starts with hyph_ and ends with .dic, such as hyph_en_US.dic for English (United States) or hyph_de_DE.dic for German (Germany). The first line names the encoding of the file, such as UTF-8; the patterns follow.

In code, a list is a HyphenationList. The spell checker uses a list only after it has been added to its HyphenationLists collection, and it takes the language of the list from the file name: hyph_en.dic is English, hyph_de_CH.dic German (Switzerland).

Hyphenation lists are separate from the dictionaries that check spelling. A dictionary and a hyphenation list of the same language are two files in two folders, and a language can have one without the other.

Where the Files Are

TX Spell .NET looks for hyphenation lists in the HyphenationLists folder, next to the application or, on the development machine, below the Assembly folder of the installation; HyphenationListsDirectoryPath sets another folder, as Installing Dictionaries and Language Data describes. The package TXTextControl.TXSpell.WinForms.SDK brings one list, hyph_en_US.dic, and AvailableHyphenationLists returns the names of all lists in the folder.

Get Lists for Other Languages

Text Control offers the language data of TX Spell .NET as ZIP archives, one per language, each with the folder Dictionaries and, for many languages, HyphenationLists and SynonymLists. Copy the hyph_ file from the HyphenationLists folder of an archive into the HyphenationLists folder of your application. Of the 47 archives, 32 contain a hyphenation list:

LanguageArchiveHyphenation list
Afrikaansaf_ZAhyph_af_ZA.dic
Bulgarianbg_BGhyph_bg_BG.dic
Catalanca_EShyph_ca.dic
Croatianhr_HRhyph_hr_HR.dic
Czechcs_CZhyph_cs_CZ.dic
Danishda_DKhyph_da_DK.dic
Dutchnl_NLhyph_nl_NL.dic
Englishen_AU, en_CA, en_GB, en_UShyph_en_AU.dic, hyph_en_CA.dic, hyph_en_GB.dic, hyph_en_US.dic
Estonianet_EEhyph_et_EE.dic
Frenchfr, fr_FRhyph_fr.dic
Germande_AT, de_CH, de_DEhyph_de_AT.dic, hyph_de_CH.dic, hyph_de_DE.dic
Greekel_GRhyph_el_GR.dic
Irishga_IEhyph_ga_IE.dic
Italianit_IThyph_it_IT.dic
Norwegiannb_NO, nn_NOhyph_nb_NO.dic, hyph_nn_NO.dic
Polishpl_PLhyph_pl_PL.dic
Portuguesept_BR, pt_PThyph_pt_BR.dic, hyph_pt_PT.dic
Romanianro_ROhyph_ro_RO.dic
Russianru_RUhyph_ru_RU.dic
Serbiansrhyph_sr.dic, hyph_sh.dic
Slovaksk_SKhyph_sk_SK.dic
Sloveniansl_SIhyph_sl_SI.dic
Spanishes_EShyph_es_ANY.dic
Swedishsv_SEhyph_sv.dic

The archives of Arabic, Belarusian, Hebrew, Persian, Urdu, Vietnamese and some other languages have a dictionary but no hyphenation list. Dictionaries and Languages describes the archives, and the blog article TX Spell .NET 4.0: New Dictionaries and Hyphenation Lists Available announced them.

How a List Is Chosen

The HyphenationLanguage property of the TXSpellChecker selects the default list, the one used for text without a language of its own. It is "(Auto)" for a spell checker you drop on a form:

The Properties window of txSpellChecker1 with HyphenationLanguage set to (Auto) and the drop-down of Language open with the values (none), (Auto) and en_US.dic.

ValueDefault list
"(Auto)"The list in the language of the default spell check dictionary, set by Language. Without an exact match, a list of nearly the same language, such as hyph_en_US.dic for British English. When Language is "(none)", the list in the language of the application's environment
The file name of a list, such as "hyph_de_DE.dic"That list, from the HyphenationLists folder
"(none)"No list is set

The chosen list is added to HyphenationLists, and its IsSelectedAsDefault property is true. When the folder has no list for the language, the property is reset to "(none)". With a TextControl, text that has a language of its own is hyphenated with a list of that language, as Hyphenation with TX Text Control describes.

Change How Words Are Divided

Each list has settings that apply to the words of its language:

PropertyDefaultEffect
HyphenateCapitalizedWordstrueWords in uppercase, such as "HYPHENATION", are hyphenated
MinCharsAtWordBegin2The fewest characters at the begin of a word, before a division
MinCharsAtWordEnd2The fewest characters at the end of a word, after a division
UseOnlyCompoundHyphenationPointsfalseCompound words are divided only between their parts, as "Rechtschreib-prüfung" in German
MinSyllablesBeforeCompoundHyphenationPoint1The fewest syllables before a division between compound parts
MinSyllablesAfterCompoundHyphenationPoint1The fewest syllables after a division between compound parts

With 3 characters at the begin and the end, for example, "international" is divided as inter-na-tional instead of in-ter-na-tion-al. The user changes the same settings on the Hyphenation tab of the options dialog, which The Hyphenation and Thesaurus Tabs describes.

Load a List in Code

To hyphenate another language than the default one, add its list to HyphenationLists. The file must be in the HyphenationLists folder, or you pass its full path:

using TXTextControl.Proofing;

// Load the German hyphenation list from the HyphenationLists folder
HyphenationList german = new HyphenationList("hyph_de_DE.dic");
txSpellChecker1.HyphenationLists.Add(german);

// Keep at least three characters on each line
german.MinCharsAtWordBegin = 3;
german.MinCharsAtWordEnd = 3;

The code works as follows:

  • The HyphenationList constructor takes the file name or the full path. A file name without a path is looked for in the default HyphenationLists folder.
  • Add checks the file. It throws an ArgumentException when the file doesn't exist ("File does not exist") or its name doesn't have the form hyph_*.dic ("Dictionary type is not valid.").
  • After Add, Language holds the language read from the file name and Name the name you passed.

To change the settings of a list that is already loaded, such as the English list, get it by its name with GetItem:

HyphenationList english = txSpellChecker1.HyphenationLists.GetItem("hyph_en_US.dic");

if (english != null)
{
    // Don't hyphenate words in uppercase, such as product names
    english.HyphenateCapitalizedWords = false;
}

GetItem returns null when no list of that name is loaded. The indexer, HyphenationLists[0], reaches a list by its position instead.

Next Steps