CocoaPods trunk is moving to be read-only. Read more on the blog, there are 15 months to go.

Translator 1.0.0

Translator 1.0.0

Maintained by Akash Tala.



  • By
  • Akash Tala

๐Ÿ“˜ Translator

Version License Platform

A lightweight, Swift-based translation client leveraging Google Translate endpoints.
Supports both modern async/await and legacy completion-handler APIs.


๐Ÿงฉ Features

  • โœ… Auto-detection of source language (sl = auto)
  • โœ… Supports async/await and completion-handler interfaces
  • โœ… Error handling with detailed enum-based errors
  • โœ… Token-based query generation

๐Ÿš€ Installation

Translator is available through CocoaPods and swift package manager.

CocoaPods:

pod 'Translator'

Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/akashtala/Translator.git", from: "1.0.0")
]

๐Ÿ”ง Usage

๐Ÿ”น Async/Await

let translator = Translator()
do {
    let result = try await translator.translateToEnglish("Bonjour")
    print(result.translatedText)
} catch {
    print("โŒ Error: \(error)")
}

๐Ÿ”น Async/Await

let translator = Translator()
do {
    let result = try await translator.translateToEnglish("Bonjour")
    print(result.translatedText)
} catch {
    print("โŒ Error: \(error)")
}

๐Ÿงช API Surface

Function Signature Description
translateToEnglish(_:) Translate text to English (auto source detection)
translateToEnglish(_:completion:) Same as above, using a callback
translate(from:to:sourceText:) Translate from a specific language to another
translate(from:to:sourceText:) Translate from a specific language to another
translate(from:to:sourceText:completion:) Same, using a completion handler

๐Ÿ” Error Handling

All translation operations may throw or return TranslationError:

  • .unsupportedLanguage(String) โ€“ Language not supported by the internal list

  • .invalidResponse โ€“ Unexpected or malformed response from the server

  • .serverError(statusCode: Int, body: String) โ€“ HTTP error with status code

  • .parsingError โ€“ Failed to construct request or parse the response

๐Ÿค Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what youโ€™d like to change.

๐Ÿ“„ License

Distributed under the MIT License. See LICENSE for more information.

๐Ÿ”— Author

Akash Tala

GitHub @akashtala

[email protected]