JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q83525F
  • 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 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. 返回结果说明

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