SwiftGoogleTranslate 0.2.1

SwiftGoogleTranslate 0.2.1

Maxim Bilan 维护。



  • 作者:
  • Maxim Bilan

SwiftGoogleTranslate

Version License Platform CocoaPods

一个框架,用于在 Swift 中使用 Google Cloud 翻译 API

安装

CocoaPods

pod 'SwiftGoogleTranslate'

手动

Copy SwiftGoogleTranslate.swift to your project.

初始化

首先,您需要在 控制台 生成 API 密钥以使用 Google Cloud 服务。然后使用以下代码

SwiftGoogleTranslate.shared.start(with: "API_KEY_HERE")

使用

框架支持 3 个端点:translatedetectlanguages。您可以在官方文档中找到更多关于如何使用框架进行操作的信息。

翻译

SwiftGoogleTranslate.shared.translate("Hello!", "es", "en") { (text, error) in
  if let t = text {
    print(t)
  }
}

检测

SwiftGoogleTranslate.shared.detect("¡Hola!") { (detections, error) in
  if let detections = detections {
    for detection in detections {
      print(detection.language)
      print(detection.isReliable)
      print(detection.confidence)
      print("---")
    }
  }
}

语言列表

SwiftGoogleTranslate.shared.languages { (languages, error) in
  if let languages = languages {
    for language in languages {
      print(language.language)
      print(language.name)
      print("---")
    }
  }
}

许可证

SwiftGoogleTranslate 可以在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。