tsx
81 lines
1.79 KB
| 1 | import React, { Component } from 'react'; |
| 2 | import Header from './Header'; |
| 3 | import Main from './Main'; |
| 4 | import FooterLinks from './FooterLinks'; |
| 5 | import { CSSProperties } from 'react'; |
| 6 | |
| 7 | import { BrowserRouter } from 'react-router-dom'; |
| 8 | import Firebase, { FirebaseContext } from './Firebase'; |
| 9 | import { IntlProvider } from 'react-intl'; |
| 10 | import { addLocaleData } from "react-intl"; |
| 11 | import locale_en from 'react-intl/locale-data/en'; |
| 12 | import locale_se from 'react-intl/locale-data/se'; |
| 13 | import locale_id from 'react-intl/locale-data/id'; |
| 14 | import messages_se from "./translations/se.json"; |
| 15 | import messages_id from "./translations/id.json"; |
| 16 | import messages_en from "./translations/en.json"; |
| 17 | |
| 18 | addLocaleData([...locale_en, ...locale_id, ...locale_se]); |
| 19 | |
| 20 | type AppProps = { |
| 21 | firebase: Firebase | null |
| 22 | } |
| 23 | |
| 24 | type AppState = { |
| 25 | contentMain: string, |
| 26 | contentSkills: string, |
| 27 | updatedAt: string |
| 28 | } |
| 29 | |
| 30 | class App extends Component { |
| 31 | |
| 32 | messages: { |
| 33 | [key: string]: object, |
| 34 | } = { |
| 35 | "se": messages_se, |
| 36 | "id": messages_id, |
| 37 | "en": messages_en |
| 38 | }; |
| 39 | |
| 40 | language = "en"; |
| 41 | |
| 42 | mainStyle: CSSProperties = { |
| 43 | position: 'absolute', |
| 44 | top: 50, |
| 45 | left: 50, |
| 46 | background: 'rgba(0,0,0,0.65)', |
| 47 | width: 300, |
| 48 | textAlign: 'left', |
| 49 | padding: 10 |
| 50 | }; |
| 51 | |
| 52 | constructor(props: AppProps) { |
| 53 | super(props) |
| 54 | |
| 55 | const tld = window.location.hostname.split('.').pop(); |
| 56 | |
| 57 | if (tld === "id") { |
| 58 | this.language = "id"; |
| 59 | } else if (tld === "se") { |
| 60 | this.language = "se"; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | render() { |
| 65 | return ( |
| 66 | <IntlProvider locale={this.language} messages={this.messages[this.language]}> |
| 67 | <BrowserRouter> |
| 68 | <FirebaseContext.Provider value={new Firebase(this.language)}> |
| 69 | <div style={this.mainStyle}> |
| 70 | <Header /> |
| 71 | <Main /> |
| 72 | <FooterLinks /> |
| 73 | </div> |
| 74 | </FirebaseContext.Provider> |
| 75 | </BrowserRouter> |
| 76 | </IntlProvider> |
| 77 | ) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | export default App; |