mirror of
https://github.com/pavlobu/deskreen.git
synced 2025-05-28 05:10:09 -07:00
able to preserve language with electron store
This commit is contained in:
parent
4d37caaaf0
commit
9f67432182
@ -17,7 +17,6 @@ i18n
|
||||
// init i18next
|
||||
// for all options read: https://www.i18next.com/overview/configuration-options
|
||||
.init({
|
||||
// fallbackLng: 'ua',
|
||||
lng: 'en',
|
||||
saveMissing: true,
|
||||
saveMissingTo: 'all',
|
||||
|
@ -34,7 +34,7 @@ export default function LanguageSelector() {
|
||||
getLangFullNameToLangISOKeyMap().get(event.currentTarget.value) ||
|
||||
'English';
|
||||
i18n.changeLanguage(newLang);
|
||||
ipcRenderer.invoke(IpcEvents.AppLanguageChanged);
|
||||
ipcRenderer.invoke(IpcEvents.AppLanguageChanged, newLang);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -17,6 +17,8 @@ import translationZH_TW from '../locales/zh_TW/translation.json';
|
||||
import translationDA from '../locales/da/translation.json';
|
||||
import translationDE from '../locales/de/translation.json';
|
||||
import { IpcEvents } from '../main/IpcEvents.enum';
|
||||
import { ElectronStoreKeys } from '../enums/ElectronStoreKeys.enum';
|
||||
import store from '../deskreen-electron-store';
|
||||
|
||||
export const getLangFullNameToLangISOKeyMap = (): Map<string, string> => {
|
||||
const res = new Map<string, string>();
|
||||
@ -68,7 +70,11 @@ export const getShuffledArrayOfHello = (): string[] => {
|
||||
|
||||
async function initI18NextOptions() {
|
||||
const appPath = await ipcRenderer.invoke(IpcEvents.GetAppPath);
|
||||
const appLanguage = String(store.get(ElectronStoreKeys.AppLanguage));
|
||||
i18n.use(SyncBackend);
|
||||
i18n.use(initReactI18next);
|
||||
const i18nextOptions = {
|
||||
debug: true,
|
||||
interpolation: {
|
||||
escapeValue: false,
|
||||
},
|
||||
@ -85,10 +91,7 @@ async function initI18NextOptions() {
|
||||
jsonIndent: 2,
|
||||
},
|
||||
saveMissing: true,
|
||||
// lng: (settings.hasSync('appLanguage')
|
||||
// ? settings.getSync('appLanguage')
|
||||
// : 'en') as string,
|
||||
lng: 'en',
|
||||
lng: config.languages.includes(appLanguage) ? appLanguage : 'en',
|
||||
fallbackLng: config.fallbackLng,
|
||||
whitelist: config.languages,
|
||||
react: {
|
||||
@ -102,9 +105,6 @@ async function initI18NextOptions() {
|
||||
}
|
||||
initI18NextOptions();
|
||||
|
||||
i18n.use(SyncBackend);
|
||||
i18n.use(initReactI18next);
|
||||
|
||||
i18n.on('languageChanged', () => {
|
||||
ipcRenderer.send('client-changed-language', i18n.language);
|
||||
});
|
||||
|
@ -5,13 +5,12 @@ import i18nextBackend from 'i18next-node-fs-backend';
|
||||
import { join } from 'path';
|
||||
import config from './app.lang.config';
|
||||
import isProduction from '../utils/isProduction';
|
||||
import store from '../deskreen-electron-store';
|
||||
import { ElectronStoreKeys } from '../enums/ElectronStoreKeys.enum';
|
||||
|
||||
const i18nextOptions = {
|
||||
fallbackLng: config.fallbackLng,
|
||||
// lng: (settings.hasSync('appLanguage')
|
||||
// ? settings.getSync('appLanguage')
|
||||
// : 'en') as string,
|
||||
lng: 'en',
|
||||
lng: store.get(ElectronStoreKeys.AppLanguage),
|
||||
ns: 'translation',
|
||||
defaultNS: 'translation',
|
||||
backend: {
|
||||
|
@ -12,7 +12,6 @@ import 'core-js/stable';
|
||||
import 'regenerator-runtime/runtime';
|
||||
import path from 'path';
|
||||
import { app, BrowserWindow, shell } from 'electron';
|
||||
// import ElectronStore from 'electron-store';
|
||||
import store from './deskreen-electron-store';
|
||||
import i18n from './configs/i18next.config';
|
||||
import signalingServer from './server';
|
||||
@ -24,8 +23,6 @@ import getNewVersionTag from './utils/getNewVersionTag';
|
||||
import initIpcMainHandlers from './main/ipcMainHandlers';
|
||||
import { ElectronStoreKeys } from './enums/ElectronStoreKeys.enum';
|
||||
|
||||
// const store = new ElectronStore();
|
||||
|
||||
export default class DeskreenApp {
|
||||
mainWindow: BrowserWindow | null = null;
|
||||
|
||||
@ -184,6 +181,9 @@ export default class DeskreenApp {
|
||||
setTimeout(async () => {
|
||||
if (lng !== 'en' && i18n.language !== lng) {
|
||||
i18n.changeLanguage(lng);
|
||||
if (store.has(ElectronStoreKeys.AppLanguage)) {
|
||||
store.delete(ElectronStoreKeys.AppLanguage);
|
||||
}
|
||||
store.set(ElectronStoreKeys.AppLanguage, lng);
|
||||
}
|
||||
}, 400);
|
||||
|
@ -21,4 +21,5 @@ export enum IpcEvents {
|
||||
GetDesktopSharingSourceIds = 'get-desktop-sharing-source-ids',
|
||||
SetDesktopCapturerSourceId = 'set-desktop-capturer-source-id',
|
||||
NotifyAllSessionsWithAppThemeChanged = 'notify-all-sessions-with-app-theme-changed',
|
||||
GetAppLanguage = 'get-app-language',
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ import signalingServer from '../server';
|
||||
import Logger from '../utils/LoggerWithFilePrefix';
|
||||
import { IpcEvents } from './IpcEvents.enum';
|
||||
import SharingSessionStatusEnum from '../features/SharingSessionService/SharingSessionStatusEnum';
|
||||
import { ElectronStoreKeys } from '../enums/ElectronStoreKeys.enum';
|
||||
import store from '../deskreen-electron-store';
|
||||
|
||||
const log = new Logger(__filename);
|
||||
const v4IPGetter = require('internal-ip').v4;
|
||||
@ -180,7 +182,11 @@ export default function initIpcMainHandlers(
|
||||
getDeskreenGlobal().connectedDevicesService.disconnectAllDevices();
|
||||
});
|
||||
|
||||
ipcMain.handle(IpcEvents.AppLanguageChanged, () => {
|
||||
ipcMain.handle(IpcEvents.AppLanguageChanged, (_, newLang) => {
|
||||
if (store.has(ElectronStoreKeys.AppLanguage)) {
|
||||
store.delete(ElectronStoreKeys.AppLanguage);
|
||||
}
|
||||
store.set(ElectronStoreKeys.AppLanguage, newLang);
|
||||
getDeskreenGlobal().sharingSessionService.sharingSessions.forEach(
|
||||
(sharingSession) => {
|
||||
sharingSession?.appLanguageChanged();
|
||||
|
Loading…
x
Reference in New Issue
Block a user