fix: force-language feature was not working

Massimo Melina committed Jun 30, 2023 at 11:25 UTC f25a39e423b5f568fbac292d3146389b3b48eb5a
1 file changed +4 -3
src/lang.ts
+4 -3
@@ -1,5 +1,5 @@
1 import Koa from 'koa'
2 -import { hasProp, wantArray } from './misc'
2 +import { hasProp, tryJson, wantArray } from './misc'
3 import { readFile } from 'fs/promises'
4 import { defineConfig } from './config'
5 import { watchLoad } from './watchLoad'
@@ -52,10 +52,11 @@ defineConfig('force_lang', '', v => {
52 undo?.()
53 if (!v)
54 return forceLangData = undefined
55 - forceLangData = {} // necessary to make the embedded language work
55 + const translation = (EMBEDDED_TRANSLATIONS as any)[v]
56 + forceLangData = { [v]: translation }
57 if (v === EMBEDDED_LANGUAGE) return
58 const res = watchLoad(code2file(v), data => {
58 - forceLangData = { [v]: JSON.parse(data) }
59 + forceLangData = { [v]: tryJson(data) || translation }
60 })
61 undo = res.unwatch
62 })