Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: loading a dictionary with cspell-lib? #6627

Open
simon-lang opened this issue Dec 4, 2024 · 1 comment
Open

Question: loading a dictionary with cspell-lib? #6627

simon-lang opened this issue Dec 4, 2024 · 1 comment

Comments

@simon-lang
Copy link

Hello,

I am using cspell-lib in my node application to check for typos. Specifically, the suggestionsForWord method.

I'd like to add multilingual support and scientific terms, however I'm unsure how to do this? The readme in the dictionary I want to use gives these installation instructions:

npm install -g @cspell/dict-scientific-terms-us
cspell link add @cspell/dict-scientific-terms-us

However as I'm not using the cspell cli, I don't think this applies? I've read through the source code in cspell-lib but don't see how.

Any advice appreciated, thanks in advance.

@Jason3S Jason3S transferred this issue from streetsidesoftware/cspell-dicts Dec 5, 2024
@Jason3S
Copy link
Collaborator

Jason3S commented Dec 5, 2024

@simon-lang,

Good question. I moved this to the CSpell repo because it has more to do with cspell-lib than with the dictionaries themselves.

There are two parts to the question:

  1. How should the dictionaries be installed?
  2. How to load the dictionaries?

Q: How should the dictionaries be installed?
A: Just like a normal dependency. See: cspell-bundled-dicts/package.json

Q: How to load the dictionaries?
A: It needs to be imported and resolved in the CSpellSettings.

Something like this:

import { resolveConfigFileImports, suggestionsForWord } from 'cspell';

const rawSettings = {
  import: ['@cspell/dict-scientific-terms-us'],
  dictionaries: ['scientific-terms-us']
};

const settings = await resolveConfigFileImports({ url: new URL(import.meta.url), settings: rawSettings });

const results = await suggestionsForWord('aachen', undefined, settings);

Note: I have not tried this code, but it should give you the right idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants