From d79d03ea165e021437fc8a8f11e2fdd49c331988 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 5 Oct 2018 15:29:21 +0800 Subject: [PATCH] Improve: Migrate i18nprops to models --- src/containers/App.tsx | 2 +- src/containers/Logs/index.tsx | 2 +- src/containers/Rules/index.tsx | 15 +++++++++++++-- src/containers/Settings/index.tsx | 2 +- src/containers/Sidebar/index.tsx | 2 +- src/i18n/en_US.ts | 3 +++ src/i18n/index.ts | 5 ----- src/i18n/zh_CN.ts | 3 +++ src/models/I18n.ts | 10 ++++++++++ src/models/index.ts | 1 + 10 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 src/models/I18n.ts diff --git a/src/containers/App.tsx b/src/containers/App.tsx index 1019374..b4dd8c6 100644 --- a/src/containers/App.tsx +++ b/src/containers/App.tsx @@ -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' diff --git a/src/containers/Logs/index.tsx b/src/containers/Logs/index.tsx index 57cd17f..9a56b4b 100644 --- a/src/containers/Logs/index.tsx +++ b/src/containers/Logs/index.tsx @@ -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' diff --git a/src/containers/Rules/index.tsx b/src/containers/Rules/index.tsx index 9fdc53c..2f613f1 100644 --- a/src/containers/Rules/index.tsx +++ b/src/containers/Rules/index.tsx @@ -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 { render () { - return 'Rules' + const { t } = this.props + + return ( +
+
+
+ ) } } + +export default translate(['Rules'])(Rules) diff --git a/src/containers/Settings/index.tsx b/src/containers/Settings/index.tsx index 0e3ed53..7749db4 100644 --- a/src/containers/Settings/index.tsx +++ b/src/containers/Settings/index.tsx @@ -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 { diff --git a/src/containers/Sidebar/index.tsx b/src/containers/Sidebar/index.tsx index 4fe70c4..065bb21 100644 --- a/src/containers/Sidebar/index.tsx +++ b/src/containers/Sidebar/index.tsx @@ -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') diff --git a/src/i18n/en_US.ts b/src/i18n/en_US.ts index 18d03e0..2c7dbb6 100644 --- a/src/i18n/en_US.ts +++ b/src/i18n/en_US.ts @@ -30,5 +30,8 @@ export default { }, Logs: { title: 'Logs' + }, + Rules: { + title: 'Rules' } } diff --git a/src/i18n/index.ts b/src/i18n/index.ts index cd9c229..d6703be 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -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) diff --git a/src/i18n/zh_CN.ts b/src/i18n/zh_CN.ts index d0806a5..7ebd0dc 100644 --- a/src/i18n/zh_CN.ts +++ b/src/i18n/zh_CN.ts @@ -30,5 +30,8 @@ export default { }, Logs: { title: '日志' + }, + Rules: { + title: '规则' } } diff --git a/src/models/I18n.ts b/src/models/I18n.ts new file mode 100644 index 0000000..4b00658 --- /dev/null +++ b/src/models/I18n.ts @@ -0,0 +1,10 @@ +export interface I18nProps { + t? ( + key: string, + variables?: { + [key: string]: any + } + ): string + + lng?: string +} diff --git a/src/models/index.ts b/src/models/index.ts index d6cff1e..d69a472 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -2,3 +2,4 @@ export * from './BaseProps' export * from './Config' export * from './Proxy' export * from './Rule' +export * from './I18n'