Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lzy1960/google-translate
Translate api for Google Translate
https://github.com/lzy1960/google-translate
google rollup tdd translate typescript vitest
Last synced: about 2 months ago
JSON representation
Translate api for Google Translate
- Host: GitHub
- URL: https://github.com/lzy1960/google-translate
- Owner: lzy1960
- License: mit
- Created: 2022-06-28T08:50:32.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-15T06:05:01.000Z (10 months ago)
- Last Synced: 2024-03-16T06:41:53.990Z (10 months ago)
- Topics: google, rollup, tdd, translate, typescript, vitest
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@lzy1960/google-translate
- Size: 301 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
google-translate
一款谷歌翻译api的插件
[![NPM version][npm-image]][npm-url] [![NPM downloads][download-image]][download-url] [![codecov][codecov-image]][codecov-url]
[![Maintainability][maintainability-image]][maintainability-url][npm-image]: http://img.shields.io/npm/v/@lzy1960/google-translate.svg
[npm-url]: http://npmjs.org/package/@lzy1960/google-translate
[download-image]: https://img.shields.io/npm/dm/@lzy1960/google-translate.svg
[download-url]: https://npmjs.org/package/@lzy1960/google-translate
[codecov-image]: https://codecov.io/gh/lzy1960/google-translate/branch/main/graph/badge.svg?token=O686OAR35N
[codecov-url]: https://codecov.io/gh/lzy1960/google-translate
[maintainability-image]: https://api.codeclimate.com/v1/badges/185da742ecab918b1a57/maintainability
[maintainability-url]: https://codeclimate.com/github/lzy1960/google-translate/maintainability
[oscs-image]: https://www.oscs1024.com/platform/badge/lzy1960/google-translate.svg?size=small
[oscs-url]: https://www.oscs1024.com/project/lzy1960/google-translate?ref=badge_small[![OSCS Status][oscs-image]][oscs-url]
感谢开源社区 OSCS 的关注!
## 项目说明
- TDD 开发流程
- 使用 ts 编写
- 集成 vitest 测试## 使用方式
1. 安装依赖包
```JS
npm i @lzy1960/google-translate
// OR
yarn add @lzy1960/google-translate
// OR
pnpm i @lzy1960/google-translate
```2. 调用
```JS
// 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" }
```3. 入参说明
`translate`接收两个参数:text 和 options
options 默认为:
```JS
{
from: 'auto', // 源语言
to: 'en', // 目标语言
tld: 'com', // 服务地址
type: 'default', // 类型 'default' / 'word'
isMobile: false // TODO:是否是移动端(移动端和pc端的返回值不一样)
}
```4. 返回结果说明
```JS
// 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 | 'cn' |
| type | 类型 | `default` \| `word` | 'default' |