diff options
author | 2022-03-30 01:36:22 +0200 | |
---|---|---|
committer | 2022-05-16 00:54:57 +0200 | |
commit | 7af01713180066b6dc1061dae930840e48c60fec (patch) | |
tree | 604a52eb8f167caf3400dad7589aaa5be2d06c8d /packages/main/src/infrastructure/config | |
parent | feat: Add custom menubar (diff) | |
download | sophie-7af01713180066b6dc1061dae930840e48c60fec.tar.gz sophie-7af01713180066b6dc1061dae930840e48c60fec.tar.zst sophie-7af01713180066b6dc1061dae930840e48c60fec.zip |
feat(main): Add localization support
Add i18next with a custom backend to the main process to load
localization from file.
Missing localizations are written to a missing localizations file in
debug mode, but silently fall back in production mode.
We will also need to add a custom backend for the renderer process that
communicates with the main process.
(i18next-fs-electron-backend is not applicable here, because we need
localizations both in the main and renderer processes.)
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/main/src/infrastructure/config')
-rw-r--r-- | packages/main/src/infrastructure/config/impl/ConfigFile.ts | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/packages/main/src/infrastructure/config/impl/ConfigFile.ts b/packages/main/src/infrastructure/config/impl/ConfigFile.ts index e8237b4..4ad0fcc 100644 --- a/packages/main/src/infrastructure/config/impl/ConfigFile.ts +++ b/packages/main/src/infrastructure/config/impl/ConfigFile.ts | |||
@@ -27,6 +27,7 @@ import { throttle } from 'lodash-es'; | |||
27 | 27 | ||
28 | import type Config from '../../../stores/config/Config'; | 28 | import type Config from '../../../stores/config/Config'; |
29 | import type Disposer from '../../../utils/Disposer'; | 29 | import type Disposer from '../../../utils/Disposer'; |
30 | import isErrno from '../../../utils/isErrno'; | ||
30 | import { getLogger } from '../../../utils/log'; | 31 | import { getLogger } from '../../../utils/log'; |
31 | import type ConfigRepository from '../ConfigRepository'; | 32 | import type ConfigRepository from '../ConfigRepository'; |
32 | import type { ReadConfigResult } from '../ConfigRepository'; | 33 | import type { ReadConfigResult } from '../ConfigRepository'; |
@@ -55,7 +56,7 @@ export default class ConfigFile implements ConfigRepository { | |||
55 | try { | 56 | try { |
56 | configStr = await readFile(this.#configFilePath, 'utf8'); | 57 | configStr = await readFile(this.#configFilePath, 'utf8'); |
57 | } catch (error) { | 58 | } catch (error) { |
58 | if ((error as NodeJS.ErrnoException).code === 'ENOENT') { | 59 | if (isErrno(error, 'ENOENT')) { |
59 | log.debug('Config file', this.#configFilePath, 'was not found'); | 60 | log.debug('Config file', this.#configFilePath, 'was not found'); |
60 | return { found: false }; | 61 | return { found: false }; |
61 | } | 62 | } |
@@ -94,7 +95,7 @@ export default class ConfigFile implements ConfigRepository { | |||
94 | mtime = stats.mtime; | 95 | mtime = stats.mtime; |
95 | log.trace('Config file last modified at', mtime); | 96 | log.trace('Config file last modified at', mtime); |
96 | } catch (error) { | 97 | } catch (error) { |
97 | if ((error as NodeJS.ErrnoException).code === 'ENOENT') { | 98 | if (isErrno(error, 'ENOENT')) { |
98 | log.debug( | 99 | log.debug( |
99 | 'Config file', | 100 | 'Config file', |
100 | this.#configFilePath, | 101 | this.#configFilePath, |