Skip to content

Commit

Permalink
fix: use.i18ncontext
Browse files Browse the repository at this point in the history
  • Loading branch information
imcuttle committed Jul 4, 2020
1 parent 6716975 commit da70207
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ should be named as `use.{{lowerCase}}`, eg. `@rp/use.i18n`.

- [@rcp/c.keepalive](packages/c.keepalive) - Keep react component view / store when switched view.
- [@rcp/c.loadingwrapper](packages/c.loadingwrapper) - A component for easy create loading mask
- [@rcp/hoc.i18n](packages/hoc.i18n) - React Component's high order component about internationalization
- [@rcp/hoc.mount](packages/hoc.mount) - The high order component for mounting component
- [@rcp/hoc.uncontrolled](packages/hoc.uncontrolled) - The high order component for creating uncontrolled component
- [@rcp/use.i18n](packages/use.i18n) - A react hook for using i18n
- [@rcp/hoc.uncontrolled](packages/hoc.uncontrolled) - The high order component for creating uncontrolled component
- [@rcp/hoc.i18n](packages/hoc.i18n) - React Component's high order component about internationalization
- [@rcp/use.i18ncontext](packages/use.i18ncontext) - A react hook for using i18n provider/consumer
- [@rcp/util.createlogger](packages/util.createlogger) - Create namespace isomorphic logger
- [@rcp/util.createmount](packages/util.createmount) - The utility for creating mountable view
Expand Down
2 changes: 1 addition & 1 deletion packages/c.keepalive/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
"@rcp/util.displayname": "^1.0.10",
"classnames": "^2.2.6"
},
"gitHead": "640a4a782c1bd8624dbb360528ed5a0ed4fe0cc1"
"gitHead": "67169750a161d406d973f1f7d73a6b3231060a54"
}
2 changes: 1 addition & 1 deletion packages/hoc.i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"lodash.foreach": "^4.5.0",
"tiny-i18n": "^2.0.3"
},
"gitHead": "640a4a782c1bd8624dbb360528ed5a0ed4fe0cc1",
"gitHead": "67169750a161d406d973f1f7d73a6b3231060a54",
"repository": {
"type": "git",
"url": "git+https://github.com/imcuttle/rcp.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/hoc.mount/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@rcp/util.displayname": "^1.0.10",
"@rcp/util.tocompclass": "^1.0.10"
},
"gitHead": "61d21542c15237221f078f8331e8c2cc960509c0",
"gitHead": "67169750a161d406d973f1f7d73a6b3231060a54",
"repository": {
"type": "git",
"url": "git+https://github.com/imcuttle/rcp.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/hoc.uncontrolled/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@rcp/util.displayname": "^1.0.10",
"@rcp/util.iscompclass": "^1.0.10"
},
"gitHead": "61d21542c15237221f078f8331e8c2cc960509c0",
"gitHead": "67169750a161d406d973f1f7d73a6b3231060a54",
"repository": {
"type": "git",
"url": "git+https://github.com/imcuttle/rcp.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/use.i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
"main": "index.js",
"typings": "index.d.js",
"version": "1.1.9",
"gitHead": "640a4a782c1bd8624dbb360528ed5a0ed4fe0cc1"
"gitHead": "67169750a161d406d973f1f7d73a6b3231060a54"
}
44 changes: 22 additions & 22 deletions packages/use.i18ncontext/__tests__/spec.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { UseI18nOptions } from '@rcp/use.i18n'
import useI18n, { I18nProvider, I18nConsumer, withTinyI18n, useI18nContext } from '../index'

