Spell checking language

Hi,
is there any way to change which language the spell checker is using? I mix languages so if it could be changed per page then that would be even better. Just the option of disabling it would be okay as well.

Important note: spell checking is a browser/native operation, and is not controled by silverbullet itself, therefor here is an also earlier post regarding spellcheck:

TL;DR
To disable globally for SB:

js.window.document.querySelector(".cm-content").setAttribute("spellcheck", "false")

Using the exact same DOM manipulation strategy by applying the standard HTML lang attribute to the CodeMirror editor container (.cm-content)

To set a language globally, the snippet is:

js.window.document.querySelector(".cm-content").setAttribute("lang", "de")

(Replace "de" with "en", "fr", "es", or whichever language code you require.)

Per-Page Dynamic Language Setting

To set the language automatically based on the page you are viewing, you can hook into SilverBullet's page load event in Space Lua. You can define a frontmatter attribute on your page (such as lang: de) and update the editor attribute dynamically whenever a page loads.

Add something like this to a Space Lua block:

event.listen {  
  name = "editor:pageLoaded",  
  run = function(e)  
    local pageLang = "en"  
    local meta = editor.getCurrentPageMeta()  
    if meta and meta.lang then  
      pageLang = meta.lang  
    end  
  
    local editorEl = js.window.document.querySelector(".cm-content")  
    if editorEl then  
      editorEl.setAttribute("lang", pageLang)  
    end  
  end  
}

Now, on any page where you want a specific spellcheck language, simply add it to the page frontmatter at the top:

---
lang: de
---

If a page omits the lang attribute, it will gracefully fall back to "en".

(Do ensure your browser actually has the corresponding language dictionaries installed for native spellcheck to function properly.)

the code above was done using Silverbullet - DeepWiki and tested by me if the actual lang is set by the script in the DOM, but i couldnt also test the spelling check, because the behaviour is specific to each browser and installed language directories :wink:

... and no, i'm not an AI-bot :stuck_out_tongue:

Thank you for the reply!

Your snippet does indeed change the lang attribute. But it seems that, at least, Edge Webview does not care about it when it comes to spellchecking unfortunately. Neither does Firefox from what I can tell. Your suggestion would've been a great solution otherwise.

Currently, I'm only using SilverBullet+, but my plan is to set up a server so I can use my phone as well. What I did now is to query the user agent string to see if it matches Edge, and then turn off spellcheck. Is there a way to directly query if I'm using SB+?

Thank you for taking the time to help!

I don't know if SB+ is based on Tauri or Electron as the browser engine, and I'm too lazy to look that up. maybe someone else has more experience in spell checking for compiled Tauri/Electron apps.

I digged a little deeper with a little help from claude and found out following, the following text was generated using AI but it contains interesting and important explanations about this topic. if it's agains the forums policy to not use ai generated contet, i'd be happy to remove it, but i thought its an important note to the topic:

Short version

Yes, both Electron and Tauri render pages with the standard DOM, so lang="..." and spellcheck="true" are recognized exactly like in a normal browser — they're just HTML/DOM attributes, nothing framework-specific.

But spellcheck only turns checking on/off for an element. It does not select which dictionary/language is used. That selection is controlled separately by the browser/webview engine, and per-element lang-based dictionary selection is inconsistently supported:

Engine Used by Respects per-element lang for dictionary choice?
Chromium (bundled) Electron No. Chromium checks text against a global list of enabled dictionaries (session.setSpellCheckerLanguages(['en-US','fr',...])), word-by-word, regardless of which field or its lang. A word is "correct" if it matches any enabled dictionary. Default = OS locale. On macOS, Electron instead uses the native macOS spellchecker, which does its own language auto-detection per field (not via lang).
WebView2 (native, Chromium-based) Tauri on Windows No, confirmed as an open issue with Microsoft — dictionary is picked from the WebView2 Environment Language setting, globally, and per-element lang (even set dynamically via JS) is ignored.
WKWebView Tauri on macOS Uses the native macOS spellchecker/NSSpellChecker (same as Electron-on-mac), which auto-detects language per editable field rather than strictly reading lang.
WebKitGTK (enchant/hunspell) Tauri on Linux Generally follows the system/GTK input language config, not per-element lang, and only checks languages whose dictionary is actually installed on the system.
Firefox (Gecko) Partially respects lang per <textarea>/<input>, but has long-standing bugs where it doesn't always pick correctly.

So: the HTML spec says UAs "should" use lang to pick a dictionary, but in practice almost none of the engines you'd hit in a Tauri or Electron app honor that per-element. It's a known, still-open gap.

Dictionary availability

  • Electron: bundles Hunspell .dic/.aff files itself (downloaded from a Google CDN by default, or you can self-host them) for Windows/Linux, so any language you enable is generally available regardless of the OS. macOS uses whatever's built into the OS.
  • Tauri: bundles nothing , it's 100% dependent on the OS/webview's own spellcheck data. Windows needs the language + "spell checking" optional feature installed via Windows Settings; macOS ships many dictionaries out of the box; Linux needs the relevant hunspell-xx/myspell-xx package installed via the system package manager. If the dictionary isn't installed at the OS level, spellcheck for that language silently doesn't happen , no error, just no red squiggles.
  • Neither Tauri nor (currently) any first-party API lets you force "field A = German dictionary, field B = French dictionary" reliably , you'd need something like electron-spellchecker's CLD-based per-input language detection, or roll your own JS spellchecker (e.g., using a WASM Hunspell) if you truly need field-level control.

TL;DR

theoretically you could use lang="en" to set the spell checking language, but depending on Browser, Engine, OS you'll get various results, with an approx of 5-10% success rate.
So the best approach would be a simple toggle to enable/disable spell checking.

Thanks! I got basically the same result when I dug around myself. And I'm almost certain that SB+ is a Tauri app.
I use Signal for desktop, which is an electron app. And, as you pointed out, it uses all installed dictionaries. If only Webview could do the same. Oh well.

Thanks for digging a bit deeper!