From 1796735419d37914391a21f0db7590cb5865a757 Mon Sep 17 00:00:00 2001 From: Yu Date: Fri, 28 Dec 2018 07:48:42 +0800 Subject: [PATCH] feat: add umi-plugin-locale browser export (#1716) * feat: add umi-plugin-locale browser export * fix package.json --- packages/umi-plugin-locale/index.d.ts | 10 ++++++++++ packages/umi-plugin-locale/package.json | 6 +++++- packages/umi-plugin-locale/src/index.js | 2 ++ packages/umi-plugin-react/locale/index.d.ts | 3 +++ packages/umi-plugin-react/locale/index.js | 1 + packages/umi-plugin-react/package.json | 4 +++- 6 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 packages/umi-plugin-locale/index.d.ts create mode 100644 packages/umi-plugin-react/locale/index.d.ts create mode 100644 packages/umi-plugin-react/locale/index.js diff --git a/packages/umi-plugin-locale/index.d.ts b/packages/umi-plugin-locale/index.d.ts new file mode 100644 index 000000000000..9158992672c9 --- /dev/null +++ b/packages/umi-plugin-locale/index.d.ts @@ -0,0 +1,10 @@ +declare function setLocale(lang: string): void; +declare function getLocale(): string; +interface Params { + id: string; + defaultMessage?: string; +} +declare function formatMessage(params: Params, data?: Object): void; +declare const FormattedMessage: React.Component; + +export { setLocale, getLocale, formatMessage, FormattedMessage }; diff --git a/packages/umi-plugin-locale/package.json b/packages/umi-plugin-locale/package.json index cead3f982311..a420968ae085 100644 --- a/packages/umi-plugin-locale/package.json +++ b/packages/umi-plugin-locale/package.json @@ -3,6 +3,9 @@ "version": "2.3.0-beta.12", "description": "A umi plugin for provide internationalization function.", "main": "./lib/index.js", + "browser": { + "./lib/index.js": "./lib/locale.js" + }, "authors": [ "yutingzhao1991 (https://github.com/yutingzhao1991)" ], @@ -18,7 +21,8 @@ "files": [ "lib", "src", - "template" + "template", + "index.d.ts" ], "keywords": [ "umi" diff --git a/packages/umi-plugin-locale/src/index.js b/packages/umi-plugin-locale/src/index.js index 7dde13eeb911..8b50e547a4c3 100644 --- a/packages/umi-plugin-locale/src/index.js +++ b/packages/umi-plugin-locale/src/index.js @@ -151,6 +151,8 @@ export default function(api, options = {}) { ...memo, alias: { ...(memo.alias || {}), + // umi/locale is deprecated + // recommend use `import { getLocale } from 'umi-plugin-locale';` now. 'umi/locale': join(__dirname, './locale.js'), 'react-intl': dirname(require.resolve('react-intl/package.json')), }, diff --git a/packages/umi-plugin-react/locale/index.d.ts b/packages/umi-plugin-react/locale/index.d.ts new file mode 100644 index 000000000000..969ffa4f1981 --- /dev/null +++ b/packages/umi-plugin-react/locale/index.d.ts @@ -0,0 +1,3 @@ +import * as locale from "umi-plugin-locale"; + +export = locale; diff --git a/packages/umi-plugin-react/locale/index.js b/packages/umi-plugin-react/locale/index.js new file mode 100644 index 000000000000..6fde479e287d --- /dev/null +++ b/packages/umi-plugin-react/locale/index.js @@ -0,0 +1 @@ +module.exports = require('umi-plugin-locale'); diff --git a/packages/umi-plugin-react/package.json b/packages/umi-plugin-react/package.json index ae9904e5e4f8..d10867259923 100644 --- a/packages/umi-plugin-react/package.json +++ b/packages/umi-plugin-react/package.json @@ -15,7 +15,9 @@ }, "files": [ "lib", - "src" + "src", + "locale/index.js", + "locale/index.d.ts" ], "license": "MIT", "dependencies": {