2020-12-05 08:47:02 +01:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2020-12-06 07:35:21 +01:00
|
|
|
import LoginPage from './components/LoginPage';
|
|
|
|
import { RegistrationSuccessPage, RegistationFormPage } from './components/RegistrationPage';
|
2020-12-05 08:47:02 +01:00
|
|
|
import { IntlProvider } from 'react-intl'
|
|
|
|
|
|
|
|
import {
|
|
|
|
Route,
|
|
|
|
Switch,
|
2020-12-06 07:35:21 +01:00
|
|
|
Redirect,
|
2020-12-05 08:47:02 +01:00
|
|
|
} from 'react-router-dom';
|
|
|
|
|
2020-12-06 06:28:00 +01:00
|
|
|
function loadLocaleData(language: string) {
|
2020-12-05 08:47:02 +01:00
|
|
|
switch (language) {
|
|
|
|
case 'es':
|
2020-12-06 06:28:00 +01:00
|
|
|
return require('./compiled-lang/es.json')
|
2020-12-05 08:47:02 +01:00
|
|
|
default:
|
2020-12-06 06:28:00 +01:00
|
|
|
return require('./compiled-lang/en.json')
|
2020-12-05 08:47:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const App = () => {
|
|
|
|
const [messages, setMessages] = useState(undefined);
|
|
|
|
|
|
|
|
// Boostrap i18n ...
|
|
|
|
const locale = (navigator.languages && navigator.languages[0])
|
|
|
|
|| navigator.language
|
|
|
|
|| 'en-US';
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const language = locale.split('-')[0];
|
|
|
|
const fetchData = async () => {
|
|
|
|
const messages = await loadLocaleData(language);
|
|
|
|
setMessages(messages);
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchData();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return messages ? (
|
|
|
|
<IntlProvider locale={locale} defaultLocale='en' messages={messages}>
|
|
|
|
<Switch>
|
2020-12-05 22:18:44 +01:00
|
|
|
<Route exact path="/">
|
|
|
|
<Redirect to="/c/login" />
|
2020-12-05 08:47:02 +01:00
|
|
|
</Route>
|
2020-12-05 22:18:44 +01:00
|
|
|
<Route exact path="/">
|
|
|
|
<Redirect to="/react" />
|
|
|
|
</Route>
|
|
|
|
<Route path="/c/login" component={LoginPage} />
|
2020-12-05 22:57:39 +01:00
|
|
|
<Route path="/c/user/registration" component={RegistationFormPage} />
|
2020-12-05 22:18:44 +01:00
|
|
|
<Route path="/c/user/registrationSuccess" component={RegistrationSuccessPage} />
|
2020-12-05 08:47:02 +01:00
|
|
|
</Switch>
|
|
|
|
</IntlProvider>
|
|
|
|
) : <div>loading</div>
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|