SpellingDictionaries class

Namespace Runic.Spelling in Runic.Spelling 0.23.0-preview.1

public sealed class SpellingDictionaries

The Hunspell dictionaries an application can check spelling with, from three sources, and the one a language is checked with. Safe to use from several threads; each call looks at the directories again, so a dictionary another Runic application downloaded is found without a restart.

Remarks

Sources, the first of a name winning: the application's own directories (SpellingDictionarySource.Bundled: SpellingDictionaries.DirectoryEnvironmentVariable, then the package's English dictionaries beside the program, or SpellingDictionariesOptions.ApplicationDirectories), then downloaded dictionaries (SpellingDictionarySource.Downloaded), then the computer's (SpellingDictionarySource.System). A dictionary that matches a language better wins over one of an earlier source that matches it worse: de-CH takes the system's de_CH over a downloaded de.

Nothing is requested over the network but by SpellingDictionaries.DownloadAsync, which the application calls when the user asks for a dictionary.

Constructors

SpellingDictionaries

public SpellingDictionaries(SpellingDictionariesOptions? options = null)

Dictionaries as options say; the defaults without them.

Fields

DirectoryEnvironmentVariable

public const string DirectoryEnvironmentVariable = "RUNIC_SPELLING_DICTIONARIES"

The environment variable naming a directory of dictionaries that comes before every other, for development or a dictionary of the user's own: RUNIC_SPELLING_DICTIONARIES. Its dictionaries count as SpellingDictionarySource.Bundled.

Properties

Catalog

public SpellingCatalog Catalog { get; }

The dictionaries that can be downloaded.

DownloadDirectory

public string DownloadDirectory { get; }

The directory downloaded dictionaries are installed in, one directory each.

SharedDownloadDirectory

public static string SharedDownloadDirectory { get; }

The directory all Runic applications of the user share for downloaded dictionaries: $XDG_DATA_HOME/runic/dictionaries (by default ~/.local/share/runic/dictionaries) on Linux, %LOCALAPPDATA%\Runic\dictionaries on Windows, ~/Library/Application Support/Runic/dictionaries on macOS.

Methods

DownloadAsync

public Task<SpellingDictionary> DownloadAsync(SpellingCatalogEntry entry, IProgress<SpellingDownloadProgress>? progress = null, CancellationToken cancellationToken = default)

Downloads entry into SpellingDictionaries.DownloadDirectory: its files from the catalog's addresses, each checked against its size and SHA-256, then moved into place at once, with its license texts and readme beside it.

Parameters

entry

An entry of SpellingDictionaries.Catalog, such as SpellingAvailability.Download.

progress

Told the bytes received, after each read.

cancellationToken

Stops the download; nothing of it stays installed.

Returns

The installed dictionary. A dictionary of the same name installed before is replaced.

Exceptions

ArgumentException

entry is not of SpellingDictionaries.Catalog.

InvalidDataException

A file's size or SHA-256 is not the catalog's; nothing is installed.

HttpRequestException

A file could not be downloaded; nothing is installed.

IOException

The dictionary could not be written; nothing is installed.

Find

public SpellingDictionary? Find(string languageTag)

The installed dictionary languageTag is checked with; null when none serves it. A language is never checked with another language's dictionary.

Parameters

languageTag

A BCP 47 tag, such as de-CH or en.

Remarks

The first that is installed of: the tag's region; its neighbour (Australian, Irish, New Zealand, South African and Indian English read with British, Canadian with American, Austrian, Luxembourg and Belgian German with Germany's, Liechtenstein's with Switzerland's); for a tag without a region, the region of each of the user's languages that is this language, and its neighbour; the language's usual region (en_US, de_DE); the language alone (de); then any other of the language's, in order.

GetAvailability

public SpellingAvailability GetAvailability(string languageTag)

Whether languageTag can be checked: the installed dictionary it is checked with, and a downloadable one that would serve it better or at all.

Parameters

languageTag

A BCP 47 tag, such as de-CH.

GetInstalled

public IReadOnlyList<SpellingDictionary> GetInstalled()

Every installed dictionary, the first of a name in the order of the sources; in that order.