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

Added multilanguage support #38

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ CodeMirror.fromTextArea(document.getElementById("textarea"), {

That's it!

## Other languages
In order to use another language instead of `en_US` you just have to provide an additional piece of configuration:

```JS
CodeMirrorSpellChecker({
codeMirrorInstance: CodeMirror,
customDict: {
dic: "https://github.com/titoBouzout/Dictionaries/blob/master/Italian.dic",
aff: "https://github.com/titoBouzout/Dictionaries/blob/master/Italian.aff"
}
});

CodeMirror.fromTextArea(document.getElementById("textarea"), {
mode: "spell-checker",
backdrop: "gfm" // Your desired mode
});
```

## Customizing
You can customize the misspelled word appearance by updating the CSS. All misspelled words will have the `.cm-spell-error` class.

Expand Down
18 changes: 16 additions & 2 deletions src/js/spell-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ function CodeMirrorSpellChecker(options) {
if(!CodeMirrorSpellChecker.aff_loading) {
CodeMirrorSpellChecker.aff_loading = true;
var xhr_aff = new XMLHttpRequest();
xhr_aff.open("GET", "https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.aff", true);
var affUrl;
if(options.customDict===undefined){
affUrl="https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.aff";
}
else{
affUrl=options.customDict.aff;
}
xhr_aff.open("GET", affUrl, true);
xhr_aff.onload = function() {
if(xhr_aff.readyState === 4 && xhr_aff.status === 200) {
CodeMirrorSpellChecker.aff_data = xhr_aff.responseText;
Expand All @@ -53,7 +60,14 @@ function CodeMirrorSpellChecker(options) {
if(!CodeMirrorSpellChecker.dic_loading) {
CodeMirrorSpellChecker.dic_loading = true;
var xhr_dic = new XMLHttpRequest();
xhr_dic.open("GET", "https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.dic", true);
var dicUrl
if(options.customDict===undefined){
dicUrl="https://cdn.jsdelivr.net/codemirror.spell-checker/latest/en_US.dic";
}
else{
affUrl=options.customDict.dic;
}
xhr_dic.open("GET", dicUrl, true);
xhr_dic.onload = function() {
if(xhr_dic.readyState === 4 && xhr_dic.status === 200) {
CodeMirrorSpellChecker.dic_data = xhr_dic.responseText;
Expand Down