File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
recipes/slim/snippets/sources Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ function getSourceCode ( appName , { sourceDir } ) {
2+ const langUrl = `${ sourceDir . locales } /` + '${lang}.json'
3+
4+ return `import React, { useState, useEffect } from 'react'
5+ import { IntlProvider } from 'react-intl'
6+ import axios from 'axios'
7+
8+ const fetchTranslations = async (lang) => {
9+ return await axios.get(\`${ langUrl } \`)
10+ }
11+
12+ const withI18n = (Component) => (props) => {
13+ const [messages, setMessages] = useState({})
14+ const locale = 'en'
15+
16+ useEffect(() => {
17+ fetchTranslations(locale).then((response) => {
18+ setMessages(response.data)
19+ })
20+ }, [])
21+
22+ return (
23+ <IntlProvider
24+ locale={locale}
25+ defaultLocale={locale}
26+ messages={messages}
27+ onError={() => {}}
28+ >
29+ <Component {...props} />
30+ </IntlProvider>
31+ )
32+ }
33+
34+ export default withI18n
35+ `
36+ }
37+
38+ module . exports = {
39+ getSourceCode,
40+ } ;
You can’t perform that action at this time.
0 commit comments