function Demo({ language = 'zh-cn', locale }: UseI18nOptions) {
const { i18n } = useI18n(
const { i18n, getDataBase, getCurrentLanguage } = useI18n(
{
'zh-cn': {
title: '标题',
Expand All @@ -26,7 +26,6 @@ function Demo({ language = 'zh-cn', locale }: UseI18nOptions) {
locale
}
)

return <p>{i18n('content', i18n('title'))}</p>
}

Expand Down Expand Up @@ -69,21 +68,25 @@ describe('useI18nContext', function() {
})

describe('withContext', function() {
const tinyI18n = createIsolateI18n()
tinyI18n.setDictionary(
{
name: '姓名',
age: '年纪'
},
'zh'
)
tinyI18n.setDictionary(
{
name: 'Name',
age: 'Age'
},
'en'
)
let tinyI18n

beforeEach(() => {
tinyI18n = createIsolateI18n()
tinyI18n.setDictionary(
{
name: '姓名',
age: '年纪'
},
'zh'
)
tinyI18n.setDictionary(
{
name: 'Name',
age: 'Age'
},
'en'
)
})

function App({ children, language = 'en' }) {
return (
Expand Down Expand Up @@ -141,17 +144,15 @@ describe('useI18nContext', function() {
<View />
</App>
)
expect(wrapper.text()).toMatchInlineSnapshot(
`"Name from OverrideView,Age from OverrideViewName from OverrideView,Age from OverrideView"`
)
expect(wrapper.text()).toMatchInlineSnapshot(`"Name,Override AgeName,Override Age"`)

wrapper = mount(
<App>
<View />
<OverrideView locale={{ name: '_name', age: '_age' }} />
</App>
)
expect(wrapper.text()).toMatchInlineSnapshot(`"Name from OverrideView,Override Age_name,_age"`)
expect(wrapper.text()).toMatchInlineSnapshot(`"Name,Override Age_name,_age"`)
})

it('should render Nested', function() {
Expand All @@ -165,7 +166,6 @@ describe('useI18nContext', function() {
},
{ locale }
)
console.log(getDataBase())
return (
<h1>
{i18n('name')},{i18n('age')}
Expand Down
2 changes: 1 addition & 1 deletion packages/use.i18ncontext/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export function useI18nContext() {
export default function useI18n(presetDict: Dictionary, opts: UseI18nOptions = {}) {
const tinyI18n = useI18nContext()

const currentLocale = tinyI18n.getDictionary()
const currentLocale = tinyI18n.getDictionary(opts.language == null ? void 0 : opts.language)

return useI18nCore(presetDict, {
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion packages/use.i18ncontext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
"main": "index.js",
"typings": "index.d.js",
"version": "1.0.6",
"gitHead": "640a4a782c1bd8624dbb360528ed5a0ed4fe0cc1"
"gitHead": "67169750a161d406d973f1f7d73a6b3231060a54"
}
2 changes: 1 addition & 1 deletion packages/util.createmount/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"main": "index.js",
"typings": "index.d.js",
"version": "1.0.11",
"gitHead": "61d21542c15237221f078f8331e8c2cc960509c0",
"gitHead": "67169750a161d406d973f1f7d73a6b3231060a54",
"repository": {
"type": "git",
"url": "git+https://github.com/imcuttle/rcp.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/util.displayname/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"@rcp/util.iscompclass": "^1.0.10"
},
"gitHead": "61d21542c15237221f078f8331e8c2cc960509c0",
"gitHead": "67169750a161d406d973f1f7d73a6b3231060a54",
"repository": {
"type": "git",
"url": "git+https://github.com/imcuttle/rcp.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/util.iscompclass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"dependencies": {
"is-plain-obj": "^1.1.0"
},
"gitHead": "61d21542c15237221f078f8331e8c2cc960509c0",
"gitHead": "67169750a161d406d973f1f7d73a6b3231060a54",
"repository": {
"type": "git",
"url": "git+https://github.com/imcuttle/rcp.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/util.iselemof/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"devDependencies": {
"@rcp/_types": "^1.0.7"
},
"gitHead": "61d21542c15237221f078f8331e8c2cc960509c0",
"gitHead": "67169750a161d406d973f1f7d73a6b3231060a54",
"repository": {
"type": "git",
"url": "git+https://github.com/imcuttle/rcp.git"
Expand Down
2 changes: 1 addition & 1 deletion packages/util.tocompclass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"devDependencies": {
"@rcp/_types": "^1.0.7"
},
"gitHead": "61d21542c15237221f078f8331e8c2cc960509c0",
"gitHead": "67169750a161d406d973f1f7d73a6b3231060a54",
"repository": {
"type": "git",
"url": "git+https://github.com/imcuttle/rcp.git"
Expand Down

0 comments on commit da70207

Please sign in to comment.