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

@sunly95/unplugin-i18n-translation

v0.1.0

Published

A auto translate i18n files for unified plugin

Downloads

2

Readme

unplugin-i18n-translation

简体中文 | English

介绍

一个支持多打包工具的自动翻译国际化文件的插件,使用 unplugin 支持ViteWebpackRollupESBuildRspack等打包工具

将国际化插件的本地语言文件翻译并生成其它语言的翻译文件

Vue2项目推荐使用vue-18n

Vue3项目推荐使用vue-i18n-next

在线翻译由 腾讯机器翻译 提供

必需

在使用之前请确保已经安装并配置了国际化插件(比如vue-18n),而且已经有一个默认语言的本地化文件作为翻译的源文件

此外,还需要申请一个腾讯云API密匙

安装

# npm
npm install @sunly95/webpack-plugin-translation --save-dev

# yarn
yarn add @sunly95/webpack-plugin-translation --dev

使用

webpack

webpack.config.js中配置插件,传入的配置参数详情见配置

// webpack.config.js

// 引入插件
const { UnpluginAutoTranslation } = require("@sunly95/unplugin-i18n-translation");

module.exports = {
  plugins: [
    // 注册插件
    UnpluginAutoTranslation.webpack({
      id: secretId, // 腾讯云API密钥ID
      key: secretKey,  // 腾讯云API密钥Key
      originLang: "zh",  // 源语言
      targetLangs: [
        { lang: "en", filename: "en-US" },
      ], // 要翻译的语言列表
      originFilePath: "./src/locales/zh-CN.json", // 翻译原始文本文件,即vue-i18n的本地化文件
      targetDirPath: "./src/locales"  // 翻译后的文件存放目录
    })
  ]
}

vue-cli

vue.config.js中配置插件,传入的配置参数详情见配置

// vue.config.js

// 引入插件
const { UnpluginAutoTranslation } = require("@sunly95/unplugin-i18n-translation");

module.exports = {
  // 注册插件
  config.plugin("AutoTranslation").use(
    UnpluginAutoTranslation.webpack({
      id: secretId, // 腾讯云API密钥ID
      key: secretKey,  // 腾讯云API密钥Key
      originLang: "zh",  // 源语言
      targetLangs: [
        { lang: "en", filename: "en-US" },
      ], // 要翻译的语言列表
      originFilePath: "./src/locales/zh-CN.json", // 翻译原始文本文件,即vue-i18n的本地化文件
      targetDirPath: "./src/locales"  // 翻译后的文件存放目录
    })
  );
}

Vite

vite.config.js中配置插件,传入的配置参数详情见配置

// vite.config.js

// 引入插件
import { UnpluginAutoTranslation } from "@sunly95/unplugin-i18n-translation";

export default defineConfig({
  plugins: [
    UnpluginAutoTranslation.vite({
      id: secretId, // 腾讯云API密钥ID
      key: secretKey,  // 腾讯云API密钥Key
      originLang: "zh",  // 源语言
      targetLangs: [
        { lang: "en", filename: "en-US" },
      ], // 要翻译的语言列表
      originFilePath: "./src/locales/zh-CN.json", // 翻译原始文本文件,即vue-i18n的本地化文件
      targetDirPath: "./src/locales"  // 翻译后的文件存放目录
    })
  ]
});

配置完成后,在打包时会自动读取originFilePath指定的文件作为翻译的原始文本,根据传入的targetLangs自动翻译并生成翻译文件,存放在targetDirPath指定的目录下

配置

| 参数 | 类型 | 是否必需 | 说明 | | -------------- | ------------------------------------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | id | string | ✅ | 腾讯云API密匙ID | | key | string | ✅ | 腾讯云API密匙key | | originLang | string | ✅ | 原始翻译文本语言,取值见输入参数的Source字段 | | targetLangs | { lang: string, filename: string }[] | ✅ | 需要翻译成的目标语言列表,lang字段表示要翻译成的语言,取值见输入参数的Target字段filename字段表示翻译后生成的i18n文件的文件名 | | originFilePath | string | ✅ | 原始翻译文本的绝对路径 | | targetDirPath | string | ✅ | 翻译后生成的目标翻译文件的存储目录 | | spaceWidth | number? | | 翻译后后生成的json文件的缩进空格数,默认为2 |

更新日志

CHANGELOG