diff --git a/README.md b/README.md index 3217bde..e9bdca9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/packages/c.keepalive/package.json b/packages/c.keepalive/package.json index 1e9a2e8..4ed31b4 100644 --- a/packages/c.keepalive/package.json +++ b/packages/c.keepalive/package.json @@ -37,5 +37,5 @@ "@rcp/util.displayname": "^1.0.10", "classnames": "^2.2.6" }, - "gitHead": "640a4a782c1bd8624dbb360528ed5a0ed4fe0cc1" + "gitHead": "67169750a161d406d973f1f7d73a6b3231060a54" } diff --git a/packages/hoc.i18n/package.json b/packages/hoc.i18n/package.json index 152f63e..a29f8da 100644 --- a/packages/hoc.i18n/package.json +++ b/packages/hoc.i18n/package.json @@ -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" diff --git a/packages/hoc.mount/package.json b/packages/hoc.mount/package.json index 38dcac9..a615c2c 100644 --- a/packages/hoc.mount/package.json +++ b/packages/hoc.mount/package.json @@ -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" diff --git a/packages/hoc.uncontrolled/package.json b/packages/hoc.uncontrolled/package.json index 26b208e..28a68c3 100644 --- a/packages/hoc.uncontrolled/package.json +++ b/packages/hoc.uncontrolled/package.json @@ -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" diff --git a/packages/use.i18n/package.json b/packages/use.i18n/package.json index 286d5be..60c0ea8 100644 --- a/packages/use.i18n/package.json +++ b/packages/use.i18n/package.json @@ -37,5 +37,5 @@ "main": "index.js", "typings": "index.d.js", "version": "1.1.9", - "gitHead": "640a4a782c1bd8624dbb360528ed5a0ed4fe0cc1" + "gitHead": "67169750a161d406d973f1f7d73a6b3231060a54" } diff --git a/packages/use.i18ncontext/__tests__/spec.test.tsx b/packages/use.i18ncontext/__tests__/spec.test.tsx index 1d28d7d..a6c8d9d 100644 --- a/packages/use.i18ncontext/__tests__/spec.test.tsx +++ b/packages/use.i18ncontext/__tests__/spec.test.tsx @@ -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: '标题', @@ -26,7 +26,6 @@ function Demo({ language = 'zh-cn', locale }: UseI18nOptions) { locale } ) - return

{i18n('content', i18n('title'))}

} @@ -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 ( @@ -141,9 +144,7 @@ describe('useI18nContext', function() { ) - 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( @@ -151,7 +152,7 @@ describe('useI18nContext', function() { ) - 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() { @@ -165,7 +166,6 @@ describe('useI18nContext', function() { }, { locale } ) - console.log(getDataBase()) return (

{i18n('name')},{i18n('age')} diff --git a/packages/use.i18ncontext/index.tsx b/packages/use.i18ncontext/index.tsx index eb2a5ce..6ab2010 100644 --- a/packages/use.i18ncontext/index.tsx +++ b/packages/use.i18ncontext/index.tsx @@ -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 diff --git a/packages/use.i18ncontext/package.json b/packages/use.i18ncontext/package.json index 96013c5..238c83b 100644 --- a/packages/use.i18ncontext/package.json +++ b/packages/use.i18ncontext/package.json @@ -34,5 +34,5 @@ "main": "index.js", "typings": "index.d.js", "version": "1.0.6", - "gitHead": "640a4a782c1bd8624dbb360528ed5a0ed4fe0cc1" + "gitHead": "67169750a161d406d973f1f7d73a6b3231060a54" } diff --git a/packages/util.createmount/package.json b/packages/util.createmount/package.json index 391d93a..ec14b2a 100644 --- a/packages/util.createmount/package.json +++ b/packages/util.createmount/package.json @@ -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" diff --git a/packages/util.displayname/package.json b/packages/util.displayname/package.json index fdf506d..ba9af22 100644 --- a/packages/util.displayname/package.json +++ b/packages/util.displayname/package.json @@ -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" diff --git a/packages/util.iscompclass/package.json b/packages/util.iscompclass/package.json index d041fef..33d4fba 100644 --- a/packages/util.iscompclass/package.json +++ b/packages/util.iscompclass/package.json @@ -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" diff --git a/packages/util.iselemof/package.json b/packages/util.iselemof/package.json index a42d1be..718e80a 100644 --- a/packages/util.iselemof/package.json +++ b/packages/util.iselemof/package.json @@ -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" diff --git a/packages/util.tocompclass/package.json b/packages/util.tocompclass/package.json index 7cd4517..a51fd63 100644 --- a/packages/util.tocompclass/package.json +++ b/packages/util.tocompclass/package.json @@ -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"