diff --git a/package-lock.json b/package-lock.json index 61176af4..30575e8b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,8 +13,8 @@ "dictionary-ca": "2.6.0", "dictionary-ca-valencia": "2.6.0", "dictionary-de": "2.0.4", + "dictionary-en": "3.2.0", "dictionary-en-gb": "2.4.0", - "dictionary-en-us": "3.0.0", "dictionary-es": "3.2.0", "dictionary-eu": "3.2.0", "dictionary-fr": "2.8.0", @@ -3597,6 +3597,15 @@ "url": "https://github.com/sponsors/wooorm" } }, + "node_modules/dictionary-en": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/dictionary-en/-/dictionary-en-3.2.0.tgz", + "integrity": "sha512-oujbJhuplUTlDntmOoultEcNyk8ge7cFI6yXNn7eJvpbBJOhGNhWtK0XjOJsiwl4EfIeyvDKwGB95vJXv1d+lQ==", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/wooorm" + } + }, "node_modules/dictionary-en-gb": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/dictionary-en-gb/-/dictionary-en-gb-2.4.0.tgz", @@ -3606,12 +3615,6 @@ "url": "https://github.com/sponsors/wooorm" } }, - "node_modules/dictionary-en-us": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/dictionary-en-us/-/dictionary-en-us-3.0.0.tgz", - "integrity": "sha512-hH033rB5pdVb51QBUBleq8z5XajVrs2tVRe26ZvIJzf5/c8BwZKlPXhr7rrW39AxZz5RQQhPpC/RMbmWtWtBUg==", - "deprecated": "Deprecated: use dictionary-en instead for English as spoken in the United States" - }, "node_modules/dictionary-es": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/dictionary-es/-/dictionary-es-3.2.0.tgz", @@ -12135,16 +12138,16 @@ "resolved": "https://registry.npmjs.org/dictionary-de/-/dictionary-de-2.0.4.tgz", "integrity": "sha512-TOTvLM7k4wJt3cgus1Ziuiqo5Tx0i+VEmXVDCDxsxHhRdSCnAQFonTx8/YlfGI+AQQIyMJhXfMnceKD56dZrMQ==" }, + "dictionary-en": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/dictionary-en/-/dictionary-en-3.2.0.tgz", + "integrity": "sha512-oujbJhuplUTlDntmOoultEcNyk8ge7cFI6yXNn7eJvpbBJOhGNhWtK0XjOJsiwl4EfIeyvDKwGB95vJXv1d+lQ==" + }, "dictionary-en-gb": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/dictionary-en-gb/-/dictionary-en-gb-2.4.0.tgz", "integrity": "sha512-zwc7e6CM/+Em+v74a5/ia6663nwR9vvtEayaX5WkgvHD99al1qm/RbcdLludqX3mggYxXXFN1zN5hzyREW/DXg==" }, - "dictionary-en-us": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/dictionary-en-us/-/dictionary-en-us-3.0.0.tgz", - "integrity": "sha512-hH033rB5pdVb51QBUBleq8z5XajVrs2tVRe26ZvIJzf5/c8BwZKlPXhr7rrW39AxZz5RQQhPpC/RMbmWtWtBUg==" - }, "dictionary-es": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/dictionary-es/-/dictionary-es-3.2.0.tgz", diff --git a/package.json b/package.json index bbb5c8bc..b72ed699 100644 --- a/package.json +++ b/package.json @@ -207,7 +207,7 @@ "dictionary-ca-valencia": "2.6.0", "dictionary-de": "2.0.4", "dictionary-en-gb": "2.4.0", - "dictionary-en-us": "3.0.0", + "dictionary-en": "3.2.0", "dictionary-es": "3.2.0", "dictionary-eu": "3.2.0", "dictionary-fr": "2.8.0", diff --git a/src/settings/__tests__/index.test.js b/src/settings/__tests__/index.test.js index 561245eb..cde5d7e9 100644 --- a/src/settings/__tests__/index.test.js +++ b/src/settings/__tests__/index.test.js @@ -43,7 +43,7 @@ describe('Settings module test suite', () => { expectHomeDirectoryCreated(); expect(fs.readFileSync).toHaveBeenCalledTimes(1); expect(result.tabs).toEqual([]); - expect(result.enabledDictionaries).toEqual(['en-US']); + expect(result.enabledDictionaries).toEqual(['en']); expect(result.theme).toEqual('system'); }); test('settings (empty) exist, should load settings from file system and merge with defaults', () => { @@ -56,7 +56,7 @@ describe('Settings module test suite', () => { expectHomeDirectoryCreated(); expect(fs.readFileSync).toHaveBeenCalledWith(path.join('$HOME', '.electronim', 'settings.json')); expect(result.tabs).toEqual([]); - expect(result.enabledDictionaries).toEqual(['en-US']); + expect(result.enabledDictionaries).toEqual(['en']); expect(result.theme).toEqual('system'); expect(result.trayEnabled).toEqual(false); }); @@ -70,7 +70,7 @@ describe('Settings module test suite', () => { expectHomeDirectoryCreated(); expect(fs.readFileSync).toHaveBeenCalledWith(path.join('$HOME', '.electronim', 'settings.json')); expect(result.tabs).toEqual([{id: '1'}]); - expect(result.enabledDictionaries).toEqual(['en-US']); + expect(result.enabledDictionaries).toEqual(['en']); expect(result.activeTab).toBe('1'); expect(result.otherSetting).toBe(1337); }); @@ -84,6 +84,19 @@ describe('Settings module test suite', () => { expect(result.tabs).toEqual([{id: '1', disabled: true}, {id: '2'}]); expect(result.activeTab).toBe('2'); }); + test.each([ + {enabledDictionaries: ['en-US', 'es'], expected: ['es', 'en']}, + {enabledDictionaries: ['en-US', 'en', 'es'], expected: ['es', 'en']}, + {enabledDictionaries: ['en-GB', 'en'], expected: ['en-GB', 'en']} + ])('settings with $enabledDictionaries dictionary, should migrate to $expected', ({enabledDictionaries, expected}) => { + // Given + fs.existsSync.mockImplementationOnce(() => true); + fs.readFileSync.mockImplementationOnce(() => JSON.stringify({enabledDictionaries})); + // When + const result = settings.loadSettings(); + // Then + expect(result.enabledDictionaries).toEqual(expected); + }); test.each([ {key: 'theme', value: '"light"', expected: 'light'}, {key: 'activeTab', value: 42, expected: 42}, @@ -110,7 +123,7 @@ describe('Settings module test suite', () => { expect(fs.writeFileSync).toHaveBeenCalledWith(path.join('$HOME', '.electronim', 'settings.json'), '{\n "tabs": [],\n' + ' "useNativeSpellChecker": false,\n' + - ' "enabledDictionaries": [\n "en-US"\n ],\n' + + ' "enabledDictionaries": [\n "en"\n ],\n' + ' "theme": "system",\n "trayEnabled": false,\n' + ' "closeButtonBehavior": "quit"\n' + '}'); @@ -124,7 +137,7 @@ describe('Settings module test suite', () => { expect(fs.writeFileSync).toHaveBeenCalledWith(path.join('$HOME', '.electronim', 'settings.json'), '{\n "tabs": [\n {\n "id": 1337\n }\n ],\n' + ' "useNativeSpellChecker": false,\n' + - ' "enabledDictionaries": [\n "en-US"\n ],\n' + + ' "enabledDictionaries": [\n "en"\n ],\n' + ' "theme": "system",\n' + ' "trayEnabled": false,\n' + ' "closeButtonBehavior": "quit",\n' + @@ -141,7 +154,7 @@ describe('Settings module test suite', () => { expect(fs.writeFileSync).toHaveBeenCalledWith(path.join('$HOME', '.electronim', 'settings.json'), '{\n "tabs": [\n {\n "id": 1337\n }\n ],\n' + ' "useNativeSpellChecker": false,\n' + - ' "enabledDictionaries": [\n "en-US"\n ],\n' + + ' "enabledDictionaries": [\n "en"\n ],\n' + ' "theme": "system",\n' + ' "trayEnabled": false,\n' + ' "closeButtonBehavior": "quit",\n' + diff --git a/src/settings/index.js b/src/settings/index.js index 57cb64f7..309496cd 100644 --- a/src/settings/index.js +++ b/src/settings/index.js @@ -25,7 +25,7 @@ const SETTINGS_FILE = 'settings.json'; const DEFAULT_SETTINGS = { tabs: [], useNativeSpellChecker: false, - enabledDictionaries: ['en-US'], + enabledDictionaries: ['en'], theme: 'system', trayEnabled: false, closeButtonBehavior: CLOSE_BUTTON_BEHAVIORS.quit @@ -62,6 +62,17 @@ const ensureDefaultValues = settings => { return {...settings, activeTab}; }; +const migrate = settings => { + // en-us dictionary key is now en + if (settings.enabledDictionaries.includes('en-US')) { + settings.enabledDictionaries = settings.enabledDictionaries + .filter(dictionary => dictionary !== 'en-US') + .filter(dictionary => dictionary !== 'en') + .concat('en'); + } + return settings; +}; + const initAppDir = () => fs.mkdirSync(appDir, {recursive: true}); const loadSettings = () => { @@ -70,7 +81,7 @@ const loadSettings = () => { if (fs.existsSync(settingsPath)) { loadedSettings = JSON.parse(fs.readFileSync(settingsPath)); } - return ensureDefaultValues(loadedSettings); + return migrate(ensureDefaultValues(loadedSettings)); }; const writeSettings = settings => { diff --git a/src/spell-check/index.js b/src/spell-check/index.js index 45f82649..ea65c159 100644 --- a/src/spell-check/index.js +++ b/src/spell-check/index.js @@ -30,7 +30,7 @@ const AVAILABLE_DICTIONARIES = { 'en-GB': { name: 'English (GB)' }, - 'en-US': { + en: { name: 'English (US)' }, es: {