Skip to content

maximbilan/SwiftGoogleTranslate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

34 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

SwiftGoogleTranslate

Version License Platform

A framework to use Cloud Translation API by Google in Swift. :snowman::frog::penguin::whale::turtle:

Installation

CocoaPods:

pod 'SwiftGoogleTranslate'

Carthage:

github "maximbilan/SwiftGoogleTranslate"

Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/maximbilan/SwiftGoogleTranslate", from: "0.2.1")
]

Manual:

Copy SwiftGoogleTranslate.swift to your project.

Initialization

First of all you have to generate an API key to use Google Cloud services in the console. Then use the following code:

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

Using

The framework supports 3 endpoints: translate, detect, and languages. You can find more information in the official documentation.

Translation:

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

Detection:

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("---")
    }
  }
}

A list of languages:

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

License

SwiftGoogleTranslate is available under the MIT license. See the LICENSE file for more info.

About

๐ŸŒ A lightweight Swift framework for Google's Cloud Translation API โ€” translate text, detect languages, and list supported languages. Works with SPM, CocoaPods & Carthage.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors