diff --git a/ACKNOWLEDGMENTS.md b/ACKNOWLEDGMENTS.md index ab977b836..e13704796 100644 --- a/ACKNOWLEDGMENTS.md +++ b/ACKNOWLEDGMENTS.md @@ -2431,18 +2431,6 @@ Signal Desktop makes use of the following open source projects. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -## os-locale - - MIT License - - Copyright (c) Sindre Sorhus (sindresorhus.com) - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ## p-map MIT License diff --git a/app/main.ts b/app/main.ts index c08111a94..13c03137e 100644 --- a/app/main.ts +++ b/app/main.ts @@ -536,7 +536,7 @@ async function createWindow() { } mainWindowCreated = true; - setupSpellChecker(mainWindow, getLocale().messages); + setupSpellChecker(mainWindow, getLocale()); if (!startInTray && windowConfig && windowConfig.maximized) { mainWindow.maximize(); } @@ -1129,7 +1129,7 @@ async function showStickerCreator() { }; stickerCreatorWindow = createBrowserWindow(options); - setupSpellChecker(stickerCreatorWindow, getLocale().messages); + setupSpellChecker(stickerCreatorWindow, getLocale()); handleCommonWindowEvents(stickerCreatorWindow); @@ -1386,6 +1386,17 @@ ipc.on('database-error', (_event: Electron.Event, error: string) => { onDatabaseError(error); }); +function getAppLocale(): string { + const { env } = process; + const envLocale = env.LC_ALL || env.LC_MESSAGES || env.LANG || env.LANGUAGE; + + if (envLocale) { + return envLocale.replace(/_/g, '-'); + } + + return getEnvironment() === Environment.Test ? 'en' : app.getLocale(); +} + // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. @@ -1396,8 +1407,7 @@ app.on('ready', async () => { logger = await logging.initialize(getMainWindow); if (!locale) { - const appLocale = - getEnvironment() === Environment.Test ? 'en' : app.getLocale(); + const appLocale = getAppLocale(); locale = loadLocale({ appLocale, logger }); } diff --git a/app/spell_check.ts b/app/spell_check.ts index af68fdc15..cb573fdd9 100644 --- a/app/spell_check.ts +++ b/app/spell_check.ts @@ -5,12 +5,11 @@ import type { BrowserWindow } from 'electron'; import { Menu, clipboard, nativeImage } from 'electron'; -import { sync as osLocaleSync } from 'os-locale'; import { uniq } from 'lodash'; import { fileURLToPath } from 'url'; import { maybeParseUrl } from '../ts/util/url'; -import type { LocaleMessagesType } from '../ts/types/I18N'; +import type { LocaleType } from './locale'; import type { MenuListType } from './menu'; @@ -35,10 +34,9 @@ export function getLanguages( export const setup = ( browserWindow: BrowserWindow, - messages: LocaleMessagesType + { name: userLocale, messages }: LocaleType ): void => { const { session } = browserWindow.webContents; - const userLocale = osLocaleSync().replace(/_/g, '-'); const availableLocales = session.availableSpellCheckerLanguages; const languages = getLanguages(userLocale, availableLocales); console.log(`spellcheck: user locale: ${userLocale}`); diff --git a/package.json b/package.json index 6c11246e8..84db7fc01 100644 --- a/package.json +++ b/package.json @@ -130,7 +130,6 @@ "node-fetch": "2.6.1", "node-forge": "0.10.0", "normalize-path": "3.0.0", - "os-locale": "3.0.1", "p-map": "2.1.0", "p-props": "4.0.0", "p-queue": "6.6.2", diff --git a/patches/os-locale+3.0.1.patch b/patches/os-locale+3.0.1.patch deleted file mode 100644 index 4d1e14b7f..000000000 --- a/patches/os-locale+3.0.1.patch +++ /dev/null @@ -1,46 +0,0 @@ -diff --git a/node_modules/os-locale/index.js b/node_modules/os-locale/index.js -index 6995b60..321e903 100644 ---- a/node_modules/os-locale/index.js -+++ b/node_modules/os-locale/index.js -@@ -25,11 +25,11 @@ function getLocale(string) { - } - - function getAppleLocale() { -- return execa.stdout('defaults', ['read', '-g', 'AppleLocale']); -+ return execa.stdout('defaults', ['read', '-g', 'AppleLocale'], { preferLocal: false }); - } - - function getAppleLocaleSync() { -- return execa.sync('defaults', ['read', '-g', 'AppleLocale']).stdout; -+ return execa.sync('defaults', ['read', '-g', 'AppleLocale'], { preferLocal: false }).stdout; - } - - function getUnixLocale() { -@@ -37,7 +37,8 @@ function getUnixLocale() { - return getAppleLocale(); - } - -- return execa.stdout('locale') -+ const args = null; -+ return execa.stdout('locale', args, { preferLocal: false }) - .then(stdout => getLocale(parseLocale(stdout))); - } - -@@ -50,7 +51,7 @@ function getUnixLocaleSync() { - } - - function getWinLocale() { -- return execa.stdout('wmic', ['os', 'get', 'locale']) -+ return execa.stdout('wmic', ['os', 'get', 'locale'], { preferLocal: false }) - .then(stdout => { - const lcidCode = parseInt(stdout.replace('Locale', ''), 16); - return lcid.from(lcidCode); -@@ -58,7 +59,7 @@ function getWinLocale() { - } - - function getWinLocaleSync() { -- const {stdout} = execa.sync('wmic', ['os', 'get', 'locale']); -+ const {stdout} = execa.sync('wmic', ['os', 'get', 'locale'], { preferLocal: false }); - const lcidCode = parseInt(stdout.replace('Locale', ''), 16); - return lcid.from(lcidCode); - } diff --git a/yarn.lock b/yarn.lock index 3229f9b09..5ac04cd0d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6634,19 +6634,6 @@ evp_bytestokey@^1.0.0, evp_bytestokey@^1.0.3: md5.js "^1.3.4" safe-buffer "^5.1.1" -execa@^0.10.0: - version "0.10.0" - resolved "https://registry.yarnpkg.com/execa/-/execa-0.10.0.tgz#ff456a8f53f90f8eccc71a96d11bdfc7f082cb50" - integrity sha512-7XOMnz8Ynx1gGo/3hyV9loYNPWM94jG3+3T3Y8tsfSstFmETmENCMU/A/zj8Lyaj1lkgEepKepvd6240tBRvlw== - dependencies: - cross-spawn "^6.0.0" - get-stream "^3.0.0" - is-stream "^1.1.0" - npm-run-path "^2.0.0" - p-finally "^1.0.0" - signal-exit "^3.0.0" - strip-eof "^1.0.0" - execa@^0.7.0: version "0.7.0" resolved "https://registry.yarnpkg.com/execa/-/execa-0.7.0.tgz#944becd34cc41ee32a63a9faf27ad5a65fc59777" @@ -8527,11 +8514,6 @@ invert-kv@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-1.0.0.tgz#104a8e4aaca6d3d8cd157a8ef8bfab2d7a3ffdb6" -invert-kv@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-2.0.0.tgz#7393f5afa59ec9ff5f67a27620d11c226e3eec02" - integrity sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA== - ip-regex@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-2.1.0.tgz#fa78bf5d2e6913c911ce9f819ee5146bb6d844e9" @@ -9407,13 +9389,6 @@ lcid@^1.0.0: dependencies: invert-kv "^1.0.0" -lcid@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/lcid/-/lcid-2.0.0.tgz#6ef5d2df60e52f82eb228a4c373e8d1f397253cf" - integrity sha512-avPEb8P8EGnwXKClwsNUgryVjllcRqtMYa49NTsbQagYuT1DcXnl1915oxWjoyGrXR6zH/Y0Zc96xWsPcoDKeA== - dependencies: - invert-kv "^2.0.0" - levn@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/levn/-/levn-0.4.1.tgz#ae4562c007473b932a6200d403268dd2fffc6ade" @@ -9690,13 +9665,6 @@ mamacro@^0.0.3: resolved "https://registry.yarnpkg.com/mamacro/-/mamacro-0.0.3.tgz#ad2c9576197c9f1abf308d0787865bd975a3f3e4" integrity sha512-qMEwh+UujcQ+kbz3T6V+wAmO2U8veoq2w+3wY8MquqwVA3jChfwY+Tk52GZKDfACEPjuZ7r2oJLejwpt8jtwTA== -map-age-cleaner@^0.1.1: - version "0.1.3" - resolved "https://registry.yarnpkg.com/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz#7d583a7306434c055fe474b0f45078e6e1b4b92a" - integrity sha512-bJzx6nMoP6PDLPBFmg7+xRKeFZvFboMrGlxmNj9ClvX53KrmvM5bXFXEWjbz4cz1AFn+jWJ9z/DJSz7hrs0w3w== - dependencies: - p-defer "^1.0.0" - map-cache@^0.2.2: version "0.2.2" resolved "https://registry.yarnpkg.com/map-cache/-/map-cache-0.2.2.tgz#c32abd0bd6525d9b051645bb4f26ac5dc98a0dbf" @@ -9778,15 +9746,6 @@ mem@^1.1.0: dependencies: mimic-fn "^1.0.0" -mem@^4.0.0: - version "4.3.0" - resolved "https://registry.yarnpkg.com/mem/-/mem-4.3.0.tgz#461af497bc4ae09608cdb2e60eefb69bff744178" - integrity sha512-qX2bG48pTqYRVmDB37rn/6PT7LcR8T7oAX3bf99u1Tt1nzxYfxkgqDwUwolPlXweM0XzBOBFzSx4kfp7KP1s/w== - dependencies: - map-age-cleaner "^0.1.1" - mimic-fn "^2.0.0" - p-is-promise "^2.0.0" - memoize-one@^5.0.0: version "5.0.5" resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-5.0.5.tgz#8cd3809555723a07684afafcd6f756072ac75d7e" @@ -9960,7 +9919,7 @@ mimic-fn@^1.0.0: resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022" integrity sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ== -mimic-fn@^2.0.0, mimic-fn@^2.1.0: +mimic-fn@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg== @@ -10875,15 +10834,6 @@ os-homedir@1.0.2, os-homedir@^1.0.0, os-homedir@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3" -os-locale@3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/os-locale/-/os-locale-3.0.1.tgz#3b014fbf01d87f60a1e5348d80fe870dc82c4620" - integrity sha512-7g5e7dmXPtzcP4bgsZ8ixDVqA7oWYuEz4lOSujeWyliPai4gfVDiFIcwBg3aGCPnmSGfzOKTK3ccPn0CKv3DBw== - dependencies: - execa "^0.10.0" - lcid "^2.0.0" - mem "^4.0.0" - os-locale@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/os-locale/-/os-locale-2.1.0.tgz#42bc2900a6b5b8bd17376c8e882b65afccf24bf2" @@ -10914,11 +10864,6 @@ p-cancelable@^2.0.0: resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-2.1.1.tgz#aab7fbd416582fa32a3db49859c122487c5ed2cf" integrity sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg== -p-defer@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/p-defer/-/p-defer-1.0.0.tgz#9f6eb182f6c9aa8cd743004a7d4f96b196b0fb0c" - integrity sha1-n26xgvbJqozXQwBKfU+WsZaw+ww= - p-finally@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae" @@ -10928,11 +10873,6 @@ p-finally@^2.0.0: resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-2.0.1.tgz#bd6fcaa9c559a096b680806f4d657b3f0f240561" integrity sha512-vpm09aKwq6H9phqRQzecoDpD8TmVyGw70qmWlyq5onxY7tqyTTFVvxMykxQSQKILBSFlbXpypIw2T1Ml7+DDtw== -p-is-promise@^2.0.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/p-is-promise/-/p-is-promise-2.1.0.tgz#918cebaea248a62cf7ffab8e3bca8c5f882fc42e" - integrity sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg== - p-limit@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.1.0.tgz#b07ff2d9a5d88bec806035895a2bab66a27988bc"