Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multi language spell check #15851

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/vector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ async function start() {
loadConfig,
loadSkin,
loadLanguage,
loadSpellCheckLanguages,
loadTheme,
loadApp,
showError,
Expand Down Expand Up @@ -139,12 +140,13 @@ async function start() {

// Load language after loading config.json so that settingsDefaults.language can be applied
const loadLanguagePromise = loadLanguage();
const loadSpellCheckLanguagesPromise = loadSpellCheckLanguages();
// as quickly as we possibly can, set a default theme...
const loadThemePromise = loadTheme();
const loadSkinPromise = loadSkin();

// await things settling so that any errors we have to render have features like i18n running
await settled(loadSkinPromise, loadThemePromise, loadLanguagePromise);
await settled(loadSkinPromise, loadThemePromise, loadLanguagePromise, loadSpellCheckLanguagesPromise);

let acceptBrowser = supportedBrowser;
if (!acceptBrowser && window.localStorage) {
Expand Down Expand Up @@ -195,6 +197,7 @@ async function start() {
await loadSkinPromise;
await loadThemePromise;
await loadLanguagePromise;
await loadSpellCheckLanguagesPromise;

// Finally, load the app. All of the other react-sdk imports are in this file which causes the skinner to
// run on the components.
Expand Down
10 changes: 10 additions & 0 deletions src/vector/init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ export async function loadLanguage() {
}
}

export async function loadSpellCheckLanguages() {
const langs = SettingsStore.getValue("spell-check-languages", null, false);
SimonBrandner marked this conversation as resolved.
Show resolved Hide resolved

try {
await languageHandler.setSpellCheckLanguages(langs);
SimonBrandner marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
console.error("Unable to set spell-check language", e);
}
}

export async function loadSkin() {
// Ensure the skin is the very first thing to load for the react-sdk. We don't even want to reference
// the SDK until we have to in imports.
Expand Down
18 changes: 15 additions & 3 deletions src/vector/platform/ElectronPlatform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,14 @@ export default class ElectronPlatform extends VectorBasePlatform {
return 'Electron Platform'; // no translation required: only used for analytics
}

/**
* Return true if platform supports multi-language
* spell-checking, otherwise false.
*/
supportsMultiLanguageSpellCheck(): boolean {
return true;
SimonBrandner marked this conversation as resolved.
Show resolved Hide resolved
}

setNotificationCount(count: number) {
if (this.notificationCount === count) return;
super.setNotificationCount(count);
Expand Down Expand Up @@ -489,13 +497,17 @@ export default class ElectronPlatform extends VectorBasePlatform {
return this.eventIndexManager;
}

setLanguage(preferredLangs: string[]) {
this._ipcCall('setLanguage', preferredLangs).catch(error => {
console.log("Failed to send setLanguage IPC to Electron");
setSpellCheckLanguages(preferredLangs: string[]) {
this._ipcCall('setSpellCheckLanguages', preferredLangs).catch(error => {
console.log("Failed to send setSpellCheckLanguages IPC to Electron");
console.error(error);
});
}

async getAvailableSpellCheckLanguages(): Promise<string[]> {
return this._ipcCall('getAvailableSpellCheckLanguages');
}

getSSOCallbackUrl(fragmentAfterLogin: string): URL {
const url = super.getSSOCallbackUrl(fragmentAfterLogin);
url.protocol = "element";
Expand Down
8 changes: 8 additions & 0 deletions src/vector/platform/WebPlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ export default class WebPlatform extends VectorBasePlatform {
return 'Web Platform'; // no translation required: only used for analytics
}

/**
* Return true if platform supports multi-language
* spell-checking, otherwise false.
*/
supportsMultiLanguageSpellCheck(): boolean {
SimonBrandner marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

/**
* Returns true if the platform supports displaying
* notifications, otherwise false.
Expand Down