Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yxw007/translate
🎉一个简单的翻译库,支持多翻译引擎。A simple translation library that supports multiple translation engines
https://github.com/yxw007/translate
amazon azure baidu browser cjs deepl ems google i18n nodejs translate translator typescript
Last synced: 3 months ago
JSON representation
🎉一个简单的翻译库,支持多翻译引擎。A simple translation library that supports multiple translation engines
- Host: GitHub
- URL: https://github.com/yxw007/translate
- Owner: yxw007
- License: mit
- Created: 2024-08-27T03:30:43.000Z (5 months ago)
- Default Branch: master
- Last Pushed: 2024-11-03T11:38:49.000Z (3 months ago)
- Last Synced: 2024-11-03T12:24:56.342Z (3 months ago)
- Topics: amazon, azure, baidu, browser, cjs, deepl, ems, google, i18n, nodejs, translate, translator, typescript
- Language: TypeScript
- Homepage:
- Size: 184 KB
- Stars: 12
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Translate
English | [简体中文](./README_zh-CN.md)
![GitHub top language](https://img.shields.io/github/languages/top/yxw007/translate)
![GitHub License](https://img.shields.io/github/license/yxw007/translate)
![NPM Version](https://img.shields.io/npm/v/%40yxw007%2Ftranslate)
![Codecov](https://codecov.io/gh/yxw007/translate/branch/master/graph/badge.svg)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/yxw007/translate/ci.yml)## ❓ Why do I need translate?
1. a lot of translation tool libraries on the market, basically not very well-maintained
2. not written by ts, not friendly enough when using the prompts
3. single function, does not support batch translation Or only support a translation engine
4. ...> Note: Translate helps you to solve all the above problems, and will expand more in the future!
## ✨ Features
- 🌐 **Multi-environment support**: Node environment, browser environment
- ✨ **Easy to use**: provides a concise API, you can easily help you to translate
- 🌍 **Multi-translation engine support**: Google, Azure Translate, etc. (will expand more in the future)
- 🛠️ **typescript**: friendlier code hints and quality assurance
- 📦 **Batch translation**: one api request, translate more content, reduce http requests to improve translation efficiency
- 🔓 **completely open source**.## 💻Translation engines, integration cases
| Name | Support | Description |
| ---------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| google | √ | Commissioned and ready for use |
| azure translate | √ | Commissioned and ready for use |
| amazon translate | √ | Commissioned and ready for use |
| baidu | √ | Commissioned and ready for use |
| deepl | √ | Commissioned and ready for use |
| yandex | | I have not tuned in as I do not have a bank account supported by the platform (help from those who are in a position to do so is welcome and appreciated) |## 🚀 Install
- npm
```bash
npm install @yxw007/translate
```- yarn
```bash
yarn add @yxw007/translate
```- pnpm
```bash
pnpm i @yxw007/translate
```## 📖 Usage
### Node
- ESM
```typescript
import { translator, engines } from "@yxw007/translate"
```- Commonjs
```typescript
const { translator, engines } = required("@yxw007/translate")
```- example
```typescript
translator.use(engines.google());
const res1 = await translator.translate("hello", { from: "en", to: "zh" });
console.log(res1);const res2 = await translator.translate(["hello", "good"], { from: "en", to: "zh", engine: "google" });
console.log(res2);
```输出结果
```bash
['你好']
["你好", "好的"]
```### Browser
use jsDelivr CDN
- `development`
```html
```
- `production````html
```- example
```html
...
...
(async () => {
const { engines, translator } = translate;
translator.use(engines.google());
const res = await translator.translate("hello", { from: "en", to: "zh" });
console.log(res);
})();