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

module-translater

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

module-translater

这是一个npm工具包-自动翻译

  • 1.3.0
  • unpublished
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

module-translater

介绍

用于全局提取项目中文多语言,i8n 国际化翻译脚本。

安装
npm install module-translater --save-dev [-g]
参数详解
translater <env>  options

Arguments:
  env                        指定环境:dev(开发)/test(测试)/prod(生产),默认为开发环境

Options:
  -d, --dir <dir>            指定需翻译的文件夹
  -s, --suffix <value>       指定需翻译的文件名后缀
  -e, --excludes <value...>  指定不需要翻译的文件,可指定多个
  -o, --output <file>        指定输出翻译写入的文件路径,默认为跟目录下,支持js、json, 默认locals.json
  --strict                   是否严格模式, 严格模式只提取$t()内的中文,否则提取全局中文

备注:参数为 dev 是只生成翻译文件,test 是会为每个翻译文件生成后缀前加.lang 的文件,以便查看翻译后对照,prod 则会直接替换翻译原文件,用于生成部署。

自定义翻译字典

在跟目录创建translater.json文件,添加自定义翻译对照,遇到相同中文则会使用指定的 key,适用于高频率出现需要的翻译 如:

{
    "com_yes": "是",
    "com_no": "否",
    "com_success": "成功",
    "com_fail": "失败",
    "com_enable": "启用",
    "com_disable": "禁用",
    "com_confirm": "确定",
    "com_cancel": "取消",
    "com_add": "新增",
    "com_edit": "编辑",
    "com_modify": "修改",
    "com_delete": "删除",
    "com_save": "保存",
    "com_handle": "操作",
    "com_action": "操作"
}    
执行翻译

全局安装

translater --help  // 帮助文档

translater dev --dir src --suffix .vue --excludes test.vue app.vue -o locals/local.json --strict  // 翻译

非全局安装在项目package.json中添加如下

  "scripts": {
    "translater": "translater dev -dir src -suffix .vue",
    "translater:test": "translater test --dir src --suffix .vue --strict",
    "translater:prod": "translater prod --dir src --suffix .vue --strict"
  },

Keywords

FAQs

Package last updated on 12 Apr 2024

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