diff --git a/package-lock.json b/package-lock.json index 89eaaf7..b163679 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2936,6 +2936,15 @@ } } }, + "@rollup/plugin-json": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-4.0.3.tgz", + "integrity": "sha512-QMUT0HZNf4CX17LMdwaslzlYHUKTYGuuk34yYIgZrNdu+pMEfqMS55gck7HEeHBKXHM4cz5Dg1OVwythDdbbuQ==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^3.0.8" + } + }, "@rollup/plugin-node-resolve": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-7.1.3.tgz", diff --git a/package.json b/package.json index 42c6953..c16c360 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "@babel/preset-react": "^7.9.4", "@babel/preset-typescript": "^7.9.0", "@rollup/plugin-commonjs": "^11.0.2", + "@rollup/plugin-json": "^4.0.3", "@rollup/plugin-node-resolve": "^7.1.3", "@rollup/plugin-strip": "^1.3.2", "@rollup/plugin-url": "^4.0.2", diff --git a/packages/json-schema-editor/src/i18n/index.ts b/packages/json-schema-editor/src/i18n/index.ts index c1f896e..d8637b1 100644 --- a/packages/json-schema-editor/src/i18n/index.ts +++ b/packages/json-schema-editor/src/i18n/index.ts @@ -10,6 +10,8 @@ i18n resources: { en, zh, + 'en-US': en, + 'zh-CN': zh, }, keySeparator: false, // we do not use keys in form messages.welcome interpolation: { diff --git a/packages/json-schema-editor/src/i18n/translations/en.json b/packages/json-schema-editor/src/i18n/translations/en.json index 399a52d..323faf1 100644 --- a/packages/json-schema-editor/src/i18n/translations/en.json +++ b/packages/json-schema-editor/src/i18n/translations/en.json @@ -1,3 +1,5 @@ { - "home": "home" + "translation": { + "import_json": "Import JSON" + } } diff --git a/packages/json-schema-editor/src/i18n/translations/zh.json b/packages/json-schema-editor/src/i18n/translations/zh.json index c218cee..33820fa 100644 --- a/packages/json-schema-editor/src/i18n/translations/zh.json +++ b/packages/json-schema-editor/src/i18n/translations/zh.json @@ -1,3 +1,5 @@ { - "home": "首页" + "translation": { + "import_json": "导入 JSON" + } } diff --git a/packages/json-schema-editor/src/index.tsx b/packages/json-schema-editor/src/index.tsx index 524a3cb..eed07cf 100644 --- a/packages/json-schema-editor/src/index.tsx +++ b/packages/json-schema-editor/src/index.tsx @@ -1,16 +1,36 @@ /** @jsx jsx */ -import { jsx } from '@emotion/core'; +import { useEffect } from 'react'; +import { Global, jsx, css } from '@emotion/core'; import { Button } from 'antd'; import { useTranslation } from 'react-i18next'; -import i18n from './i18n'; +import './i18n'; -i18n.changeLanguage('en'); +interface EditorProps { + lang?: string; +} + +function JsonSchemaEditor({ lang }: EditorProps): JSX.Element { + const { t, i18n } = useTranslation(); + + useEffect(() => { + if (!lang) return; + i18n.changeLanguage(lang); + }, [i18n, lang]); -function JsonSchemaEditor(): JSX.Element { - const { t } = useTranslation(); return ( -