mirror of
https://github.com/bellingcat/ukraine-timemap.git
synced 2026-06-13 05:48:36 +03:00
Add LanguageSwitch component for changing app's language (#25)
Co-authored-by: msramalho <19508417+msramalho@users.noreply.github.com>
This commit is contained in:
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user