Add LanguageSwitch component for changing app's language (#25)

Co-authored-by: msramalho <19508417+msramalho@users.noreply.github.com>
This commit is contained in:
wattroll
2022-04-07 00:54:42 +03:00
committed by GitHub
parent 4c1b220d75
commit f024d2195a
12 changed files with 108 additions and 9 deletions

View File

@@ -3,6 +3,14 @@ import ReactDOM from "react-dom/client";
import { Provider } from "react-redux";
import store from "./store";
import App from "./components/App";
import copy from "./common/data/copy.json";
// XXX: Hack to make migration from "copy.json" and
// adding missing translation strings smoother.
Object.assign(copy, {
ru: { ...copy["en"], ...copy["uk"], ...copy["ru"] },
uk: { ...copy["en"], ...copy["ru"], ...copy["uk"] },
});
const root = ReactDOM.createRoot(document.getElementById("explore-app"));
root.render(
@@ -11,6 +19,21 @@ root.render(
</Provider>
);
store.subscribe(() => {
const { app } = store.getState();
renderAppLanguage(app);
});
// Update language in places that are out of the App's reach
function renderAppLanguage({ language }) {
const html = document.documentElement;
if (language && language !== html.lang) {
html.lang = language;
const title = process.env.page_title[language];
if (title) document.title = title;
}
}
// Expressions from https://exceptionshub.com/how-to-detect-safari-chrome-ie-firefox-and-opera-browser.html
/* eslint-disable */