Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Add multi language spell check #5452

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2f988bc
Added UI
SimonBrandner Nov 26, 2020
051368e
Fix i18n
SimonBrandner Nov 26, 2020
aba5ef1
Merge branch 'develop' into feature-multi-language-spell-check
SimonBrandner Nov 28, 2020
557e650
Added spell-check-languages setting
SimonBrandner Nov 28, 2020
43daec0
Added setSpellCheckLanguages() method
SimonBrandner Nov 28, 2020
5e4f990
Added persistance
SimonBrandner Nov 28, 2020
f0bbed0
Allow default value
SimonBrandner Nov 29, 2020
8f40cd3
Added styling
SimonBrandner Nov 29, 2020
7609f20
Added newline to end
SimonBrandner Nov 29, 2020
ead00dc
Set spell-check languages without reloading
SimonBrandner Nov 29, 2020
38080c5
Added getAvailableSpellCheckLanguages() methods
SimonBrandner Nov 29, 2020
5d9f5ba
Fix indentation
SimonBrandner Nov 30, 2020
b207a87
Change label
SimonBrandner Dec 1, 2020
cf61d50
Added SpellCheckLanguagesDropdown
SimonBrandner Dec 1, 2020
a6d6af1
Added defaults
SimonBrandner Dec 1, 2020
e9203d7
Removed unnecessary imports
SimonBrandner Dec 1, 2020
8287f19
Fix i18n
SimonBrandner Dec 1, 2020
44a363f
Fix default value
SimonBrandner Dec 1, 2020
3c2bb6e
Cleanup
SimonBrandner Dec 1, 2020
db5bc0c
Fix formatting
SimonBrandner Dec 1, 2020
bab541a
Hide spell-check settings if not using Electron
SimonBrandner Dec 2, 2020
fa19adc
Simplifie
SimonBrandner Dec 3, 2020
b8008b5
Added in if statement
SimonBrandner Dec 3, 2020
19d9ea3
Merge branch 'develop' into feature-multi-language-spell-check
SimonBrandner Dec 3, 2020
bd0e544
Merge branch 'develop' into feature-multi-language-spell-check
SimonBrandner Feb 18, 2021
5de99c7
Fix licenses
SimonBrandner Feb 18, 2021
ed02503
Fix one more license
SimonBrandner Feb 18, 2021
2ebc125
Removed unnecessary functions
SimonBrandner Feb 18, 2021
305d64c
Removed log
SimonBrandner Feb 18, 2021
1ba512a
Use getSpellCheckLanguages() instead of a setting
SimonBrandner Feb 18, 2021
5a6e393
Removed spell-check-languages
SimonBrandner Feb 18, 2021
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
1 change: 1 addition & 0 deletions res/css/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
@import "./views/settings/_DevicesPanel.scss";
@import "./views/settings/_E2eAdvancedPanel.scss";
@import "./views/settings/_EmailAddresses.scss";
@import "./views/settings/_SpellCheckLanguages.scss";
@import "./views/settings/_IntegrationManager.scss";
@import "./views/settings/_Notifications.scss";
@import "./views/settings/_PhoneNumbers.scss";
Expand Down
36 changes: 36 additions & 0 deletions res/css/views/settings/_SpellCheckLanguages.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2019 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C.
SimonBrandner marked this conversation as resolved.
Show resolved Hide resolved

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

.mx_ExistingSpellCheckLanguage {
display: flex;
align-items: center;
margin-bottom: 5px;
}

.mx_ExistingSpellCheckLanguage_language {
flex: 1;
margin-right: 10px;
}

.mx_GeneralUserSettingsTab_spellCheckLanguageInput {
margin-top: 1em;
margin-bottom: 1em;
}

