Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-i18n-helper

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-i18n-helper

- 自动查找 包含中文 的字符串和模板字符串,并替换为自定义的国际化方法

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

vite-plugin-i18n-helper

简介

  • 自动查找 包含中文 的字符串和模板字符串,并替换为自定义的国际化方法

安装

node version: >=12.0.0

vite version: >=2.0.0

npm i vite-plugin-i18n-helper -D
# or
yarn add vite-plugin-i18n-helper -D
# or
pnpm install vite-plugin-i18n-helper -D

使用

  • vite.config.ts 中的配置插件
import i18nHelperPlugin from 'vite-plugin-i18n-helper'
import path from 'path'
export default () => {
  return {
    plugins: [
      i18nHelperPlugin({
        includes: ["src/*"],
        exclude: ["node_modules/*", "src/i18n.js"],
        customI18n: "i18nHepler",
        customI18nUrl: "/src/i18n",
        dictJson: path.resolve(__dirname, "./src/dict.json"),
        raw: true,
      }),
    ],
  }
}

示例

// 原始代码
const fn = (val) => "(" + val + ")";
const name1 = "一二三";
const name2 = `一二三${name1}`;
const name3 = `${name1}一二三${fn(name1)}`;
const name4 = "1" + "2" + "三";
const name5 = "i18n!:一二三";
const name6 = "    一二三   ";
  • 无 dictJson 参数时 会 转义所有包含中文的字符
// 处理后结果
import {i18nHepler} from "/src/i18n.js"
const fn = (val) => "(" + val + ")";
const name1 = i18nHepler("一二三");
const name2 = i18nHepler("一二三{0}",[name1]);
const name3 = i18nHepler("{0}一二三{1}",[name1,fn(name1)]);
const name4 = "1" + "2" + i18nHepler("三");
const name5 = "一二三";
const name6 = `    ${i18nHepler("一二三")}   `;
  • 有 dictJson 参数时 会 转义 dictJson 中匹配到的字符
json 内容
{
  "一二三": "123",
  "一二三{0}": "123{0}",
  "{0}一二三{1}": "{0}123{1}"
}
// 处理后结果
import {i18nHepler} from "/src/i18n.js"
const fn = val => '(' + val + ')';
const name1 = i18nHepler("123",null,"一二三");
const name2 = i18nHepler("123{0}",[name1],"一二三{0}");
const name3 = i18nHepler("{0}123{1}",[name1,fn(name1)],"{0}一二三{1}");
const name4 = "1" + "2" + "三";
const name5 = "一二三";
const name6 = `    ${i18nHepler("123",null,"一二三")}   `;

参数说明

参数类型默认值必填说明
customI18nstring-自定义 i18n 方法
customI18nUrlstring-自定义i8n 方法导入地址
dictJsonstring[]-匹配字典
includesArray<string|RegExp>|string|RegExp-匹配文件规则
excludeArray<string|RegExp>|string|RegExp-忽略文件规则
ignoreMarkstringi18n!:忽略以该标识开头的内容
rawboolean-是否保留 dictJson 匹配前的 原始值 (是 将作为customI18n 第三个参数传入)
outputboolean-是否输出字符串处理的结果

辅助功能

  • 查看替换字符串
    • ip + 端口 + '/virtual:i18n-helper/result' (例如 http://127.0.0.1:5173/virtual:i18n-helper/result)
    • 绿色已完成替换 橙色 未完成
  • 构建时输出替换结果
    • 设置 output:true 会输出 _i18n_helper_result.html 文件

FAQs

Package last updated on 05 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc