Browse Source

feat: 添加 i18n

master
suanmei 5 years ago
committed by 拾邑
parent
commit
de4a5c5849
  1. 9
      package-lock.json
  2. 1
      package.json
  3. 2
      packages/json-schema-editor/src/i18n/index.ts
  4. 4
      packages/json-schema-editor/src/i18n/translations/en.json
  5. 4
      packages/json-schema-editor/src/i18n/translations/zh.json
  6. 34
      packages/json-schema-editor/src/index.tsx
  7. 2
      rollup.config.js

9
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": { "@rollup/plugin-node-resolve": {
"version": "7.1.3", "version": "7.1.3",
"resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-7.1.3.tgz", "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-7.1.3.tgz",

1
package.json

@ -16,6 +16,7 @@
"@babel/preset-react": "^7.9.4", "@babel/preset-react": "^7.9.4",
"@babel/preset-typescript": "^7.9.0", "@babel/preset-typescript": "^7.9.0",
"@rollup/plugin-commonjs": "^11.0.2", "@rollup/plugin-commonjs": "^11.0.2",
"@rollup/plugin-json": "^4.0.3",
"@rollup/plugin-node-resolve": "^7.1.3", "@rollup/plugin-node-resolve": "^7.1.3",
"@rollup/plugin-strip": "^1.3.2", "@rollup/plugin-strip": "^1.3.2",
"@rollup/plugin-url": "^4.0.2", "@rollup/plugin-url": "^4.0.2",

2
packages/json-schema-editor/src/i18n/index.ts

@ -10,6 +10,8 @@ i18n
resources: { resources: {
en, en,
zh, zh,
'en-US': en,
'zh-CN': zh,
}, },
keySeparator: false, // we do not use keys in form messages.welcome keySeparator: false, // we do not use keys in form messages.welcome
interpolation: { interpolation: {

4
packages/json-schema-editor/src/i18n/translations/en.json

@ -1,3 +1,5 @@
{ {
"home": "home" "translation": {
"import_json": "Import JSON"
}
} }

4
packages/json-schema-editor/src/i18n/translations/zh.json

@ -1,3 +1,5 @@
{ {
"home": "首页" "translation": {
"import_json": "导入 JSON"
}
} }

34
packages/json-schema-editor/src/index.tsx

@ -1,16 +1,36 @@
/** @jsx jsx */ /** @jsx jsx */
import { jsx } from '@emotion/core'; import { useEffect } from 'react';
import { Global, jsx, css } from '@emotion/core';
import { Button } from 'antd'; import { Button } from 'antd';
import { useTranslation } from 'react-i18next'; 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 ( return (
<div> <div
<Button>{t('home')}</Button> css={css`
padding: 5px;
`}
>
<Global
styles={css`
* {
font-size: 12px;
}
`}
/>
<Button type="primary">{t('import_json')}</Button>
</div> </div>
); );
} }

2
rollup.config.js

@ -2,6 +2,7 @@ import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs'; import commonjs from '@rollup/plugin-commonjs';
import strip from '@rollup/plugin-strip'; import strip from '@rollup/plugin-strip';
import url from '@rollup/plugin-url'; import url from '@rollup/plugin-url';
import json from '@rollup/plugin-json';
import babel from 'rollup-plugin-babel'; import babel from 'rollup-plugin-babel';
import svgr from '@svgr/rollup'; import svgr from '@svgr/rollup';
import { sizeSnapshot } from 'rollup-plugin-size-snapshot'; import { sizeSnapshot } from 'rollup-plugin-size-snapshot';
@ -14,6 +15,7 @@ export default {
plugins: [ plugins: [
resolve({ extensions, preferBuiltins: true }), resolve({ extensions, preferBuiltins: true }),
commonjs(), commonjs(),
json(),
babel({ babel({
extensions, extensions,
exclude: 'node_modules/**', exclude: 'node_modules/**',

Loading…
Cancel
Save