JSPM

bmc-i18n-extract-cli

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

这是一款能够自动将代码里的中文转成i18n国际化标记的命令行工具。当然,你也可以用它实现将中文语言包自动翻译成其他语言。适用于vue2、vue3和react

Package Exports

    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 (bmc-i18n-extract-cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    基于 @ifreeovo/i18n-extract-cli 项目改进和扩展的国际化工具

    @bmc/translate-utils

    一个翻译工具函数库。支持有道,谷歌,百度,阿里云机器翻译,以及 OpenAI。

    install

    npm i @bmc/translate-utils

    api

    googleTranslate

    declare function googleTranslate(
      word: string, // 待翻译文本
      originLang: string, // 源语言
      targetLang: string, // 目标语言
      proxy: string | undefined // 代理地址
    ): Promise<string>

    例子

    const res = await googleTranslate('翻译内容', 'zh-CN', 'en-US', 'socks://127.0.0.1:1080')

    youdaoTranslate

    interface YoudaoConfig {
      key?: string // 有道词典appKey
      secret?: string // 有道词典appSecret
    }
    
    declare function youdaoTranslate(
      word: string, // 待翻译文本
      originLang: string, // 源语言
      targetLang: string, // 目标语言
      option: YoudaoConfig // 有道词典配置
    ): Promise<string>

    例子

    const res = await googleTranslate('翻译内容', 'zh-CN', 'en-US', {
      key: '2d8e89a6fd072117',
      secret: 'HiX7rGmYRad3ISMLYexRLfpkJi2taMPh',
    })

    openaiTranslate

    interface OpenAIConfig {
      baseUrl?: string // OpenAI API base URL, 默认 https://api.openai.com/v1
      apiKey?: string // OpenAI API Key
      model?: string // 模型,默认 gpt-4o-mini
    }
    
    declare function openaiTranslate(
      word: string, // 待翻译文本,可包含多行,按 \n 分割
      originLang: string, // 源语言
      targetLang: string, // 目标语言
      option: OpenAIConfig
    ): Promise<string>

    例子

    const res = await openaiTranslate('第一行\n第二行', 'zh-CN', 'en-US', {
      apiKey: process.env.OPENAI_API_KEY,
      baseUrl: 'https://api.openai.com/v1',
      model: 'gpt-4o-mini',
    })