1
0
mirror of https://github.com/pavlobu/deskreen.git synced 2025-05-27 21:00:08 -07:00

remove remote from i18next.config.client

This commit is contained in:
Pavlo Buidenkov 2022-05-28 21:50:48 +02:00
parent 468bc83c9a
commit 143ec1644c
2 changed files with 40 additions and 32 deletions

View File

@ -1,7 +1,7 @@
/* istanbul ignore file */
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { remote, ipcRenderer } from 'electron';
import { ipcRenderer } from 'electron';
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import SyncBackend from 'i18next-node-fs-backend';
@ -67,41 +67,44 @@ export const getShuffledArrayOfHello = (): string[] => {
return res;
};
const appPath = remote.getGlobal('appPath');
async function initI18NextOptions() {
const appPath = await ipcRenderer.invoke('get-app-path');
const i18nextOptions = {
interpolation: {
escapeValue: false,
},
backend: {
// path where resources get loaded from
loadPath: isProduction()
? join(appPath, 'locales/{{lng}}/{{ns}}.json')
: join(__dirname, './locales/{{lng}}/{{ns}}.json'),
// path to post missing resources
addPath: isProduction()
? join(appPath, 'locales/{{lng}}/{{ns}}.json')
: join(__dirname, './locales/{{lng}}/{{ns}}.missing.json'),
// jsonIndent to use when storing json files
jsonIndent: 2,
},
saveMissing: true,
lng: (settings.hasSync('appLanguage')
? settings.getSync('appLanguage')
: 'en') as string,
fallbackLng: config.fallbackLng,
whitelist: config.languages,
react: {
wait: false,
},
};
if (!i18n.isInitialized) {
i18n.init(i18nextOptions);
}
}
initI18NextOptions();
const i18nextOptions = {
interpolation: {
escapeValue: false,
},
backend: {
// path where resources get loaded from
loadPath: isProduction()
? join(appPath, 'locales/{{lng}}/{{ns}}.json')
: join(__dirname, './locales/{{lng}}/{{ns}}.json'),
// path to post missing resources
addPath: isProduction()
? join(appPath, 'locales/{{lng}}/{{ns}}.json')
: join(__dirname, './locales/{{lng}}/{{ns}}.missing.json'),
// jsonIndent to use when storing json files
jsonIndent: 2,
},
saveMissing: true,
lng: (settings.hasSync('appLanguage')
? settings.getSync('appLanguage')
: 'en') as string,
fallbackLng: config.fallbackLng,
whitelist: config.languages,
react: {
wait: false,
},
};
i18n.use(SyncBackend);
i18n.use(initReactI18next);
if (!i18n.isInitialized) {
i18n.init(i18nextOptions);
}
i18n.on('languageChanged', () => {
ipcRenderer.send('client-changed-language', i18n.language);
});

View File

@ -79,4 +79,9 @@ export default function initIpcMainHandlers(
}
return '255.255.255.255';
});
ipcMain.handle('get-app-path', () => {
const deskreenGlobal = getDeskreenGlobal();
return deskreenGlobal.appPath;
});
}