@aplus-frontend/translate-utils
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@aplus-frontend/translate-utils

一个翻译工具函数库。支持有道,谷歌,百度。

install

pnpm i @aplus-frontend/translate-utils

api

googleTranslate

interface GoogleOption {
  word: string // 待翻译文本
  originLang: string // 源语言
  targetLang: string // 目标语言
  proxy: string | undefined // 代理地址
}

declare function googleTranslate(option: GoogleOption): Promise<string>

例子

const res = await googleTranslate({
  word: '翻译内容',
  originLang: 'zh-CN',
  targetLang: 'en-US',
  proxy: 'socks://127.0.0.1:1080',
})

youdaoTranslate

interface YoudaoConfig {
  key?: string // 有道词典appKey
  secret?: string // 有道词典appSecret
}

interface YoudaoOption {
  word: string // 待翻译文本
  originLang: string // 源语言
  targetLang: string // 目标语言
  option: YoudaoConfig // 有道词典配置
}

declare function youdaoTranslate(option: YoudaoOption): Promise<string>

例子

const res = await youdaoTranslate({
  word: '翻译内容',
  originLang: 'zh-CN',
  targetLang: 'en-US',
  option: {
    key: '2d8e89a6fd072117',
    secret: 'HiX7rGmYRad3ISMLYexRLfpkJi2taMPh',
  },
})

baiduTranslate

interface BaiduConfig {
  key?: string
  secret?: string
}

interface BaiduOption {
  word: string // 待翻译文本
  originLang: string // 源语言
  targetLang: string // 目标语言
  option: BaiduConfig // 有道词典配置
}

declare function baiduTranslate(option: YoudaoOption): Promise<string>

例子

const res = await baiduTranslate({
  word: '翻译内容',
  originLang: 'zh-CN',
  targetLang: 'en-US',
  option: {
    key: '2d8e89a6fd072117',
    secret: 'HiX7rGmYRad3ISMLYexRLfpkJi2taMPh',
  },
})

Readme

Keywords

Package Sidebar

Install

npm i @aplus-frontend/translate-utils

Weekly Downloads

0

Version

1.0.0

License

Apache-2.0

Unpacked Size

21.1 kB

Total Files

6

Last publish

Collaborators

  • alanreumy
  • lonelyfkinging
  • huimin2000
  • hemuxue
  • kuguago
  • orange1992
  • zxlin429
  • huaz
  • rainiexxx
  • asd517665931
  • limoer
  • ollieliu