diff --git a/electron/createWindow.js b/electron/createWindow.js index aa5402e09..16e98327e 100644 --- a/electron/createWindow.js +++ b/electron/createWindow.js @@ -5,7 +5,7 @@ import windowStateKeeper from 'electron-window-state'; import setupBarMenu from './menu/setupBarMenu'; import * as PAGES from '../../ui/constants/pages'; -import SUPPORTED_LANGUAGES from '../../ui/constants/supported_languages'; +import setLanguage from './setLanguage'; export default appState => { // Get primary display dimensions from Electron. @@ -147,18 +147,3 @@ 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'; - - const supportedNonEnglish = Object.keys(SUPPORTED_LANGUAGES).filter(language => language !== 'en'); - if (supportedNonEnglish.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/src/platforms/electron/setLanguage.js b/src/platforms/electron/setLanguage.js new file mode 100644 index 000000000..a8db87a0d --- /dev/null +++ b/src/platforms/electron/setLanguage.js @@ -0,0 +1,22 @@ +import SUPPORTED_LANGUAGES from '../../ui/constants/supported_languages'; + +export default async function setLanguage(window) { + const storedLanguage = await window.webContents.executeJavaScript("localStorage.getItem('language')"); + const lang = storedLanguage || app.getLocale().slice(0, 2) || 'en'; + const supportedNonEnglish = Object.keys(SUPPORTED_LANGUAGES).filter(language => language !== 'en'); + + if (supportedNonEnglish.includes(lang)) { + fetch('https://lbry.com/i18n/get/lbry-desktop/app-strings/' + lang + '.json') + .then(response => response.json()) + .then(json => { + const messages = {}; + messages[lang] = json; + window.webContents.send('language-set', messages, lang); + }) + .catch(error => { + window.webContents.send('language-set', {}, lang, error); + }); + } else { + window.webContents.send('language-set', {}, lang); + } +} diff --git a/static/index-electron.html b/static/index-electron.html index c30ddb9e6..6af12eb1d 100644 --- a/static/index-electron.html +++ b/static/index-electron.html @@ -8,9 +8,21 @@