aboutsummaryrefslogtreecommitdiffstats
path: root/packages/shared
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-04-03 18:56:00 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-05-16 00:54:59 +0200
commit7a926c4b223c8be46a1defab4a86104d617eaaf9 (patch)
tree5e50a787397ff72268c22c6dffc67432dc76e184 /packages/shared
parentfix(main): Inconsistent RendererBridge snapshot (diff)
downloadsophie-7a926c4b223c8be46a1defab4a86104d617eaaf9.tar.gz
sophie-7a926c4b223c8be46a1defab4a86104d617eaaf9.tar.zst
sophie-7a926c4b223c8be46a1defab4a86104d617eaaf9.zip
refactor: Use i18next for language resolution
Due to https://github.com/i18next/i18next/issues/1564 we still have to implement our own language resolution, but we can rely on resolvedLanguage to determine which language to pass through to the renderer. We will use the language detected by chromium as the system locale, so there is no need to use os-locale for detection any more. We use i18next in the main process do resolve the language, then set the resolve (not requested!) language in the renderer process to avoid doing resolution twice. This avoids the need in the renderer process to know the list of supported languages. We set the language and the writing direction in HTML in the renderer. Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/shared')
-rw-r--r--packages/shared/src/index.ts2
-rw-r--r--packages/shared/src/stores/SharedStoreBase.ts2
-rw-r--r--packages/shared/src/stores/WritingDirection.ts32
3 files changed, 36 insertions, 0 deletions
diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts
index c4de885..95af73a 100644
--- a/packages/shared/src/index.ts
+++ b/packages/shared/src/index.ts
@@ -80,3 +80,5 @@ export {
80 defineSharedStoreModel, 80 defineSharedStoreModel,
81 FALLBACK_LOCALE, 81 FALLBACK_LOCALE,
82} from './stores/SharedStoreBase'; 82} from './stores/SharedStoreBase';
83
84export { default as WritingDirection } from './stores/WritingDirection';
diff --git a/packages/shared/src/stores/SharedStoreBase.ts b/packages/shared/src/stores/SharedStoreBase.ts
index a576a0e..bd71cea 100644
--- a/packages/shared/src/stores/SharedStoreBase.ts
+++ b/packages/shared/src/stores/SharedStoreBase.ts
@@ -30,6 +30,7 @@ import {
30import GlobalSettingsBase from './GlobalSettingsBase'; 30import GlobalSettingsBase from './GlobalSettingsBase';
31import ProfileBase from './Profile'; 31import ProfileBase from './Profile';
32import ServiceBase from './ServiceBase'; 32import ServiceBase from './ServiceBase';
33import WritingDirection from './WritingDirection';
33 34
34export const FALLBACK_LOCALE = 'en'; 35export const FALLBACK_LOCALE = 'en';
35 36
@@ -46,6 +47,7 @@ export function defineSharedStoreModel<
46 services: types.array(types.reference(service)), 47 services: types.array(types.reference(service)),
47 shouldUseDarkColors: false, 48 shouldUseDarkColors: false,
48 language: FALLBACK_LOCALE, 49 language: FALLBACK_LOCALE,
50 writingDirection: types.optional(WritingDirection, 'ltr'),
49 }); 51 });
50} 52}
51 53
diff --git a/packages/shared/src/stores/WritingDirection.ts b/packages/shared/src/stores/WritingDirection.ts
new file mode 100644
index 0000000..561a86b
--- /dev/null
+++ b/packages/shared/src/stores/WritingDirection.ts
@@ -0,0 +1,32 @@
1/*
2 * Copyright (C) 2022 Kristóf Marussy <kristof@marussy.com>
3 *
4 * This file is part of Sophie.
5 *
6 * Sophie is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * SPDX-License-Identifier: AGPL-3.0-only
19 */
20
21import { Instance, types } from 'mobx-state-tree';
22
23const WritingDirection = /* @__PURE__ */ (() =>
24 types.enumeration('WritingDirection', ['ltr', 'rtl']))();
25
26/*
27 eslint-disable-next-line @typescript-eslint/no-redeclare --
28 Intentionally naming the type the same as the store definition.
29*/
30type WritingDirection = Instance<typeof WritingDirection>;
31
32export default WritingDirection;