curriculum/src/index.js

57 lines
1.4 KiB
JavaScript
Raw Normal View History

import './index.css';
import React from 'react';
import ReactDOM from 'react-dom';
2020-12-31 17:38:30 +01:00
import { IntlProvider } from 'react-intl';
import App from './App';
import messages from './messages';
import reportWebVitals from './reportWebVitals';
2020-12-31 17:38:30 +01:00
const GLOBAL_MESSAGE_KEY = "global";
2020-12-31 17:38:30 +01:00
const i18nConfig = {
defaultLocale: 'fr',
messages,
2020-12-31 17:38:30 +01:00
};
const language = function () {
2020-12-31 17:38:30 +01:00
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
let lang = urlParams.get("lang");
if (messages[lang] === undefined) {
2020-12-31 17:38:30 +01:00
lang = navigator.language.split(/[-_]/)[0];
}
return lang;
}
const langJson = function () {
const messageLocalized = i18nConfig.messages[language()];
const messageGlobal = i18nConfig.messages[GLOBAL_MESSAGE_KEY];
const messageMerged = {
...messageLocalized,
...messageGlobal
};
console.log(JSON.stringify(messageMerged))
return messageMerged;
}
ReactDOM.render(
<React.StrictMode>
<IntlProvider
2020-12-31 17:38:30 +01:00
locale={language}
defaultLocale={i18nConfig.defaultLocale}
messages={langJson()}
2020-12-31 17:38:30 +01:00
>
<App />
2020-12-31 17:38:30 +01:00
</IntlProvider>
</React.StrictMode>,
document.getElementById('root')
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();