Package Exports
- @lzy1960/google-translate
- @lzy1960/google-translate/dist/index.cjs.js
- @lzy1960/google-translate/dist/index.esm.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@lzy1960/google-translate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
google-translate
一款谷歌翻译api的插件
项目说明
- TDD 开发流程
- 使用 ts 编写
- 集成 vitest 测试
使用方式
安装依赖包
npm i @lzy1960/google-translate // OR yarn add @lzy1960/google-translate // OR pnpm i @lzy1960/google-translate
调用
// default options const options = { from: 'auto', to: 'en', tld: 'com', type: 'default' } const res = await translate('你好', options) console.log(res) // { "from": "zh-CN", "pronunciation": "Nǐ hǎo", "text": "Hello" }
入参说明
translate接收两个参数:text 和 optionsoptions 默认为:
{ from: 'auto', // 源语言 to: 'en', // 目标语言 tld: 'com', // 服务地址 type: 'default', // 类型 'default' / 'word' isMobile: false // TODO:是否是移动端(移动端和pc端的返回值不一样) }
返回结果说明
// default { from: "zh-CN", // 源语言 pronunciation: "Nǐ hǎo", // 读音 text: "Hello" // 目标语言结果 } // word { text: '你好!', common: [ { type: '感叹词', words: [ { word: 'Hello!', explains: ['你好!', '喂!'], frequency: 1, }, { word: 'Hi!', explains: ['嗨!', '你好!'], frequency: 1, }, { word: 'Hallo!', explains: ['你好!'], frequency: 3, }, ], }, ], }
options 参数说明
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| from | 源语言 | string | 'auto' |
| to | 目标语言 | string | 'en' |
| tld | 地区 | string | 'com' |
| type | 类型 | default | word |
'default' |
| proxy | 代理地址 | string | -- |