.mx_SpellCheckLanguages {
@mixin mx_Settings_fullWidthField;
}
110 changes: 110 additions & 0 deletions src/components/views/settings/SpellCheckSettings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
Copyright 2019 New Vector Ltd
SimonBrandner marked this conversation as resolved.
Show resolved Hide resolved

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React from 'react';
import LanguageDropdown from "../../../components/views/elements/LanguageDropdown";
import AccessibleButton from "../../../components/views/elements/AccessibleButton";
import {_t} from "../../../languageHandler";

interface ExistingSpellCheckLanguageIProps {
language: string,
onRemoved(language: string),
};

interface SpellCheckLanguagesIProps {
languages: Array<string>,
onLanguagesChange(languages: Array<string>),
};

interface SpellCheckLanguagesIState {
newLanguage: string,
}

export class ExistingSpellCheckLanguage extends React.Component<ExistingSpellCheckLanguageIProps> {
_onRemove = (e) => {
e.stopPropagation();
e.preventDefault();

return this.props.onRemoved(this.props.language);
};

render() {
return (
<div className="mx_ExistingSpellCheckLanguage">
<span className="mx_ExistingSpellCheckLanguage_language">{this.props.language}</span>
<AccessibleButton onClick={this._onRemove} kind="danger_sm">
{_t("Remove")}
</AccessibleButton>
</div>
);
}
}

