1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2025-02-08 15:58:42 +01:00

refs #2128 Set spellchecker languages in main process

This commit is contained in:
AkiraFukushima 2021-03-26 01:30:17 +09:00
parent 501b2aceca
commit 2277097f75
5 changed files with 59 additions and 20 deletions

View File

@ -458,7 +458,8 @@
"authorize_url_error": "Failed to get authorize url",
"domain_confirmed": "{{domain}} is confirmed, please login",
"domain_doesnt_exist": "Failed to connect {{domain}}, make sure the server URL",
"loading": "Loading..."
"loading": "Loading...",
"language_not_support_spellchecker_error": "This language is not supported by Spellchecker"
},
"validation": {
"login": {

View File

@ -1,6 +1,7 @@
export type LanguageType = {
name: string
key: string
rfc4646: string
}
export type LanguageList = {

View File

@ -1,70 +1,87 @@
export default {
de: {
name: 'Deutsch',
key: 'de'
key: 'de',
rfc4646: 'de'
},
en: {
name: 'English',
key: 'en'
key: 'en',
rfc4646: 'en-US'
},
fr: {
name: 'Français',
key: 'fr'
key: 'fr',
rfc4646: 'fr'
},
ja: {
name: '日本語',
key: 'ja'
key: 'ja',
rfc4646: 'ja-JP'
},
ko: {
name: '한국어',
key: 'ko'
key: 'ko',
frc4646: 'ko'
},
pl: {
name: 'Polski',
key: 'pl'
key: 'pl',
rfc4646: 'pl'
},
it: {
name: 'Italiano',
key: 'it'
key: 'it',
rfc4646: 'it'
},
zh_cn: {
name: '简体中文',
key: 'zh_cn'
key: 'zh_cn',
rfc4646: 'zh-CN'
},
zh_tw: {
name: '繁體中文',
key: 'zh_tw'
key: 'zh_tw',
rfc4646: 'zh-TW'
},
cs: {
name: 'čeština',
key: 'cs'
key: 'cs',
rfc4646: 'cs'
},
es_es: {
name: 'Español',
key: 'es_es'
key: 'es_es',
rfc4646: 'es-ES'
},
no: {
name: 'norsk',
key: 'no'
key: 'no',
rfc4646: 'no'
},
pt_pt: {
name: 'Português',
key: 'pt_pt'
key: 'pt_pt',
rfc4646: 'pt-PT'
},
ru: {
name: 'русский',
key: 'ru'
key: 'ru',
rfc4646: 'ru'
},
si: {
name: 'සිංහල',
key: 'si'
key: 'si',
rfc4646: 'si'
},
sv_se: {
name: 'svenska',
key: 'sv_se'
key: 'sv_se',
rfc4646: 'sv-SE'
},
tzm: {
name: 'Tamaziɣt',
key: 'tzm'
key: 'tzm',
rfc4646: 'tzm'
}
}

View File

@ -40,7 +40,7 @@ import Hashtags from './hashtags'
import UnreadNotification from './unreadNotification'
import i18next from '~/src/config/i18n'
import { i18n as I18n } from 'i18next'
import Language from '../constants/language'
import Language, { LanguageType } from '../constants/language'
import { LocalAccount } from '~/src/types/localAccount'
import { LocalTag } from '~/src/types/localTag'
import { UnreadNotification as UnreadNotificationConfig } from '~/src/types/unreadNotification'
@ -1034,6 +1034,12 @@ ipcMain.handle('toggle-spellchecker', async (_: IpcMainInvokeEvent, value: boole
})
ipcMain.handle('update-spellchecker-languages', async (_: IpcMainInvokeEvent, languages: Array<string>) => {
const decoded: Array<string> = languages.map(l => {
const d = decodeLanguage(l)
return d.rfc4646
})
mainWindow?.webContents.session.setSpellCheckerLanguages(decoded)
const preferences = new Preferences(preferencesDBPath)
const conf = await preferences.update({
language: {
@ -1494,3 +1500,12 @@ const username = (account: Entity.Account): string => {
return account.username
}
}
const decodeLanguage = (lang: string): LanguageType => {
const l = Object.keys(Language).find(k => Language[k].key === lang)
if (l === undefined) {
return Language.en
} else {
return Language[l]
}
}

View File

@ -86,7 +86,12 @@ export default {
return this.$store.state.Preferences.Language.language.spellchecker.languages
},
set(value) {
this.$store.dispatch('Preferences/Language/updateSpellcheckerLanguages', value)
this.$store.dispatch('Preferences/Language/updateSpellcheckerLanguages', value).catch(() => {
this.$message({
message: this.$t('message.language_not_support_spellchecker_error'),
type: 'error'
})
})
}
}
},