diff --git a/electron/createWindow.js b/electron/createWindow.js index 6c7034f3a..1e6df6867 100644 --- a/electron/createWindow.js +++ b/electron/createWindow.js @@ -88,6 +88,8 @@ export default appState => { window.loadURL(rendererURL + deepLinkingURI); setupBarMenu(); + setLanguage(window); + window.on('close', event => { if (!appState.isQuitting && !appState.autoUpdateAccepted) { event.preventDefault(); @@ -144,3 +146,16 @@ export default appState => { return window; }; + +async function setLanguage(window) { + const storedLanguage = await window.webContents.executeJavaScript("localStorage.getItem('language')"); + const lang = storedLanguage || app.getLocale().slice(0, 2) || 'en'; + if (['pl', 'id', 'de'].includes(lang)) { + const response = await fetch('https://lbry.com/i18n/get/lbry-desktop/app-strings/' + lang + '.json'); + const json = await response.json(); + const messages = {}; + messages[lang] = json; + // Send message to render layer to update language. + window.webContents.send('language-update', messages, lang); + } +} diff --git a/static/index-electron.html b/static/index-electron.html index 3b8b8e263..c30ddb9e6 100644 --- a/static/index-electron.html +++ b/static/index-electron.html @@ -8,28 +8,9 @@
diff --git a/ui/index.jsx b/ui/index.jsx index b874c8000..a93e4797d 100644 --- a/ui/index.jsx +++ b/ui/index.jsx @@ -13,7 +13,7 @@ import ReactDOM from 'react-dom'; import { Provider } from 'react-redux'; import { doConditionalAuthNavigate, doDaemonReady, doAutoUpdate, doOpenModal, doHideModal } from 'redux/actions/app'; import { Lbry, doToast, isURIValid, setSearchApi } from 'lbry-redux'; -import { doUpdateIsNightAsync } from 'redux/actions/settings'; +import { doUpdateIsNightAsync, doSetClientSetting } from 'redux/actions/settings'; import { doAuthenticate, Lbryio, @@ -31,6 +31,7 @@ import { PersistGate } from 'redux-persist/integration/react'; import analytics from 'analytics'; import { getAuthToken, setAuthToken } from 'util/saved-passwords'; import { X_LBRY_AUTH_TOKEN } from 'constants/token'; +import * as SETTINGS from 'constants/settings'; // Import our app styles // If a style is not necessary for the initial page load, it should be removed from `all.scss` @@ -193,6 +194,12 @@ ipcRenderer.on('devtools-is-opened', () => { doLogWarningConsoleMessage(); }); +ipcRenderer.on('language-update', (event, messages, language) => { + window.i18n_messages = messages; + window.localStorage.setItem(SETTINGS.LANGUAGE, language); + doSetClientSetting(SETTINGS.LANGUAGE, language); +}); + // Force exit mode for html5 fullscreen api // See: https://github.com/electron/electron/issues/18188 remote.getCurrentWindow().on('leave-full-screen', event => {