From bae8e39e674aba8ca63665872e96c124f879cdff Mon Sep 17 00:00:00 2001 From: Alexey Lysenko Date: Mon, 1 Nov 2021 16:20:33 +0300 Subject: [PATCH] =?UTF-8?q?fix=20=D0=BF=D1=80=D0=BE=D0=B1=D0=BB=D0=B5?= =?UTF-8?q?=D0=BC=D1=8B=20=D1=81=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + фикс проблемы с маркировкой автопереводов --- sources/LocalizationEditor/Models/Localization.swift | 1 + sources/LocalizationEditor/Models/LocalizationString.swift | 6 +++--- .../Providers/LocalizationsDataSource.swift | 2 +- sources/LocalizationEditor/Services/AutoTranslator.swift | 4 +++- sources/LocalizationEditor/UI/Cells/LocalizationCell.swift | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/sources/LocalizationEditor/Models/Localization.swift b/sources/LocalizationEditor/Models/Localization.swift index e781188..1d03df3 100644 --- a/sources/LocalizationEditor/Models/Localization.swift +++ b/sources/LocalizationEditor/Models/Localization.swift @@ -25,6 +25,7 @@ final class Localization { func update(key: String, value: String, message: String?) { if let existing = translations.first(where: { $0.key == key }) { existing.update(newValue: value) + existing.update(message: message) return } diff --git a/sources/LocalizationEditor/Models/LocalizationString.swift b/sources/LocalizationEditor/Models/LocalizationString.swift index d9f758b..cf828d4 100644 --- a/sources/LocalizationEditor/Models/LocalizationString.swift +++ b/sources/LocalizationEditor/Models/LocalizationString.swift @@ -14,7 +14,7 @@ import Foundation final class LocalizationString { let key: String private(set) var value: String - private (set) var message: String? + private(set) var message: String? init(key: String, value: String, message: String?) { self.key = key @@ -23,10 +23,10 @@ final class LocalizationString { } func update(newValue: String) { - value = newValue + self.value = newValue } - func updateMessage(_ message: String?) { + func update(message: String?) { self.message = message } } diff --git a/sources/LocalizationEditor/Providers/LocalizationsDataSource.swift b/sources/LocalizationEditor/Providers/LocalizationsDataSource.swift index 6afca68..4244085 100644 --- a/sources/LocalizationEditor/Providers/LocalizationsDataSource.swift +++ b/sources/LocalizationEditor/Providers/LocalizationsDataSource.swift @@ -263,7 +263,7 @@ final class LocalizationsDataSource: NSObject { with: "", message: locString?.message?.replacingOccurrences(of: kAutotranslatedTag, with: "")) locString?.update(newValue: "") - locString?.updateMessage(locString?.message?.replacingOccurrences(of: kAutotranslatedTag, with: "")) + locString?.update(message: locString?.message?.replacingOccurrences(of: kAutotranslatedTag, with: "")) } } diff --git a/sources/LocalizationEditor/Services/AutoTranslator.swift b/sources/LocalizationEditor/Services/AutoTranslator.swift index 069949f..e8ff462 100644 --- a/sources/LocalizationEditor/Services/AutoTranslator.swift +++ b/sources/LocalizationEditor/Services/AutoTranslator.swift @@ -47,7 +47,9 @@ class AutoTranslator { let res = try translator.translateSync(text: stringToTranslate, targetLang: locLang) var message = locString?.message ?? "" if !message.contains(kAutotranslatedTag) { - message = [message, kAutotranslatedTag].joined(separator: " ") + message = [message, kAutotranslatedTag] + .joined(separator: " ") + .trimmingCharacters(in: .whitespaces) } translated[locKey]?[locLang] = .init(key: locKey, value: res, message: message) } diff --git a/sources/LocalizationEditor/UI/Cells/LocalizationCell.swift b/sources/LocalizationEditor/UI/Cells/LocalizationCell.swift index f4a69af..393a45a 100644 --- a/sources/LocalizationEditor/UI/Cells/LocalizationCell.swift +++ b/sources/LocalizationEditor/UI/Cells/LocalizationCell.swift @@ -64,7 +64,7 @@ extension LocalizationCell: NSTextFieldDelegate { } setStateUI() - value.update(newValue: valueTextField.stringValue) delegate?.userDidUpdateLocalizationString(language: language, key: value.key, with: valueTextField.stringValue, message: value.message) + value.update(newValue: valueTextField.stringValue) } }