export default class SpellCheckLanguages extends React.Component<SpellCheckLanguagesIProps, SpellCheckLanguagesIState> {
constructor(props) {
super(props);
this.state = {
newLanguage: "",
}
}

_onRemoved = (language) => {
const languages = this.props.languages.filter((e) => e !== language);
this.props.onLanguagesChange(languages);
};

_onAddClick = (e) => {
e.stopPropagation();
e.preventDefault();

const language = this.state.newLanguage;

if (!language) return;
if (this.props.languages.includes(language)) return;

this.props.languages.push(language)
this.props.onLanguagesChange(this.props.languages);
};

_onNewLanguageChange = (language: string) => {
if (this.state.newLanguage === language) return;
this.setState({newLanguage: language});
};

render() {
const existingSpellCheckLanguages = this.props.languages.map((e) => {
return <ExistingSpellCheckLanguage language={e} onRemoved={this._onRemoved} key={e} />;
});

let addButton = (
<AccessibleButton onClick={this._onAddClick} kind="primary">
{_t("Add")}
</AccessibleButton>
);

return (
<div className="mx_SpellCheckLanguages">
{existingSpellCheckLanguages}
<form onSubmit={this._onAddClick} noValidate={true}>
<LanguageDropdown className="mx_GeneralUserSettingsTab_spellCheckLanguageInput"
value={this.state.newLanguage}
onOptionChange={this._onNewLanguageChange} />
SimonBrandner marked this conversation as resolved.
Show resolved Hide resolved
{addButton}
</form>
</div>
);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import ProfileSettings from "../../ProfileSettings";
import * as languageHandler from "../../../../../languageHandler";
import SettingsStore from "../../../../../settings/SettingsStore";
import LanguageDropdown from "../../../elements/LanguageDropdown";
import SpellCheckSettings from "../../SpellCheckSettings"
import AccessibleButton from "../../../elements/AccessibleButton";
import DeactivateAccountDialog from "../../../dialogs/DeactivateAccountDialog";
import PropTypes from "prop-types";
Expand Down Expand Up @@ -49,6 +50,7 @@ export default class GeneralUserSettingsTab extends React.Component {

this.state = {
language: languageHandler.getCurrentLanguage(),
spellCheckLanguages: SettingsStore.getValue("spell-check-languages", null, false),
haveIdServer: Boolean(MatrixClientPeg.get().getIdentityServerUrl()),
serverSupportsSeparateAddAndBind: null,
idServerHasUnsignedTerms: false,
Expand Down Expand Up @@ -182,6 +184,12 @@ export default class GeneralUserSettingsTab extends React.Component {
PlatformPeg.get().reload();
};

_onSpellCheckLanguagesChange = (languages) => {
SettingsStore.setValue("spell-check-languages", null, SettingLevel.DEVICE, languages);
this.setState({spellCheckLanguages: languages})
PlatformPeg.get().reload();
};

_onPasswordChangeError = (err) => {
// TODO: Figure out a design that doesn't involve replacing the current dialog
let errMsg = err.error || "";
Expand Down Expand Up @@ -303,6 +311,16 @@ export default class GeneralUserSettingsTab extends React.Component {
);
}

_renderSpellCheckSection() {
return (
<div className="mx_SettingsTab_section">
<span className="mx_SettingsTab_subheading">{_t("Spell checking")}</span>
<SpellCheckSettings languages={this.state.spellCheckLanguages}
onLanguagesChange={this._onSpellCheckLanguagesChange} />
</div>
);
}

_renderDiscoverySection() {
const SetIdServer = sdk.getComponent("views.settings.SetIdServer");

Expand Down Expand Up @@ -409,6 +427,7 @@ export default class GeneralUserSettingsTab extends React.Component {
{this._renderProfileSection()}
{this._renderAccountSection()}
{this._renderLanguageSection()}
{this._renderSpellCheckSection()}
{ discoverySection }
{this._renderIntegrationManagerSection() /* Has its own title */}
{ accountManagementSection }
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,7 @@
"Use an Integration Manager to manage bots, widgets, and sticker packs.": "Use an Integration Manager to manage bots, widgets, and sticker packs.",
"Manage integrations": "Manage integrations",
"Integration Managers receive configuration data, and can modify widgets, send room invites, and set power levels on your behalf.": "Integration Managers receive configuration data, and can modify widgets, send room invites, and set power levels on your behalf.",
"Add": "Add",
"Error encountered (%(errorDetail)s).": "Error encountered (%(errorDetail)s).",
"Checking for an update...": "Checking for an update...",
"No update available.": "No update available.",
Expand Down Expand Up @@ -1148,6 +1149,7 @@
"Set a new account password...": "Set a new account password...",
"Account": "Account",
"Language and region": "Language and region",
"Spell checking": "Spell checking",
"Agree to the identity server (%(serverName)s) Terms of Service to allow yourself to be discoverable by email address or phone number.": "Agree to the identity server (%(serverName)s) Terms of Service to allow yourself to be discoverable by email address or phone number.",
"Account management": "Account management",
"Deactivating your account is a permanent action - be careful!": "Deactivating your account is a permanent action - be careful!",
Expand Down Expand Up @@ -1345,7 +1347,6 @@
"Invalid Email Address": "Invalid Email Address",
"This doesn't appear to be a valid email address": "This doesn't appear to be a valid email address",
"Unable to add email address": "Unable to add email address",
"Add": "Add",
"We've sent you an email to verify your address. Please follow the instructions there and then click the button below.": "We've sent you an email to verify your address. Please follow the instructions there and then click the button below.",
"Email Address": "Email Address",
"Remove %(phone)s?": "Remove %(phone)s?",
Expand Down
7 changes: 7 additions & 0 deletions src/languageHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,13 @@ export function setLanguage(preferredLangs: string | string[]) {
});
}

export function setSpellCheckLanguages(preferredLangs: string[]) {
SimonBrandner marked this conversation as resolved.
Show resolved Hide resolved
const plaf = PlatformPeg.get();
if (plaf) {
plaf.setLanguage(preferredLangs);
}
}

export function getAllLanguagesFromJson() {
return getLangsJson().then((langsObject) => {
const langs = [];
Expand Down
4 changes: 4 additions & 0 deletions src/settings/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ export const SETTINGS: {[setting: string]: ISetting} = {
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: "en",
},
"spell-check-languages": {
SimonBrandner marked this conversation as resolved.
Show resolved Hide resolved
supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG,
default: [],
},
"breadcrumb_rooms": {
// not really a setting
supportedLevels: [SettingLevel.ACCOUNT],
Expand Down