From 7af01713180066b6dc1061dae930840e48c60fec Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Wed, 30 Mar 2022 01:36:22 +0200 Subject: feat(main): Add localization support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- packages/main/src/infrastructure/config/impl/ConfigFile.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'packages/main/src/infrastructure/config') 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'; import type Config from '../../../stores/config/Config'; import type Disposer from '../../../utils/Disposer'; +import isErrno from '../../../utils/isErrno'; import { getLogger } from '../../../utils/log'; import type ConfigRepository from '../ConfigRepository'; import type { ReadConfigResult } from '../ConfigRepository'; @@ -55,7 +56,7 @@ export default class ConfigFile implements ConfigRepository { try { configStr = await readFile(this.#configFilePath, 'utf8'); } catch (error) { - if ((error as NodeJS.ErrnoException).code === 'ENOENT') { + if (isErrno(error, 'ENOENT')) { log.debug('Config file', this.#configFilePath, 'was not found'); return { found: false }; } @@ -94,7 +95,7 @@ export default class ConfigFile implements ConfigRepository { mtime = stats.mtime; log.trace('Config file last modified at', mtime); } catch (error) { - if ((error as NodeJS.ErrnoException).code === 'ENOENT') { + if (isErrno(error, 'ENOENT')) { log.debug( 'Config file', this.#configFilePath, -- cgit v1.2.3-70-g09d2