@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
secret?: string
}
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',
},
})