Skip to content

🎉一个简单的翻译库,支持多翻译引擎。A simple translation library that supports multiple translation engines

License

Notifications You must be signed in to change notification settings

yxw007/translate

Repository files navigation

Translate

English | 简体中文

GitHub top language GitHub License

❓ 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.

🚀 Install

  • npm

    npm install @yxw007/translate
  • yarn

    yarn add @yxw007/translate
  • pnpm

    pnpm i @yxw007/translate

📖 Usage

  • ESM

    import { translator, engines } from "@yxw007/translate"
    
    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);

    output

    ['你好']
    ["你好", "好的"]
  • Commonjs

    const { translator, engines }  = required("@yxw007/translate")
    
    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);

    output

    ['你好']
    ["你好", "好的"]

📄 License

Translate is released under the MIT license. See the LICENSE file.