diff options
Diffstat (limited to 'src/I18n.tsx')
-rw-r--r-- | src/I18n.tsx | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/I18n.tsx b/src/I18n.tsx new file mode 100644 index 000000000..39b5273c1 --- /dev/null +++ b/src/I18n.tsx | |||
@@ -0,0 +1,42 @@ | |||
1 | import { Component, ReactNode } from 'react'; | ||
2 | import { inject, observer } from 'mobx-react'; | ||
3 | import { IntlProvider } from 'react-intl'; | ||
4 | |||
5 | import { generatedTranslations } from './i18n/translations'; | ||
6 | import UserStore from './stores/UserStore'; | ||
7 | import AppStore from './stores/AppStore'; | ||
8 | |||
9 | const translations = generatedTranslations(); | ||
10 | |||
11 | type Props = { | ||
12 | stores: { | ||
13 | app: typeof AppStore; | ||
14 | user: typeof UserStore; | ||
15 | }; | ||
16 | children: ReactNode; | ||
17 | }; | ||
18 | |||
19 | @inject('stores') | ||
20 | @observer | ||
21 | class I18N extends Component<Props> { | ||
22 | componentDidUpdate() { | ||
23 | window['ferdi'].menu.rebuild(); | ||
24 | } | ||
25 | |||
26 | render() { | ||
27 | const { stores, children } = this.props; | ||
28 | const { locale } = stores.app; | ||
29 | return ( | ||
30 | <IntlProvider | ||
31 | {...{ locale, key: locale, messages: translations[locale] }} | ||
32 | ref={intlProvider => { | ||
33 | window['ferdi'].intl = intlProvider ? intlProvider.state.intl : null; | ||
34 | }} | ||
35 | > | ||
36 | {children} | ||
37 | </IntlProvider> | ||
38 | ); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | export default I18N; | ||