Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>i18n-overseasNew to Visual Studio Code? Get it now.
i18n-overseas

i18n-overseas

i18n-overseas

|
15 installs
| (0) | Free
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

i18n-overseas README

Features

  • 识别项目中的 Hard Code(需要被翻译的内容)

  • 黑白名单纠错机制

  • 一键转换 Hard Code 为国际化标识

  • 自动生成国际化的 key

插件介绍

背景

针对已有/新建项目,存在多语言内容需要被翻译,常规流程是逐个找到需要被翻译的内容,替换为国际化标识如 $t('key'),并在 locales 语言包中新增相应的 key 和文案,人工查找替换较为困难,费时费力且容易错漏。当前插件可以辅助查找 hard code 以及一键写入 key 到语言包中。

使用

使用插件之前需插件处于 visible 状态

在侧边栏 treeview 可以看见三个菜单,显示当前文件的检测结果

  • 待翻译的 Hard Code
  • Hard Code 黑名单
  • Hard Code 白名单 点击的子菜单,可以跳转到项目中对应的位置

插件面板

插件图标

Hard Code 检测规则

  • 变量/对象属性默认为非 hard code
    • 当变量名/对象属性等于 title、message、description 时,识别为 hard code
  • 对象属性默认非 hard cod,
    • 对象属性名包含 title、message、description 时,识别为 hard code
    • 对象属性等于 label,识别为 hard code
  • 模板字符串,其他规则同上变量
    • 但不识别拥有国际化标识的部分,即使变量名等于 title 时
  • JSX 组件属性默认非 hard code
    • 当属性名包含 title、message、description、text、tips 时,识别为 hard code
    • 当属性名等于 title 时,识别为 hard code
  • JSXText 默认识别为 hard code
    • 当只包含非语言字符时,如 &¥,识别为非 hard code
  • 函数参数、return 返回值、JSX Children 中的表达式,都默认识别为 hard code
    • 以下场景识别为非 hard code
      • 函数名等于 console、require、import
      • 只含非语言字符如&¥
      • 只含数字
      • 只含字母和下划线,且中间至少含有一个下划线"_"
      • 只含小写字母、数字、"."、"_"、"-"
      • 只含大写字母、数字、"."、"_"、"-"
      • 内容为小驼峰
  • 其他未覆盖的场景,均默认不识别
    • 内容包含中文时,识别为 hard code

黑名单

在检测 Hard Code 出现错误时,鼠标悬浮在”错误“ Hard Code 上,点击快速修复,选择"该内容不需要翻译,添加黑名单"

白名单

在检测 Hard Code 出现错误时,鼠标划选代码(字符串、模板字符串需要包含引号),点击将 [''] 标记为 Hard Code,选择 hard code 的场景类型

场景类型说明:

  • js-string

    • 普通字符串如"name",或模板字符串name{value}
  • jsx-attribute-string

    • 第一行为 jsx-attribute-string,第二行为普通字符串 js-string

      <button title="name"></button>   √
      <button title={"name"}></button> ×
      
  • jsx-text

    • jsx 组件中的 children 文本,第一行为 jsx-text,第二行为普通字符串 js-string

      <button>name</button>     √
      <button>{"name"}</button> ×
      

插件指令

插件配置

{
  "i18n-overseas.rules.detectVariableIdContain": {
    "type": "array",
    "default": [],
    "description": "检测规则,当变量包含关键字时识别为 hard code"
  },
  "i18n-overseas.localesPath": {
    "type": "string",
    "default": "",
    "description": "存放语言包 locales 的路径"
  },
  "i18n-overseas.sourceLanguage": {
    "type": "string",
    "default": "zh-CN",
    "description": "设置语言来源,设置后转换 hard code 自动将 key 填入该语言包"
  },
  "i18n-overseas.internationalizationID": {
    "type": "string",
    "default": "formatMessage",
    "description": "国际化标识"
  },
  "i18n-overseas.detectRules": {
    "type": "object",
    "properties": {
      "ObjectPropertyOnly": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "ObjectPropertyInclude": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "ObjectPropertyExclude": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "ObjectPropertyExcludeOnly": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "VariableIdentifierOnly": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "VariableIdentifierInclude": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "VariableIdentifierExclude": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "VariableIdentifierExcludeOnly": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "JsxAttributeOnly": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "JsxAttributeInclude": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "FunctionNameOnly": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "FunctionNameInclude": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "FunctionNameExclude": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "FunctionNameExcludeOnly": {
        "type": "array",
        "items": {
          "type": "string"
        }
      }
    },
    "default": {},
    "description": "国际化标识"
  }
}
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft