@ diglot/ 代码
代码块注释提取 挖掘机。查找带有每个语言代号器的代码块的取词评论,将每个评论行变成一个 code-comment 段,并在应用翻译时仅替换注释文本.
pnpm add @diglot/code @diglot/core
使用量
import { applyCode, extractCode } from '@diglot/code'
const { segments } = extractCode(code, 'ts')
const { code: translated, report } = applyCode(code, 'ts', translations)
对于适配器:
findComments(code, language)返回时{ line, start, end, text }用于每条流言评论行,其中[start, end)代码中的文本commentDraft(comment, language, context)将注释转换为分区草稿;内置代码和 URL 成为占位符replaceComments(code, replacements)备注文本
支持的语言: JavaScript 和 TypeScript ()js, (中文(简体) ), ts, (中文(简体) ), jsx, (中文(简体) ), tsx, (中文(简体) ), mjs, (中文(简体) ), cjs),Vue和HTML(包括 <script> 财务报告和审定财务报表 <style> cSS、SCSS和Less,外壳(bash, (中文(简体) ), sh, (中文(简体) ), zsh),多滕夫和伊尼,YAML,TOML,JSON5和JSONC.
未取出:双斜线指令( S)// ^?, (中文(简体) ), // @errors, (中文(简体) ), // ---cut---),什基语注音(// [!code ++]),工具文件册(eslint-disable, (中文(简体) ), @ts-expect-error, (中文(简体) ), #region),评论出代码,并用不到两个字来评论.