Skip to content
| Marketplace
Sign in
Visual Studio Code>Snippets>i18next-auto-toolsNew to Visual Studio Code? Get it now.
i18next-auto-tools

i18next-auto-tools

zhaodekevin

|
37 installs
| (1) | Free
i18next-auto-tools
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

I18next Auto Tools

辅助 i18next 做国际化翻译的插件。更适合辅助老项目升级际化。通过配置语言和输出路径一键快捷键生成多个语言文件。

Features

常用代码片段:

ii18n: 快捷插入 i18next 模块 import { useTranslation } from 'react-i18next';

ti18n: 快捷引入 t 函数 const { t } = useTranslation();

以下为快捷键:

command+shift+i (MacOS) 替换选中文本为 t 函数包含花括号(DOM 中替换文本) {t('REPLACEMENT')}

ctrl+shift+i (windows) 替换选中文本为 t 函数包含花括号(DOM 中替换文本) {t('REPLACEMENT')}

shift+i (MacOS) 替换选中文本为 t 函数(函数中替换文本) t('REPLACEMENT')

shift+i (windows) 替换选中文本为 t 函数(函数中替换文本) t('REPLACEMENT')

command+i (MacOS) 替换选中文本为 t 函数(模版字符串中替换文本) ${t('REPLACEMENT')}

ctrl+i (windows) 替换选中文本为 t 函数(模版字符串中替换文本) ${t('REPLACEMENT')}

如何工作

  • 选中文字快捷键替换为 t 函数,自动翻译输出语言文件

注意 默认以选中文本为输入语言 json 文件的 key,默认翻译中文为其他语言

必要条件

工作区目录创建i18n.tools.config.json文件,并填写以下配置信息

{
  "languages": [
    {
      "code": "zh",
      "fileName": "zh.json"
    },
    {
      "code": "en",
      "fileName": "en.json"
    }
  ],
  "path": "./src/i18n/locales",
  "API_KEY": "**********",
  "SECRET_KEY": "**********",
  "domTemplate": "{t('REPLACEMENT')}",
  "$Template": "${t('REPLACEMENT')}",
  "functionTemplate": "t('REPLACEMENT')"
}

注意 languages 为语言列表,code 必须采用百度翻译对应国家编码,如 zh、en

注意 path 为语言文件输入路径,可以自定义

注意 API_KEY、SECRET_KEY 为百度翻译平台秘钥

注意 domTemplate、$Template、functionTemplate 可以修改自定义替换模版

Enjoy!

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft