Used OS language to default localization
This commit is contained in:
parent
2a30fee4b5
commit
4a0855e074
3 changed files with 26 additions and 23 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,28 +8,9 @@
|
|||
<body>
|
||||
<div id="app"></div>
|
||||
<script>
|
||||
window.i18n_messages = {};
|
||||
|
||||
function loadUi () {
|
||||
const script = document.createElement('script');
|
||||
script.setAttribute('src', 'ui.js');
|
||||
document.body.appendChild(script);
|
||||
}
|
||||
|
||||
let lang;
|
||||
try {
|
||||
lang = window.localStorage.getItem('language') || 'en';
|
||||
} catch {
|
||||
lang = 'en';
|
||||
}
|
||||
if (lang && lang != 'en') {
|
||||
fetch('https://lbry.com/i18n/get/lbry-desktop/app-strings/' + lang + '.json')
|
||||
.then(r => r.json())
|
||||
.then(j => { window.i18n_messages[lang] = j; loadUi(); })
|
||||
.catch(loadUi);
|
||||
} else {
|
||||
loadUi();
|
||||
}
|
||||
const script = document.createElement('script');
|
||||
script.setAttribute('src', 'ui.js');
|
||||
document.body.appendChild(script);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -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 => {
|
||||
|
|
Loading…
Reference in a new issue