From f566e5ff9af0bbcfedcff7581721f75f0bdd9fdc Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Wed, 25 Oct 2017 18:47:33 -0700 Subject: [PATCH 1/4] Spellcheck language settings (enable/disable & dictionary languages) fix #2183 Auditors: @bbondy, @bsclifton --- app/browser/reducers/spellCheckerReducer.js | 23 +++ app/extensions/brave/about-preferences.html | 1 + app/extensions/brave/index-dev.html | 2 + app/extensions/brave/index.html | 2 + .../brave/locales/en-US/locales.properties | 26 +++ .../locales/en-US/preferences.properties | 29 +--- app/locale.js | 23 +-- js/about/preferences.js | 34 +++- js/constants/appConfig.js | 2 + js/constants/settings.js | 2 + package-lock.json | 19 +++ package.json | 1 + .../reducers/spellCheckerReducerTest.js | 153 +++++++++++++++++- 13 files changed, 277 insertions(+), 40 deletions(-) create mode 100644 app/extensions/brave/locales/en-US/locales.properties diff --git a/app/browser/reducers/spellCheckerReducer.js b/app/browser/reducers/spellCheckerReducer.js index e811500e3f2..5fdfd47938a 100644 --- a/app/browser/reducers/spellCheckerReducer.js +++ b/app/browser/reducers/spellCheckerReducer.js @@ -8,6 +8,9 @@ const appConstants = require('../../../js/constants/appConstants') const {makeImmutable} = require('../../common/state/immutableUtil') const {getWebContents} = require('../webContentsCache') const spellChecker = require('../../spellChecker') +const settings = require('../../../js/constants/settings') +const {setUserPref} = require('../../../js/state/userPrefs') +const getSetting = require('../../../js/settings').getSetting const migrate = (state) => { if (state.get('dictionary')) { @@ -28,12 +31,32 @@ const migrate = (state) => { return state } +const setSpellCheckerSettings = () => { + const enabled = getSetting(settings.SPELLCHECK_ENABLED) + setUserPref('browser.enable_spellchecking', enabled) + if (enabled) { + setUserPref('spellcheck.dictionaries', + getSetting(settings.SPELLCHECK_LANGUAGES)) + } +} + const spellCheckerReducer = (state, action, immutableAction) => { action = immutableAction || makeImmutable(action) switch (action.get('actionType')) { case appConstants.APP_SET_STATE: state = migrate(state) break + // TODO(darkdh): APP_SET_STATE is too early for startup setting so we use + // APP_WINDOW_CREATED here + case appConstants.APP_WINDOW_CREATED: + setSpellCheckerSettings() + break + case appConstants.APP_CHANGE_SETTING: + if ([settings.SPELLCHECK_ENABLED, settings.SPELLCHECK_LANGUAGES] + .includes(action.get('key'))) { + setSpellCheckerSettings() + } + break case appConstants.APP_SPELLING_SUGGESTED: if (typeof action.get('suggestion') === 'string') { const webContents = getWebContents(action.get('tabId')) diff --git a/app/extensions/brave/about-preferences.html b/app/extensions/brave/about-preferences.html index 992e4841495..317f01b5e13 100644 --- a/app/extensions/brave/about-preferences.html +++ b/app/extensions/brave/about-preferences.html @@ -19,6 +19,7 @@ +
diff --git a/app/extensions/brave/index-dev.html b/app/extensions/brave/index-dev.html index 0b8496dc191..17dff0c9e3e 100644 --- a/app/extensions/brave/index-dev.html +++ b/app/extensions/brave/index-dev.html @@ -19,6 +19,8 @@ + +
diff --git a/app/extensions/brave/index.html b/app/extensions/brave/index.html index bc3b4dec0f8..eba8b9b80a8 100644 --- a/app/extensions/brave/index.html +++ b/app/extensions/brave/index.html @@ -19,6 +19,8 @@ + +
diff --git a/app/extensions/brave/locales/en-US/locales.properties b/app/extensions/brave/locales/en-US/locales.properties new file mode 100644 index 00000000000..183b3228927 --- /dev/null +++ b/app/extensions/brave/locales/en-US/locales.properties @@ -0,0 +1,26 @@ +bn-BD=Bengali (Bangladesh) +bn-IN=Bengali (India) +cs=Czech +de-DE=German (Germany) +en-GB=English (U.K.) +en-US=English (U.S.) +es=Spanish +eu=Basque +fr-FR=French (France) +hi-IN=Hindi (India) +id-ID=Indonesian (Indonesia) +it-IT=Italian +ja-JP=Japanese (Japan) +ko-KR=Korean +ms-MY=Malay (Malaysia) +nl-NL=Dutch (Netherlands) +pl-PL=Polish +pt-BR=Portuguese (Brazil) +ru=Russian +sl=Slovenian +sv-SE=Swedish (Sweden) +ta=Tamil +te=Telugu +tr-TR=Turkish (Turkey) +uk=Ukrainian +zh-CN=Simplified Chinese (China) diff --git a/app/extensions/brave/locales/en-US/preferences.properties b/app/extensions/brave/locales/en-US/preferences.properties index 4b9ba6e8743..03a1a7a6de6 100644 --- a/app/extensions/brave/locales/en-US/preferences.properties +++ b/app/extensions/brave/locales/en-US/preferences.properties @@ -54,9 +54,6 @@ bitcoinBalance=Please transfer:  bitwarden=bitwarden® blockAttackSites=Block reported attack sites (not available yet) blockedCountBadge=Display block count badge on shields button -bn-BD=Bengali (Bangladesh) -bn-BD=Bengali (Bangladesh) -bn-IN=Bengali (India) bookmarksBarFaviconOnly=Favicons only bookmarksBarTextAndFavicon=Text and Favicons bookmarksBarTextOnly=Text only @@ -96,12 +93,10 @@ createWallet=create wallet createWalletStatus=Click the Create Wallet button to get started. creatingWallet=creating… creatingWalletStatus=Creating wallet… -cs=Czech dashboardSettingsTitle=Dashboard dashboardShowImages=Show images dashlane=Dashlane® (requires application) date=Date -de-DE=German (Germany) default=Default default=Default defaultBrowser=Brave is your default browser. @@ -121,8 +116,7 @@ downloadsAskAlwaysSwitch=Always ask me where to save files downloadsInput=~/downloads/ downloadsLabel=Save my downloads here: emailAddress=Email address -en-GB=English (U.K.) -en-US=English (U.S.) +enableSpellCheck=Enable Spell Check * enableAutofill=Enable Autofill enableFlash=Enable Adobe Flash support enableFlashSubtext=Brave uses a special version of Pepper Flash which must be installed from @@ -134,36 +128,28 @@ enableWidevine=Enable Google Widevine support engineGoKey=Engine Go Key (Type First) engineGoKey=Engine Go Key (type first) enpass=Enpass® (requires application) -es=Spanish -eu=Basque extensions=Extensions firstKey=Key 1 firstRecoveryKey=Recovery Key 1 flash=Run Adobe Flash Player flashAllowAlways=Allow until {{time}} flashTroubleshooting=Flash not working? Try the troubleshooting tips on our -fr-FR=French (France) fullscreenContent=Full Screen Content fullscreenPermission=Fullscreen access general=General generalSettings=General Settings geolocationPermission=Location access -hi-IN=Hindi (India) hideExcluded=Show only included sites hint0=The site shields panel allows you to turn HTTPS Everywhere on or off. HTTPS Everywhere automatically changes your HTTP traffic to HTTPS for supported sites to keep you more secure. hint1=Brave will always auto-update for you, but you can check for an update on demand in the menu. hint2=The File menu allows you to create a New Session Tab. Session tabs are like any other tab but they run in a different user profile. This allows you to login to the same sites multiple times with the same browser. hintsTitle=Helpful hints -id-ID=Indonesian (Indonesia) importBrowserData=Import Browser Data importButton=Import now… importLabel=Browser data import: importNow=Import now… include=Include insufficientFundsStatus=Your account balance is under your budget for this month. Please add funds. -it-IT=Italian -ja-JP=Japanese (Japan) -ko-KR=Korean lastContribution=Last contribution: lastPass=LastPass® ledgerBackupText1=Below, you will find the anonymized recovery key that is required if you ever lose access to this computer. @@ -199,7 +185,6 @@ minimumVisitsLow=1 visit minimumVisitsMedium=5 visits minimumVisitsSetting=Minimum visits for publisher relevancy monthlyBudget=monthly budget -ms-MY=Malay (Malaysia) multipleHomePages.title=Multiple home pages myHomepage=My home page is newTabBlank=blank @@ -209,7 +194,6 @@ newTabHomePage=Home page newTabMode=A new tab shows newTabNewTabPage=Dashboard nextContribution=Next contribution: -nl-NL=Dutch (Netherlands) nonVerifiedPublishers=Allow contributions to non-verified sites noPaymentHistory=No previous contributions normal=Normal @@ -252,7 +236,6 @@ paymentsWelcomeTitle=Welcome to Brave Payments! pendingFundsStatus=Pending funds: {{funds}}. Newly-added funds may take 30+ minutes to appear. percentage=% percentPaid=Percentage -pl-PL=Polish plugins=Plugins pluginSettings=Plugin Settings pointerLockPermission=Disable your mouse cursor @@ -262,7 +245,6 @@ privacy=Privacy privateData=Private Data privateDataMessage=Clear the following data types when I close Brave protocolRegistrationPermission=Protocol registration -pt-BR=Portuguese (Brazil) publisher=Site publishers=Publishers rank=Rank @@ -273,7 +255,6 @@ recoveryKey=Recovery Key recoverLedger=Recover your wallet remove=Remove requiresRestart=* Requires browser restart -ru=Russian savedSiteSettings=Saved site settings and permissions saveRecoveryFile=Save recovery file… scaleSizeLarger=Larger @@ -309,7 +290,7 @@ showTopsiteSuggestions=Show top site suggestions site=Site sitePermissions=Saved Site Permissions sitePermissionsExceptions=Saved Site Exceptions -sl=Slovenian +spellCheckLanguages=Spell Check Languages * startsWith=Brave starts with startsWithOptionHomePage=Home page startsWithOptionLastTime=My windows / tabs from last time @@ -320,7 +301,6 @@ statusNextReconcileOverdue=Overdue statusNextReconcileToday=Today statusOnError=Brave Wallet can't be reached. submitFeedback=Submit Feedback… -sv-SE=Swedish (Sweden) swipeNavigationDistance=Swipe Navigation Distance switchToNewTabs=Switch to new tabs immediately sync=Sync @@ -359,7 +339,6 @@ syncSiteSettings=Saved site settings syncStart=I am new to Sync syncTitle=Brave Sync syncTitleMessage=Sync encrypted browser data between your devices securely and privately using Brave Sync. -ta=Tamil tabCloseAction=When closing an active tab: tabCloseActionLastActive=Select the last viewed tab tabCloseActionNext=Select the next tab @@ -370,12 +349,9 @@ tabs=Tabs tabSettings=Tab Settings tabsPerTabPage=Number of tabs per tab set: tabsSettings=Tabs Settings -te=Telugu timeSpent=Time Spent toolbarUserInterfaceScale=Toolbar and UI elements scale totalAmount=Total Amount -tr-TR=Turkish (Turkey) -uk=Ukrainian update=Update updateToPreviewReleases=Update to preview releases * urlBarOptions=URL Bar Options @@ -391,4 +367,3 @@ visits=Visits wideURLbar=Use wide URL bar widevine=Run Google Widevine widevineSection=Google Widevine Support -zh-CN=Chinese diff --git a/app/locale.js b/app/locale.js index 74a8232d2a2..18c36da7e58 100644 --- a/app/locale.js +++ b/app/locale.js @@ -268,8 +268,9 @@ var rendererIdentifiers = function () { 'autoplayMedia', // Release channels 'channelDev', - 'channelBeta' - ].concat(countryCodes) + 'channelBeta', + 'spellCheckLanguages' + ].concat(countryCodes).concat(availableLanguages) } var ctx = null @@ -302,32 +303,32 @@ exports.translation = function (token, replacements = {}) { const DEFAULT_LANGUAGE = 'en-US' const availableLanguages = [ - 'eu', 'bn-BD', 'bn-IN', - 'zh-CN', 'cs', - 'nl-NL', - 'en-US', + 'de-DE', 'en-GB', + 'en-US', + 'es', + 'eu', 'fr-FR', - 'de-DE', 'hi-IN', 'id-ID', 'it-IT', 'ja-JP', 'ko-KR', 'ms-MY', + 'nl-NL', 'pl-PL', 'pt-BR', 'ru', 'sl', 'sv-SE', - 'es', 'ta', 'te', 'tr-TR', - 'uk' + 'uk', + 'zh-CN' ] // Currently configured languages @@ -394,7 +395,9 @@ exports.init = function (language) { path.join(__dirname, 'extensions', 'brave', 'locales', lang, 'error.properties'), path.join(__dirname, 'extensions', 'brave', 'locales', lang, 'passwords.properties'), path.join(__dirname, 'extensions', 'brave', 'locales', lang, 'common.properties'), - path.join(__dirname, 'extensions', 'brave', 'locales', lang, 'countries.properties') + path.join(__dirname, 'extensions', 'brave', 'locales', lang, 'countries.properties'), + path.join(__dirname, 'extensions', 'brave', 'locales', lang, 'locales.properties'), + path.join(__dirname, 'extensions', 'brave', 'locales', lang, 'preferences.properties') ) } diff --git a/js/about/preferences.js b/js/about/preferences.js index 725cfac18cf..17a7b0457d0 100644 --- a/js/about/preferences.js +++ b/js/about/preferences.js @@ -6,9 +6,13 @@ const React = require('react') const ImmutableComponent = require('../../app/renderer/components/immutableComponent') const Immutable = require('immutable') +const Select = require('react-select') const {StyleSheet, css} = require('aphrodite/no-important') const globalStyles = require('../../app/renderer/components/styles/global') const commonStyles = require('../../app/renderer/components/styles/commonStyles') +const locale = require('../../js/l10n') +// TODO(cezaraugusto): replace this with our own style +import 'react-select/dist/react-select.css' // Components const PreferenceNavigation = require('../../app/renderer/components/preferences/preferenceNavigation') @@ -100,6 +104,7 @@ class GeneralTab extends ImmutableComponent { this.importBrowserDataNow = this.importBrowserDataNow.bind(this) this.onChangeSetting = this.onChangeSetting.bind(this) this.setAsDefaultBrowser = this.setAsDefaultBrowser.bind(this) + this.onSpellCheckLangsChange = this.onSpellCheckLangsChange.bind(this) } importBrowserDataNow () { @@ -117,6 +122,10 @@ class GeneralTab extends ImmutableComponent { this.props.onChangeSetting(key, value) } + onSpellCheckLangsChange (value) { + this.props.onChangeSetting(settings.SPELLCHECK_LANGUAGES, value.split(',')) + } + setAsDefaultBrowser () { aboutActions.setAsDefaultBrowser() } @@ -136,6 +145,12 @@ class GeneralTab extends ImmutableComponent { ) }) + const spellCheckLangOptions = this.props.languageCodes.map(function (lc) { + return ( + { value: lc, label: locale.translation(lc) } + ) + }) + const homepage = getSetting(settings.HOMEPAGE, this.props.settings) const disableShowHomeButton = !homepage || !homepage.length const defaultLanguage = this.props.languageCodes.find((lang) => lang.includes(navigator.language)) || 'en-US' @@ -148,6 +163,18 @@ class GeneralTab extends ImmutableComponent { onClick={this.setAsDefaultBrowser} /> + const spellCheckLanguages = getSetting(settings.SPELLCHECK_ENABLED, this.props.settings) + ? +