@rmw/markdown-translate

0.0.5 • Public • Published

@rmw/markdown-translate

说明

市面上的 markdown 翻译工具都有问题,不好用。

比如用 menthays/markdown-translator 翻译 markdown 文本,会把

对 [libmdbx](https://github.com/erthink/libmdbx) 的 rust 封装

翻译成

Right [libmdbx](https://github.com/erthink/libmdbx) The rust package of

原因是它把文本拆分为 { text: '对 ' },{ text: 'libmdbx' },{ text: ' 的 rust 封装' }分开去翻译。

而用另外一些,比如bilingual ,又不能保持链接的样式。

我写的 @rmw/markdown-translate 解决了一系列问题,并且支持

  • 翻译 rust 代码的注释文本
  • 不翻译 vuepress 中的配置字段

安装

yarn add @rmw/markdown-translate 或者 npm install @rmw/markdown-translate

使用

翻译需要 AZURE 的翻译接口,请先去 AZURE 创建“翻译”资源 ,配置中的 keyregion都来自这里,如下图。

用法演示如下 :

#!/usr/bin/env coffee

import translate from '@rmw/markdown-translate'
import {readFileSync} from 'fs'
import {homedir} from 'os'
import {join} from 'path'

# config file like { key: 'xxx', region: 'japaneast' }
config = JSON.parse readFileSync(join(homedir(), '.config/markdown-translate.json'),"utf8")

md = """
---

next: /日志/2020-11-29

---

上面的是博客配置,会不翻译

可以翻译[带有连接的文本](https://rmw.link)

程序人生 :

> 路漫漫其修远兮,
> 吾将上下而求索。

internal/main/run_main_module

\```rust
// 可以翻译rust的代码注释
/*
可以翻译
多行注释
*/
let s  = "字符串中的文本不会翻译 https://阿里巴巴.com";
\```

对 [libmdbx](https://github.com/rmw-lib/mdbx) 的封装
"""

console.log await translate(
  md
  {
    from : 'zh-Hans'
    to: "en-us"
    ...config
  }
)

运行后输出如下

关于

本项目隶属于人民网络(rmw.link) 代码计划。

人民网络

Readme

Keywords

none

Package Sidebar

Install

npm i @rmw/markdown-translate

Weekly Downloads

1

Version

0.0.5

License

AGPL

Unpacked Size

17.9 kB

Total Files

5

Last publish

Collaborators

  • gcxfd