JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 27
  • Score
    100M100P100Q82325F
  • License MIT

Translate api for Google Translate

Package Exports

  • @lzy1960/google-translate
  • @lzy1960/google-translate/lib/guide-google-translate.mjs.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@lzy1960/google-translate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

google-translate

一款谷歌翻译api的插件

NPM version NPM downloads codecov Maintainability Language grade: JavaScript

OSCS Status

感谢开源社区 OSCS 的关注!

项目说明

  • TDD 开发流程
  • 使用 ts 编写
  • 集成 vitest 测试

使用方式

  1. 安装依赖包

    npm i @lzy1960/google-translate
    // OR
    yarn add @lzy1960/google-translate
    // OR
    pnpm i @lzy1960/google-translate
  2. 调用

    // default options
    const options = {
     from: 'auto',
     to: 'en',
     tld: 'cn',
     type: 'default'
    }
    const res = await translate('你好', options)
    console.log(res) // { "from": "zh-CN", "pronunciation": "Nǐ hǎo", "text": "Hello" }
  3. 入参说明

    translate接收两个参数:text 和 options

    options 默认为:

    {
     from: 'auto', // 源语言
     to: 'en', // 目标语言
     tld: 'cn', // 服务地址
     type: 'default', // 类型 'default' / 'word'
     isMobile: false // TODO:是否是移动端(移动端和pc端的返回值不一样)
    }
  4. 返回结果说明

    // default
    {
     from: "zh-CN", // 源语言
     pronunciation: "Nǐ hǎo", // 读音
     text: "Hello" // 目标语言结果
    }
    // word
    {
    text: '你好!',
       common: [
         {
           type: '感叹词',
           words: [
             {
               word: 'Hello!',
               explains: ['你好!', '喂!'],
               frequency: 1,
             },
             {
               word: 'Hi!',
               explains: ['嗨!', '你好!'],
               frequency: 1,
             },
             {
               word: 'Hallo!',
               explains: ['你好!'],
               frequency: 3,
             },
           ],
         },
       ],
    }

options 参数说明

参数 说明 类型 默认值
from 源语言 string 'auto'
to 目标语言 string 'en'
tld 地区 string 'cn'
type 类型 default | word 'default'