From d31764b95ba15716feae01ed7e862e350ad41472 Mon Sep 17 00:00:00 2001 From: Serhii Londar Date: Mon, 9 Dec 2024 09:11:52 +0100 Subject: [PATCH] fix: Remove functionality to work with json files (#289) --- .../CrowdinContentDeliveryAPI.swift | 15 ------- .../LocalLocalizationExtractor.swift | 22 ----------- .../Extensions/String+Extensions.swift | 4 -- .../CrowdinLocalizationDownloader.swift | 16 +------- .../CrowdinJsonDownloadOperation.swift | 39 ------------------- .../CrowdinXcstringsDownloadOperation.swift | 6 ++- 6 files changed, 6 insertions(+), 96 deletions(-) delete mode 100644 Sources/CrowdinSDK/Providers/Crowdin/LocalizationDownloader/Operations/CrowdinJsonDownloadOperation.swift diff --git a/Sources/CrowdinSDK/CrowdinAPI/ContentDeliveryAPI/CrowdinContentDeliveryAPI.swift b/Sources/CrowdinSDK/CrowdinAPI/ContentDeliveryAPI/CrowdinContentDeliveryAPI.swift index e810cf12..ab0bf138 100644 --- a/Sources/CrowdinSDK/CrowdinAPI/ContentDeliveryAPI/CrowdinContentDeliveryAPI.swift +++ b/Sources/CrowdinSDK/CrowdinAPI/ContentDeliveryAPI/CrowdinContentDeliveryAPI.swift @@ -130,21 +130,6 @@ class CrowdinContentDeliveryAPI: BaseAPI { } } - func getJson(filePath: String, etag: String?, timestamp: TimeInterval?, completion: @escaping CrowdinAPIStringsCompletion) { - self.getFile(filePath: filePath, etag: etag, timestamp: timestamp) { (data, response, error) in - let etag = (response as? HTTPURLResponse)?.allHeaderFields[Strings.etag.rawValue] as? String - if let data = data { - guard let strings = try? JSONSerialization.jsonObject(with: data, options: .fragmentsAllowed) as? [String: String] else { - completion(nil, etag, error) - return - } - completion(strings, etag, nil) - } else { - completion(nil, etag, error) - } - } - } - // MARK - Mapping download methods: func getStringsMapping(filePath: String, etag: String?, timestamp: TimeInterval?, completion: @escaping CrowdinAPIStringsMappingCompletion) { self.getFile(filePath: filePath, etag: etag, timestamp: timestamp) { (data, _, error) in diff --git a/Sources/CrowdinSDK/CrowdinSDK/Localization/Extractor/LocalLocalizationExtractor.swift b/Sources/CrowdinSDK/CrowdinSDK/Localization/Extractor/LocalLocalizationExtractor.swift index 83f8eff6..106c006a 100644 --- a/Sources/CrowdinSDK/CrowdinSDK/Localization/Extractor/LocalLocalizationExtractor.swift +++ b/Sources/CrowdinSDK/CrowdinSDK/Localization/Extractor/LocalLocalizationExtractor.swift @@ -72,28 +72,6 @@ final class LocalLocalizationExtractor { } setupPluralsBundle() } - - static func extractLocalizationJSONFile(to path: String) { - let json = self.extractLocalizationJSON() - guard let data = try? JSONSerialization.data(withJSONObject: json, options: .prettyPrinted) else { return } - try? data.write(to: URL(fileURLWithPath: path)) - } - - static func extractLocalizationJSON() -> [String: Any] { - var result = [String: Any]() - self.allLocalizations.forEach { (localization) in - let extractor = LocalLocalizationExtractor(localization: localization) - var dict = [String: Any]() - if !extractor.localizationDict.isEmpty { - dict[Keys.strings.rawValue] = extractor.localizationDict - } - if !extractor.localizationPluralsDict.isEmpty { - dict[Keys.plurals.rawValue] = extractor.localizationPluralsDict - } - result[localization] = dict - } - return result - } func extractLocalizationStrings(to path: String) -> StringsFile { let file = StringsFile(path: path + String.pathDelimiter + localization + FileType.strings.extension) diff --git a/Sources/CrowdinSDK/Providers/Crowdin/Extensions/String+Extensions.swift b/Sources/CrowdinSDK/Providers/Crowdin/Extensions/String+Extensions.swift index 2d53a25c..ab660ca1 100644 --- a/Sources/CrowdinSDK/Providers/Crowdin/Extensions/String+Extensions.swift +++ b/Sources/CrowdinSDK/Providers/Crowdin/Extensions/String+Extensions.swift @@ -32,10 +32,6 @@ extension String { hasSuffix(FileExtensions.xliff.extension) } - var isJson: Bool { - hasSuffix(FileExtensions.json.extension) - } - var isXcstrings: Bool { hasSuffix(FileExtensions.xcstrings.extension) } diff --git a/Sources/CrowdinSDK/Providers/Crowdin/LocalizationDownloader/CrowdinLocalizationDownloader.swift b/Sources/CrowdinSDK/Providers/Crowdin/LocalizationDownloader/CrowdinLocalizationDownloader.swift index 0119cb95..e1a814a0 100644 --- a/Sources/CrowdinSDK/Providers/Crowdin/LocalizationDownloader/CrowdinLocalizationDownloader.swift +++ b/Sources/CrowdinSDK/Providers/Crowdin/LocalizationDownloader/CrowdinLocalizationDownloader.swift @@ -30,9 +30,8 @@ class CrowdinLocalizationDownloader: CrowdinDownloaderProtocol { let strings = files.filter({ $0.isStrings }) let plurals = files.filter({ $0.isStringsDict }) let xliffs = files.filter({ $0.isXliff }) - let jsons = files.filter({ $0.isJson }) let xcstrings = files.filter({ $0.isXcstrings }) - self.download(strings: strings, plurals: plurals, xliffs:xliffs, jsons: jsons, xcstrings: xcstrings, with: hash, timestamp: timestamp, for: localization) + self.download(strings: strings, plurals: plurals, xliffs:xliffs, xcstrings: xcstrings, with: hash, timestamp: timestamp, for: localization) } else if let error = error { self.errors = [error] self.completion?(nil, nil, self.errors) @@ -40,7 +39,7 @@ class CrowdinLocalizationDownloader: CrowdinDownloaderProtocol { } } - func download(strings: [String], plurals: [String], xliffs: [String], jsons: [String], xcstrings: [String], with hash: String, timestamp: TimeInterval?, for localization: String) { + func download(strings: [String], plurals: [String], xliffs: [String], xcstrings: [String], with hash: String, timestamp: TimeInterval?, for localization: String) { self.operationQueue.cancelAllOperations() self.contentDeliveryAPI = CrowdinContentDeliveryAPI(hash: hash, session: URLSession.shared) @@ -87,17 +86,6 @@ class CrowdinLocalizationDownloader: CrowdinDownloaderProtocol { operationQueue.addOperation(download) } - jsons.forEach { filePath in - let download = CrowdinJsonDownloadOperation(filePath: filePath, localization: localization, timestamp: timestamp, contentDeliveryAPI: contentDeliveryAPI) - download.completion = { [weak self] (strings, _, error) in - guard let self = self else { return } - self.add(strings: strings) - self.add(error: error) - } - completionBlock.addDependency(download) - operationQueue.addOperation(download) - } - xcstrings.forEach { filePath in let download = CrowdinXcstringsDownloadOperation(filePath: filePath, localization: localization, diff --git a/Sources/CrowdinSDK/Providers/Crowdin/LocalizationDownloader/Operations/CrowdinJsonDownloadOperation.swift b/Sources/CrowdinSDK/Providers/Crowdin/LocalizationDownloader/Operations/CrowdinJsonDownloadOperation.swift deleted file mode 100644 index fbe6f253..00000000 --- a/Sources/CrowdinSDK/Providers/Crowdin/LocalizationDownloader/Operations/CrowdinJsonDownloadOperation.swift +++ /dev/null @@ -1,39 +0,0 @@ -// -// CrowdinJsonDownloadOperation.swift -// CrowdinSDK -// -// Created by Serhii Londar on 05.07.2020. -// - -import Foundation - -typealias CrowdinJsonDownloadOperationCompletion = ([String: String]?, [AnyHashable: Any]?, Error?) -> Void - -class CrowdinJsonDownloadOperation: CrowdinDownloadOperation { - var timestamp: TimeInterval? - var eTagStorage: AnyEtagStorage - var completion: CrowdinJsonDownloadOperationCompletion? = nil - - init(filePath: String, localization: String, timestamp: TimeInterval?, contentDeliveryAPI: CrowdinContentDeliveryAPI, completion: CrowdinJsonDownloadOperationCompletion?) { - self.timestamp = timestamp - self.eTagStorage = FileEtagStorage(localization: localization) - super.init(filePath: filePath, contentDeliveryAPI: contentDeliveryAPI) - self.completion = completion - } - - required init(filePath: String, localization: String, timestamp: TimeInterval?, contentDeliveryAPI: CrowdinContentDeliveryAPI) { - self.timestamp = timestamp - self.eTagStorage = FileEtagStorage(localization: localization) - super.init(filePath: filePath, contentDeliveryAPI: contentDeliveryAPI) - } - - override func main() { - let etag = eTagStorage.etag(for: filePath) - contentDeliveryAPI.getJson(filePath: filePath, etag: etag, timestamp: timestamp) { [weak self] (strings, etag, error) in - guard let self = self else { return } - self.eTagStorage.save(etag: etag, for: self.filePath) - self.completion?(strings, nil, error) - self.finish(with: error != nil) - } - } -} diff --git a/Sources/CrowdinSDK/Providers/Crowdin/LocalizationDownloader/Operations/CrowdinXcstringsDownloadOperation.swift b/Sources/CrowdinSDK/Providers/Crowdin/LocalizationDownloader/Operations/CrowdinXcstringsDownloadOperation.swift index 35377493..f6ab8701 100644 --- a/Sources/CrowdinSDK/Providers/Crowdin/LocalizationDownloader/Operations/CrowdinXcstringsDownloadOperation.swift +++ b/Sources/CrowdinSDK/Providers/Crowdin/LocalizationDownloader/Operations/CrowdinXcstringsDownloadOperation.swift @@ -7,6 +7,8 @@ import Foundation +typealias CrowdinDownloadOperationCompletion = ([String: String]?, [AnyHashable: Any]?, Error?) -> Void + public struct Localizations: Codable { public let sourceLanguage: String public let version: String @@ -170,10 +172,10 @@ class XCStringsStorage { class CrowdinXcstringsDownloadOperation: CrowdinDownloadOperation { var timestamp: TimeInterval? let eTagStorage: AnyEtagStorage - var completion: CrowdinJsonDownloadOperationCompletion? = nil + var completion: CrowdinDownloadOperationCompletion? = nil let localization: String - init(filePath: String, localization: String, language: String, timestamp: TimeInterval?, contentDeliveryAPI: CrowdinContentDeliveryAPI, completion: CrowdinJsonDownloadOperationCompletion?) { + init(filePath: String, localization: String, language: String, timestamp: TimeInterval?, contentDeliveryAPI: CrowdinContentDeliveryAPI, completion: CrowdinDownloadOperationCompletion?) { self.localization = localization self.timestamp = timestamp self.eTagStorage = FileEtagStorage(localization: language)