Skip to content

Commit

Permalink
fix проблемы с редактированием переводов
Browse files Browse the repository at this point in the history
+ фикс проблемы с маркировкой автопереводов
  • Loading branch information
abesmon committed Nov 1, 2021
1 parent 3811e7b commit bae8e39
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions sources/LocalizationEditor/Models/Localization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions sources/LocalizationEditor/Models/LocalizationString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""))
}
}

Expand Down
4 changes: 3 additions & 1 deletion sources/LocalizationEditor/Services/AutoTranslator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion sources/LocalizationEditor/UI/Cells/LocalizationCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit bae8e39

Please sign in to comment.