npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-plugin-lp-react-intl

v1.0.7

Published

让你的 React 项目国际化更轻松! 自动提取中文、插入国际化代码,并与 react-intl 无缝集成。开发者的福音!✨

Downloads

399

Readme

🌟 vite-plugin-babel-react-intl

让你的 React 项目国际化更轻松!
自动提取中文、插入国际化代码,并与 react-intl 无缝集成。开发者的福音!✨

🚀 vite-plugin-lp-react-intl 是一个 Vite 插件,用于自动化国际化处理,通过 Babel 插件将项目中的中文内容提取并转化为国际化代码。

✨ 特性

  • 📦 自动检测项目中的中文文案。
  • 🌍 将中文文案替换为 react-intlformatMessage 调用。
  • 📂 支持 TypeScript 和 JSX/TSX 文件。
  • 🛠 可自定义文件过滤规则。

🛠 安装

# 使用 npm
npm install vite-plugin-lp-react-intl --save-dev

# 或者使用 yarn
yarn add vite-plugin-lp-react-intl --dev

# 或者使用 pnpm
pnpm add vite-plugin-lp-react-intl --save-dev

⚡ 快速开始

1. 配置 Vite 插件

vite.config.ts 中添加插件配置:

import { defineConfig } from "vite";
import vitePluginLpReactIntl from "vite-plugin-lp-react-intl";

export default defineConfig({
  plugins: [
    vitePluginLpReactIntl({
      include: ["src/**/*.{js,jsx,ts,tsx}"], // 可选:包含某些文件
      exclude: ["src/excluded/**"], // 可选:排除某些文件
    }),
  ],
});

2. 使用效果

在你的项目中,当你运行 Vite 开发服务器时,插件会自动将如下代码:

export default function App() {
  return <div>你好,世界!</div>;
}

转换为:

import { defineMessages } from "react-intl";
import intl from "src/locales/intl";

const messages = defineMessages({
  helloWorld: { id: "你好,世界!" },
});

export default function App() {
  return <div>{intl.formatMessage(messages.helloWorld)}</div>;
}

⚙️ 配置选项

| 参数 | 类型 | 默认值 | 说明 | | ------------ | -------------- | ----------------- | -------------------------------- | | include | string[] | ["src/**/*.{js,jsx,ts,tsx}"] | 包含某些文件或路径 | | exclude | string[] | [] | 排除某些文件或路径 |

🤖 支持的文件类型

  • .js
  • .jsx
  • .ts
  • .tsx

📄 开发者提示

  • 确保你的项目中已经安装了 react-intl
  • ⚡ 建议通过 lp-react-intl-cli 生成 src/locales文件夹和 src/locales/intl.ts 文件。并通过 lp-react-intl-cli extract src命令提取src目录下的所有文件中的中文内容到json文件中。
  • 通过 vitePluginLpReactIntl 的配置项 include 可指定需要国际化的文件。
  • 通过 vitePluginLpReactIntl 的配置项 exclude 可排除不需要国际化的文件。

🤝 贡献

欢迎贡献代码或提需求!请访问 GitHub 仓库 开启 Issue 或提交 PR。

📄 License

MIT © 刘鹏