npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lmk123/free-microsoft-translator

v0.0.1

Published

A browser-based translator library wrapping Bing and Microsoft Translator APIs

Readme

Free Microsoft Translator

微软翻译服务的浏览器 / Node.js 端翻译库。

这是 bing-translate-api v4.2.0 的 fork 版本,遵循原项目的实现逻辑,但:

  • 进行了改造以运行在浏览器端环境(e.g. 浏览器扩展程序)
  • 删掉了一些功能
  • 改变了函数签名

安装

npm install @lmk123/free-microsoft-translator

使用方法

选择翻译方式

// 默认使用 Microsoft 翻译
import { translate as metTranslate } from '@lmk123/free-microsoft-translator';
const metResult = await metTranslate('Hello', 'zh-Hans');

// 导入 Bing 翻译
import { translate } from '@lmk123/free-microsoft-translator/bing';
const bingResult = await translate('Hello', 'zh-Hans');

Microsoft 翻译

Microsoft 翻译基于 Azure Cognitive Services Translator API,功能更强大,支持批量翻译和多语言同时翻译。

基本翻译

import { translate } from '@lmk123/free-microsoft-translator';

// 单文本翻译
const result = await translate('Hello, nice to meet you!', 'zh-Hans');

console.log(result[0].detectedLanguage.language); // 'en'
console.log(result[0].translations[0].text); // '你好,很高兴见到你!'

多语言同时翻译

import { translate } from '@lmk123/free-microsoft-translator';

// 同时翻译到多个目标语言
const result = await translate('你好,很高兴认识你!', ['en', 'ja', 'ko']);

console.log(result[0].translations[0].text); // 'Hello, nice to meet you!' (英语)
console.log(result[0].translations[1].text); // 'こんにちは、はじめまして!' (日语)
console.log(result[0].translations[2].text); // '안녕하세요, 만나서 반갑습니다!' (韩语)

批量翻译

import { translate } from '@lmk123/free-microsoft-translator';

// 一次翻译多个文本
const result = await translate(['Hello', 'World', 'Good morning'], 'zh-Hans');

console.log(result[0].translations[0].text); // '你好'
console.log(result[1].translations[0].text); // '世界'
console.log(result[2].translations[0].text); // '早上好'

翻译 HTML 文本

import { translate } from '@lmk123/free-microsoft-translator';

const htmlText = '<div class="notranslate">Keep this</div><div>Translate this</div>';
const result = await translate(htmlText, 'zh-Hans', {
  translateOptions: { textType: 'html' }
});

console.log(result[0].translations[0].text);
// '<div class="notranslate">Keep this</div><div>翻译这个</div>'

使用付费服务密钥

import { translate } from '@lmk123/free-microsoft-translator';

// 使用 Azure 订阅密钥
const result = await translate('Hello', 'zh-Hans', {
  authenticationHeaders: {
    'Ocp-Apim-Subscription-Key': 'YOUR_KEY'
  }
});

// 或使用自定义 JWT 令牌
const result2 = await translate('Hello', 'zh-Hans', {
  authenticationHeaders: {
    'Authorization': 'Bearer YOUR_TOKEN'
  }
});

Bing 翻译

基本翻译

import { translate } from '@lmk123/free-microsoft-translator/bing';

// 翻译文本
const result = await translate('Hello, world!', 'zh-Hans', { from: 'en' });
console.log(result.translation); // 你好,世界!

自动语言检测

import { translate } from '@lmk123/free-microsoft-translator/bing';

// 不指定 from 参数,或者设置为 null / 'auto-detect' 即可自动检测
const result = await translate('你好', 'en');

console.log(result.translation); // Hello
console.log(result.language); // { from: 'zh-Hans', to: 'en', score: 1.0 }

返回原始响应

import { translate } from '@lmk123/free-microsoft-translator/bing';

const result = await translate('Hello', 'zh-Hans', { from: 'en', raw: true });

console.log(result.raw); // 完整的 API 响应

自定义 User-Agent(仅限 Node.js 环境)

import { translate } from '@lmk123/free-microsoft-translator/bing';

const result = await translate(
  'Hello',
  'zh-Hans',
  {
    from: 'en',
    userAgent: 'Mozilla/5.0 ...'
  }
);

开发

# 安装依赖
npm install

# 开发模式
npm run dev

# 构建
npm run build

许可证

MIT

相关项目