Skip to content

Swift wrapper for public google translate

License

Notifications You must be signed in to change notification settings

MarkParker5/SwiftyTranslate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftyTranslate

Swift wrapper for public google translate

public struct Language: Identifiable, Hashable {
    let code: String
    let name: String
    
    public var id: String { code }
}

public extension Language {
    static let english = Language(code: "en", name: "English")
}

public class SwiftyTranslate {
    
    public var languages: [Language] { get }
    
    public func translate(text: String, to language: Language) async throws -> String?
}

Usage

Install as a swift package

import SwiftyTranslate

func demo() async throws {
  let translator = SwiftyTranslate()
  let translatedText = try await translator.translate(text: "Hello, World!", to: .english)
}