diff --git a/BartyCrouch.podspec b/BartyCrouch.podspec index 924cea2..d6b8a16 100644 --- a/BartyCrouch.podspec +++ b/BartyCrouch.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "BartyCrouch" - s.version = "4.14.2" + s.version = "4.15.0" s.summary = "Localization/I18n: Incrementally update/translate your Strings files from .swift, .h, .m(m), .storyboard or .xib files." s.description = <<-DESC diff --git a/CHANGELOG.md b/CHANGELOG.md index 8222b43..15a1284 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,13 @@ If needed, pluralize to `Tasks`, `PRs` or `Authors` and list multiple entries se ### Security - None. +## [4.15.0] - 2023-05-22 +### Changed +- Improved implementation of DeepL API client for more reliable escaping than the previous manual escaping logic. + PR: [#277](https://github.com/FlineDev/BartyCrouch/issues/277) | Author: [Nico](https://github.com/NickAtGit) +- Upgraded Swift-Syntax dependency to work with Swift 5.8 to fix build issues. + PR: [#279](https://github.com/FlineDev/BartyCrouch/issues/279) | Author: [Alex Deem](https://github.com/alexdeem) + ## [4.14.0] - 2022-12-14 ### Added - Support for Swift 5.7 and Xcode 14, dropping support for older versions and fixing the 'could not parse syntax tree' issue. diff --git a/Package.swift b/Package.swift index 1b92697..7846816 100644 --- a/Package.swift +++ b/Package.swift @@ -17,7 +17,7 @@ let package = Package( .package(name: "Rainbow", url: "https://github.com/onevcat/Rainbow.git", from: "3.1.5"), .package(name: "SwiftCLI", url: "https://github.com/jakeheis/SwiftCLI.git", from: "6.0.3"), .package(name: "Toml", url: "https://github.com/jdfergason/swift-toml.git", .branch("master")), - .package(url: "https://github.com/apple/swift-syntax.git", .branch("0.50700.1")), + .package(url: "https://github.com/apple/swift-syntax.git", from: "508.0.0"), // A collection of tools for debugging, diffing, and testing your application's data structures. .package(url: "https://github.com/pointfreeco/swift-custom-dump.git", from: "0.3.0"), diff --git a/Sources/BartyCrouch/main.swift b/Sources/BartyCrouch/main.swift index b680607..08df412 100644 --- a/Sources/BartyCrouch/main.swift +++ b/Sources/BartyCrouch/main.swift @@ -5,7 +5,7 @@ import SwiftCLI // MARK: - CLI let cli = CLI( name: "bartycrouch", - version: "4.14.2", + version: "4.15.0", description: "Incrementally update & translate your Strings files from code or interface files." ) diff --git a/Sources/BartyCrouchKit/FileHandling/SupportedLanguagesReader.swift b/Sources/BartyCrouchKit/FileHandling/SupportedLanguagesReader.swift index 539bff3..2c08d89 100644 --- a/Sources/BartyCrouchKit/FileHandling/SupportedLanguagesReader.swift +++ b/Sources/BartyCrouchKit/FileHandling/SupportedLanguagesReader.swift @@ -10,6 +10,7 @@ class SupportedLanguagesReader: SyntaxVisitor { typeName: String ) { self.typeName = typeName + super.init(viewMode: .sourceAccurate) } override func visit(_ enumDeclaration: EnumDeclSyntax) -> SyntaxVisitorContinueKind { diff --git a/Sources/BartyCrouchTranslator/DeeplApi/DeepLApi.swift b/Sources/BartyCrouchTranslator/DeeplApi/DeepLApi.swift index eb8e607..b6a98c4 100644 --- a/Sources/BartyCrouchTranslator/DeeplApi/DeepLApi.swift +++ b/Sources/BartyCrouchTranslator/DeeplApi/DeepLApi.swift @@ -57,13 +57,24 @@ extension DeepLApi: Endpoint { var method: HttpMethod { switch self { case .translate(let texts, let sourceLanguage, let targetLanguage, let authKey): - let textEntries = texts.map { "text=\($0.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!)" } - .joined(separator: "&") - let authKeyEntry = "auth_key=\(authKey)" - let sourceLanguageEntry = "source_lang=\(sourceLanguage.deepLParameterValue)" - let targetLanguageEntry = "target_lang=\(targetLanguage.deepLParameterValue)" - let bodyString = [authKeyEntry, sourceLanguageEntry, targetLanguageEntry, textEntries].joined(separator: "&") - return .post(body: bodyString.data(using: .utf8)!) + + let authKeyItem = URLQueryItem(name: "auth_key", value: authKey) + let textItems = texts.map { URLQueryItem(name: "text", value: $0) } + let targetLangItem = URLQueryItem(name: "target_lang", value: targetLanguage.deepLParameterValue) + let sourceLangItem = URLQueryItem(name: "source_lang", value: sourceLanguage.deepLParameterValue) + + var components = URLComponents() + components.queryItems = ([authKeyItem, targetLangItem, sourceLangItem] + textItems).compactMap { $0 } + + guard var queryItemsString = components.string else { + fatalError("Invalid arguments.") + } + // queryItemsString starts with a ? but post API expects the query string without leading ? + if queryItemsString.hasPrefix("?") { + queryItemsString.removeFirst() + } + + return .post(body: queryItemsString.data(using: .utf8)!) } } diff --git a/Sources/SupportingFiles/Info.plist b/Sources/SupportingFiles/Info.plist index 74175bc..a4e2747 100644 --- a/Sources/SupportingFiles/Info.plist +++ b/Sources/SupportingFiles/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 4.14.2 + 4.15.0 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSHumanReadableCopyright diff --git a/Tests/BartyCrouchTranslatorTests/DeepLTranslatorApiTests.swift b/Tests/BartyCrouchTranslatorTests/DeepLTranslatorApiTests.swift index 4f8c4f8..e5fcb27 100644 --- a/Tests/BartyCrouchTranslatorTests/DeepLTranslatorApiTests.swift +++ b/Tests/BartyCrouchTranslatorTests/DeepLTranslatorApiTests.swift @@ -20,6 +20,7 @@ class DeepLTranslatorApiTests: XCTestCase { switch apiProvider.performRequestAndWait(on: endpoint, decodeBodyTo: DeepLTranslateResponse.self) { case let .success(translateResponses): XCTAssertEqual(translateResponses.translations[0].text, "Wie alt sind Sie?") + XCTAssertEqual(translateResponses.translations[1].text, "Liebe") case let .failure(failure): XCTFail(failure.localizedDescription)