Skip to content

Commit

Permalink
Merge branch 'release/4.7.0' into versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Jul 30, 2021
2 parents e6a6dea + c5bcc03 commit c16b219
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion BartyCrouch.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "BartyCrouch"
s.version = "4.6.0"
s.version = "4.7.0"
s.summary = "Localization/I18n: Incrementally update/translate your Strings files from .swift, .h, .m(m), .storyboard or .xib files."

s.description = <<-DESC
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ If needed, pluralize to `Tasks`, `PRs` or `Authors` and list multiple entries se
### Security
- None.

## [4.7.0] - 2021-07-31
### Added
- Add support for DeepL API Free
PR: [#230](https://github.com/Flinesoft/BartyCrouch/pull/230) | Author: [Manabu Nakazawa](https://github.com/mshibanami)

## [4.6.0] - 2021-05-08
### Changed
- Updated swift-syntax to match Swift 5.4 to support Xcode 12.5.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<img src="https://api.codacy.com/project/badge/Coverage/7b34ad9193c2438aa32aa29a0490451f"/>
</a>
<a href="https://github.com/Flinesoft/BartyCrouch/releases">
<img src="https://img.shields.io/badge/Version-4.6.0-blue.svg"
alt="Version: 4.6.0">
<img src="https://img.shields.io/badge/Version-4.7.0-blue.svg"
alt="Version: 4.7.0">
</a>
<img src="https://img.shields.io/badge/Swift-5.4-FFAC45.svg"
alt="Swift: 5.4">
Expand Down
2 changes: 1 addition & 1 deletion Sources/BartyCrouch/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SwiftCLI
// MARK: - CLI
let cli = CLI(
name: "bartycrouch",
version: "4.6.0",
version: "4.7.0",
description: "Incrementally update & translate your Strings files from code or interface files."
)

Expand Down
11 changes: 10 additions & 1 deletion Sources/BartyCrouchTranslator/BartyCrouchTranslator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,22 @@ public final class BartyCrouchTranslator {
}

private let microsoftProvider = ApiProvider<MicrosoftTranslatorApi>(baseUrl: MicrosoftTranslatorApi.baseUrl)
private let deepLProvider = ApiProvider<DeepLApi>(baseUrl: DeepLApi.baseUrl)
private let deepLProvider: ApiProvider<DeepLApi>

private let translationService: TranslationService

/// Creates a new translator object configured to use the specified translation service.
public init(translationService: TranslationService) {
self.translationService = translationService

let deepLApiType: DeepLApi.ApiType
if case let .deepL(apiKey) = translationService {
deepLApiType = apiKey.hasSuffix(":fx") ? .free : .pro
} else {
deepLApiType = .pro
}

deepLProvider = ApiProvider<DeepLApi>(baseUrl: DeepLApi.baseUrl(for: deepLApiType))
}

/// Translates the given text from a given language to one or multiple given other languages.
Expand Down
15 changes: 13 additions & 2 deletions Sources/BartyCrouchTranslator/DeeplApi/DeepLApi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ enum DeepLApi {
extension DeepLApi: Endpoint {
typealias ClientErrorType = DeepLTranslateErrorResponse

static var baseUrl: URL {
URL(string: "https://api.deepl.com")!
enum ApiType {
case free
case pro
}

var decoder: JSONDecoder {
Expand Down Expand Up @@ -75,4 +76,14 @@ extension DeepLApi: Endpoint {
var headers: [String: String] {
["Content-Type": "application/json"]
}

static func baseUrl(for apiType: ApiType) -> URL {
switch apiType {
case .free:
return URL(string: "https://api-free.deepl.com")!

case .pro:
return URL(string: "https://api.deepl.com")!
}
}
}
2 changes: 1 addition & 1 deletion Sources/SupportingFiles/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>4.6.0</string>
<string>4.7.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DeepLTranslatorApiTests: XCTestCase {
apiKey: apiKey
)

let apiProvider = ApiProvider<DeepLApi>(baseUrl: DeepLApi.baseUrl)
let apiProvider = ApiProvider<DeepLApi>(baseUrl: DeepLApi.baseUrl(for: .pro))

switch apiProvider.performRequestAndWait(on: endpoint, decodeBodyTo: DeepLTranslateResponse.self) {
case let .success(translateResponses):
Expand Down

0 comments on commit c16b219

Please sign in to comment.