Socket
Book a DemoInstallSign in
Socket

mute-english-api

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mute-english-api

提供英语词典和百度翻译等API服务的npm包,支持多种翻译服务集成

1.0.2
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Mute English API

🚀 一个功能丰富的npm包,提供英语词典查询和百度翻译等API服务,支持多种翻译服务集成。

✨ 功能特性

  • 📚 英语词典API - 免费的英语单词查询服务
  • 🌐 百度翻译API - 支持多语言翻译(需要百度API密钥)
  • 🔧 模块化架构 - 清晰的代码结构,易于扩展
  • ⚙️ 统一配置管理 - 支持环境变量和程序配置
  • 📦 批量操作 - 支持批量翻译和语言检测
  • 🔄 向后兼容 - 保持原有API接口不变

📦 安装

npm install mute-english-api

🚀 快速开始

英语词典查询(免费)

import { fetchTranslation, getWordMeaning } from 'mute-english-api';

// 基础词典查询
const data = await fetchTranslation('hello');
console.log(data);

// 获取详细释义
const meaning = await getWordMeaning('world');
if (meaning.success) {
    console.log(`${meaning.word}: ${meaning.meanings[0]?.definitions[0]?.definition}`);
}

百度翻译(需要API密钥)

import { setBaiduTranslateConfig, translateText, quickTranslate } from 'mute-english-api';

// 方式1: 设置配置后使用
setBaiduTranslateConfig('your_appid', 'your_key');
const result = await translateText('Hello World', 'en', 'zh');
console.log(result.translated); // 输出:你好世界

// 方式2: 一键翻译(推荐简单场景)
const quickResult = await quickTranslate('your_appid', 'your_key', 'Good morning!');
console.log(quickResult.translated); // 输出:早上好!

📋 完整API文档

英语词典API

fetchTranslation(word)

获取英语单词的完整词典数据。

参数:

  • word (string) - 要查询的英语单词

返回: Promise<Array> - 词典数据数组

getWordMeaning(word)

获取单词的结构化释义信息。

返回格式:

{
    success: boolean,
    word: string,
    phonetics: Array,
    meanings: Array,
    sourceUrls: Array
}

getWordPhonetics(word)

获取单词的发音信息。

百度翻译API

setBaiduTranslateConfig(appid, key)

设置百度翻译API配置。

参数:

  • appid (string) - 百度翻译API的APPID
  • key (string) - 百度翻译API的KEY

translateText(text, from, to)

翻译文本。

参数:

  • text (string) - 需要翻译的文本
  • from (string) - 源语言代码,默认'en'
  • to (string) - 目标语言代码,默认'zh'

返回格式:

{
    success: boolean,
    translated: string,
    data: Object,
    error?: string
}

batchTranslate(texts, from, to, delay)

批量翻译文本数组。

参数:

  • texts (Array) - 文本数组
  • from (string) - 源语言,默认'en'
  • to (string) - 目标语言,默认'zh'
  • delay (number) - 请求间隔(毫秒),默认1000

detectLanguage(text)

检测文本语言。

getSupportedLanguages()

获取支持的语言列表。

quickTranslate(appid, key, text, from, to)

一键设置配置并翻译。

⚙️ 配置管理

环境变量配置(推荐)

export BAIDU_TRANSLATE_APPID=your_appid
export BAIDU_TRANSLATE_KEY=your_key

设置环境变量后,无需调用 setBaiduTranslateConfig()

程序配置

import { configManager } from 'mute-english-api';

// 设置百度翻译配置
configManager.setBaiduTranslateConfig('appid', 'key');

// 自定义服务配置
configManager.setConfig('myService', {
    apiUrl: 'https://api.example.com',
    apiKey: 'my_key'
});

// 获取配置
const config = configManager.getConfig('myService');

📚 支持的语言

百度翻译支持以下语言:

代码语言代码语言
auto自动检测zh中文
en英语jp日语
kor韩语spa西班牙语
fra法语de德语
ru俄语it意大利语
pt葡萄牙语ara阿拉伯语

📁 项目结构

mute-english-api/
├── index.js                    # 主入口文件
├── src/
│   ├── config/
│   │   └── index.js            # 配置管理器
│   ├── services/
│   │   ├── baiduTranslate.js   # 百度翻译服务
│   │   └── dictionaryApi.js    # 英语词典服务
│   └── utils/
│       └── crypto.js           # 加密工具
├── examples/
│   └── usage.js                # 使用示例
├── test/
│   └── index.test.js           # 测试文件
└── package.json

🔧 高级用法

模块化导入

// 导入特定服务
import { baiduTranslateService } from 'mute-english-api/baidu-translate';
import { dictionaryService } from 'mute-english-api/dictionary';
import configManager from 'mute-english-api/config';

扩展其他翻译服务

import { configManager } from 'mute-english-api';

// 添加Google翻译配置
configManager.setConfig('googleTranslate', {
    apiKey: 'your_google_api_key',
    apiUrl: 'https://translation.googleapis.com/language/translate/v2'
});

🧪 运行示例

# 克隆项目
git clone https://github.com/czm233/mute-english-api.git
cd mute-english-api

# 安装依赖
npm install

# 运行示例(需要先设置百度API密钥)
node examples/usage.js

🔑 获取百度翻译API密钥

  • 访问 百度翻译开放平台
  • 注册账号并完成实名认证
  • 创建应用获取APPID和KEY
  • 通过环境变量或程序配置使用

📄 许可证

ISC License

🤝 贡献

欢迎提交Issue和Pull Request!

📞 联系方式

Keywords

translation

FAQs

Package last updated on 19 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.