Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit 2c11a9d

Browse files
Merge pull request #1432 from ssbc/spellcheck-options
Allow selection of multiple or no spellchecker languages.
2 parents 1ba77b6 + 1b789e6 commit 2c11a9d

File tree

4 files changed

+107
-4
lines changed

4 files changed

+107
-4
lines changed

index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ electron.app.on('ready', () => {
170170
});
171171
})
172172

173+
electron.ipcMain.handle('setSpellcheckLangs', (ev, params) => {
174+
if (!windows.main) { return }
175+
const { langs, enabled } = params
176+
windows.main.webContents.session.setSpellCheckerLanguages(enabled ? langs : []);
177+
})
173178
electron.ipcMain.handle('consoleLog', (ev, o) => console.log(o))
174179
electron.ipcMain.handle('consoleError', (ev, o) => console.error(o))
175180
electron.ipcMain.handle('badgeCount', (ev, count) => {

lib/depject/page/html/render/settings.js

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
const { h } = require('mutant')
1+
const { computed, h, map, Value, watch } = require('mutant')
22
const nest = require('depnest')
33
const packageInfo = require('../../../../../package.json')
4+
const ExpanderHook = require('../../../../expander-hook')
45

56
const themeNames = Object.keys(require('../../../../../styles'))
7+
const electron = require('electron')
68

79
exports.needs = nest({
810
'settings.obs.get': 'first',
@@ -13,6 +15,12 @@ exports.needs = nest({
1315

1416
exports.gives = nest('page.html.render')
1517

18+
let availableDictionaries = Value([])
19+
20+
electron.ipcRenderer.on('setAvailableDictionaries', (ev, langs) => {
21+
availableDictionaries.set(langs)
22+
})
23+
1624
exports.create = function (api) {
1725
return nest('page.html.render', function channel (path) {
1826
if (path !== '/settings') return
@@ -31,6 +39,12 @@ exports.create = function (api) {
3139

3240
const theme = api.settings.obs.get('patchwork.theme', 'light')
3341
const lang = api.settings.obs.get('patchwork.lang', '')
42+
const spellcheckLangs = api.settings.obs.get('patchwork.spellcheckLangs', ['en-GB'])
43+
const enableSpellCheck = api.settings.obs.get('patchwork.enableSpellCheck', true)
44+
const spellcheckParams = computed([spellcheckLangs, enableSpellCheck], (langs, enabled) => ({ langs, enabled }))
45+
watch(spellcheckParams, (params) => {
46+
electron.ipcRenderer.invoke('setSpellcheckLangs', params)
47+
})
3448
const fontSize = api.settings.obs.get('patchwork.fontSize', '')
3549
const fontFamily = api.settings.obs.get('patchwork.fontFamily', '')
3650
const includeParticipating = api.settings.obs.get('patchwork.includeParticipating', false)
@@ -66,7 +80,7 @@ exports.create = function (api) {
6680
]),
6781

6882
h('section', [
69-
h('h2', i18n('Language')),
83+
h('h2', i18n('Interface Language')),
7084
h('select', {
7185
style: { 'font-size': '120%' },
7286
value: lang,
@@ -79,6 +93,30 @@ exports.create = function (api) {
7993
])
8094
]),
8195

96+
h('section', [
97+
h('h2', i18n('Spellchecking')),
98+
h('div', [
99+
checkbox(enableSpellCheck, {
100+
label: i18n('Enable Spellchecking')
101+
})
102+
]),
103+
h('h3', i18n('Languages to check for (select multiple)')),
104+
h('select', {
105+
disabled: computed(enableSpellCheck, (b) => !b),
106+
multiple: true,
107+
size: 10,
108+
style: { 'font-size': '120%' },
109+
hooks: [SpellcheckChangeHook(spellcheckLangs)]
110+
}, [
111+
map(availableDictionaries, (code) => h('option', {
112+
value: code,
113+
selected: spellcheckLangs().indexOf(code) !== -1,
114+
}, [
115+
'[', code, '] ', getLocaleName(code)
116+
]))
117+
])
118+
]),
119+
82120
h('section', [
83121
h('h2', i18n('Font Size')),
84122
h('select', {
@@ -99,7 +137,7 @@ exports.create = function (api) {
99137
'ev-change': (ev) => fontFamily.set(ev.target.value)
100138
}, [
101139
h('option', { value: '' }, i18n('Default')),
102-
fontFamilies.map(family => h('option', { value: family }, family))
140+
fontFamilies.map(family => h('option', { value: family, }, family))
103141
])
104142
]),
105143
h('h2', i18n('Notification Options')),
@@ -159,3 +197,17 @@ function checkbox (param, { label }) {
159197
}), ' ', label
160198
])
161199
}
200+
201+
function SpellcheckChangeHook (spellcheckLangs) {
202+
return function (element) {
203+
element.addEventListener('change', (ev) => {
204+
const newLangs = []
205+
for (const c of ev.target.children) {
206+
if (c.selected) {
207+
newLangs.push(c.value)
208+
}
209+
}
210+
spellcheckLangs.set(newLangs)
211+
})
212+
}
213+
}

lib/window.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ module.exports = function Window (config, path, opts, serverDevToolsCallback, na
2929
data: opts.data || '',
3030
title: opts.title || 'Patchwork',
3131
})
32+
const availableLangs = window.webContents.session.availableSpellCheckerLanguages
33+
window.webContents.send('setAvailableDictionaries', availableLangs)
3234
})
3335

3436
// setTimeout(function () {

locales/en.json

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,5 +306,49 @@
306306
"nl": "nl",
307307
"Last activity": "Last activity",
308308
"Status": "Status",
309-
"Indexes": "Indexes"
309+
"Indexes": "Indexes",
310+
"Interface Language": "Interface Language",
311+
"fa": "fa",
312+
"Spellchecking": "Spellchecking",
313+
"Enable Spellchecking": "Enable Spellchecking",
314+
"Languages to check for (select multiple)": "Languages to check for (select multiple)",
315+
"af": "af",
316+
"bg": "bg",
317+
"ca": "ca",
318+
"cs": "cs",
319+
"cy": "cy",
320+
"da": "da",
321+
"en-AU": "en-AU",
322+
"en-CA": "en-CA",
323+
"en-GB": "en-GB",
324+
"en-GB-oxendict": "en-GB-oxendict",
325+
"en-US": "en-US",
326+
"es-419": "es-419",
327+
"es-AR": "es-AR",
328+
"es-ES": "es-ES",
329+
"es-MX": "es-MX",
330+
"es-US": "es-US",
331+
"et": "et",
332+
"fo": "fo",
333+
"he": "he",
334+
"hi": "hi",
335+
"hr": "hr",
336+
"hu": "hu",
337+
"hy": "hy",
338+
"id": "id",
339+
"it": "it",
340+
"ko": "ko",
341+
"lt": "lt",
342+
"lv": "lv",
343+
"nb": "nb",
344+
"pt-PT": "pt-PT",
345+
"ro": "ro",
346+
"sh": "sh",
347+
"sq": "sq",
348+
"sr": "sr",
349+
"sv": "sv",
350+
"ta": "ta",
351+
"tg": "tg",
352+
"tr": "tr",
353+
"vi": "vi"
310354
}

0 commit comments

Comments
 (0)