Improve: Migrate i18nprops to models

This commit is contained in:
Jason 2018-10-05 15:29:21 +08:00
parent 26541f22fc
commit d79d03ea16
10 changed files with 34 additions and 11 deletions

View File

@ -1,7 +1,7 @@
import * as React from 'react'
import { Route } from 'react-router-dom'
import { hot } from 'react-hot-loader'
import { I18nProps } from '@i18n'
import { I18nProps } from '@models'
import './App.scss'
import Overview from '@containers/Overview'

View File

@ -1,7 +1,7 @@
import * as React from 'react'
import * as dayjs from 'dayjs'
import { translate } from 'react-i18next'
import { I18nProps } from '@i18n'
import { I18nProps } from '@models'
import { Card, Header } from '@components'
import './style.scss'

View File

@ -1,7 +1,18 @@
import * as React from 'react'
import { Header } from '@components'
import { translate } from 'react-i18next'
import { I18nProps } from '@models'
export default class Rules extends React.Component<{}, {}> {
class Rules extends React.Component<I18nProps, {}> {
render () {
return 'Rules'
const { t } = this.props
return (
<div className="page">
<Header title={t('title')} />
</div>
)
}
}
export default translate(['Rules'])(Rules)

View File

@ -2,7 +2,7 @@ import * as React from 'react'
import { Header, Card, Row, Col, Switch, ButtonSelect, ButtonSelectOptions, Input, Icon } from '@components'
import { translate } from 'react-i18next'
import { changeLanguage } from 'i18next'
import { I18nProps } from '@i18n'
import { I18nProps } from '@models'
import './style.scss'
class Settings extends React.Component<I18nProps, {}> {

View File

@ -1,7 +1,7 @@
import * as React from 'react'
import { NavLink } from 'react-router-dom'
import { translate } from 'react-i18next'
import { I18nProps } from '@i18n'
import { I18nProps } from '@models'
import './style.scss'
const logo = require('@assets/logo.png')

View File

@ -30,5 +30,8 @@ export default {
},
Logs: {
title: 'Logs'
},
Rules: {
title: 'Rules'
}
}

View File

@ -24,9 +24,4 @@ const options = {
}
}
export interface I18nProps {
t? (key: string, variables?: { [key: string]: any }): string
lng?: string
}
export default i18n.use(LanguageDetector).init(options)

View File

@ -30,5 +30,8 @@ export default {
},
Logs: {
title: '日志'
},
Rules: {
title: '规则'
}
}

10
src/models/I18n.ts Normal file
View File

@ -0,0 +1,10 @@
export interface I18nProps {
t? (
key: string,
variables?: {
[key: string]: any
}
): string
lng?: string
}

View File

@ -2,3 +2,4 @@ export * from './BaseProps'
export * from './Config'
export * from './Proxy'
export * from './Rule'
export * from './I18n'