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) } }