Open towerberlin opened 4 months ago
I think this could be done pretty easily with a plug. Maybe have a default language and allow it to be overridden with a Frontmatter tag? I wonder how this would play into potential plans (if any) for localizing the app?
For now, I think I have a workaround for you:
First, create this custom function somewhere in your space (I created a page called SetLanguageFunction
, but you can put it on any page, really). Replace "en" with whatever you want the default language to be.
```space-script
silverbullet.registerFunction("setLang", (lang = "en") => {
document.documentElement.lang = lang;
});
Then create a page (I called it "SetLanguageWidget") as a widget that runs it on every page and sets the language:
{{#if setLang(@page.language)}}{{/if}}
Then you can override the language for a specific page using Frontmatter:
This page should have the <html>
tag's lang
attribute set to "de"!
There may be a more elegant way to handle it - I'm still pretty new to SilverBullet.
This workaround doesn't work for me (Silverbullet Version 0.7.6)
Console-log from browser:
Error loading space-script: Error evaluating script: expected expression, got ';' for script: silverbullet.registerFunction("setLang", (lang = "en") => { document.documentElement.lang = lang ||; });
Any idea how to fix this?
@inos-github sorry that should be:
```space-script
silverbullet.registerFunction("setLang", (lang = "en") => {
document.documentElement.lang = lang;
});
```
(I fixed the original comment, too)
@joekrill thank you for the replay an the fix! Now I have another error :
Remote syscall error document is not defined
An exception was thrown as a result of invoking function renderTemplateWidgetsTop error: document is not defined
Error: document is not defined
onMessage worker_sandbox.ts:93
onmessage worker_sandbox.ts:59
I'm using the actual Firefox Browser on Linux
@inos-github hmm, I guess SilverBullet also runs this code on the server? You can try something like this:
```space-script
silverbullet.registerFunction("setLang", (lang = "en") => {
if (typeof document !== "undefined") {
document.documentElement.lang = lang;
}
});
```
Now it works, thank you very much!
Is it possible to define the content language in SETTINGS?
I write my notes in German and in SB, for example, the spell check only works for English content.