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": {
"version": "7.1.3",
"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-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",

2
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: {

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 */
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 (
<div>
<Button>{t('home')}</Button>
<div
css={css`
padding: 5px;
`}
>
<Global
styles={css`
* {
font-size: 12px;
}
`}
/>
<Button type="primary">{t('import_json')}</Button>
</div>
);
}

2
rollup.config.js

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

Loading…
Cancel
Save