一些排名较高的npm翻译插件

411 阅读1分钟

最近在做国际化,由于需要翻译成不同的语言,所以需要找到一些插件的支持,搜了一下现有的一些插件,发现下面这几个是排名相对来说比较高的。

translate

能够在Node.js和浏览器上将文本转换为不同的语言。默认允许你使用Google(默认)、Yandex、Libre或DeepL作为内置翻译器。 示例代码:

import translate from "translate";

translate.engine = "deepl";
translate.key = process.env.DEEPL_KEY;

const text = await translate("Hello world", "es");
console.log(text);
// "Hola mundo"

插件地址:translate

bing-translate-api

提供免费的必应翻译和微软翻译API。示例代码:

const { translate } = require('bing-translate-api');

translate('你好', null, 'en').then(res => {
  console.log(res.translation);
}).catch(err => {
  console.error(err);
});

插件地址:bing-translate-api

其它

除了谷歌翻译之外,还发现了 libreyandex,DeepL等不太常见的第三方翻译网站。