From f136a2f9c84d6fee9234256de33ab1217ea22518 Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Thu, 1 Jul 2021 21:22:59 +0200 Subject: [PATCH] feat: add translation to the modules name (#496) --- .swiftlint.yml | 1 + Kit/module/popup.swift | 6 ++++-- Kit/module/settings.swift | 2 +- Stats/Views/Settings.swift | 17 ++++++++++++++--- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index f1b7748d..31529875 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -28,6 +28,7 @@ identifier_name: - NumbersOfProcesses - NetworkReaders - SensorsList + - Alignments line_length: 200 diff --git a/Kit/module/popup.swift b/Kit/module/popup.swift index da034720..dad3b9b6 100644 --- a/Kit/module/popup.swift +++ b/Kit/module/popup.swift @@ -224,6 +224,7 @@ internal class HeaderView: NSStackView { private var activityButton: NSButton? private var settingsButton: NSButton? + private var title: String = "" private var isCloseAction: Bool = false override init(frame: NSRect) { @@ -292,7 +293,8 @@ internal class HeaderView: NSStackView { } public func setTitle(_ newTitle: String) { - self.titleView?.stringValue = newTitle + self.title = newTitle + self.titleView?.stringValue = localizedString(newTitle) } override func draw(_ dirtyRect: NSRect) { @@ -324,7 +326,7 @@ internal class HeaderView: NSStackView { @objc func openSettings(_ sender: Any) { self.window?.setIsVisible(false) - NotificationCenter.default.post(name: .toggleSettings, object: nil, userInfo: ["module": self.titleView?.stringValue ?? ""]) + NotificationCenter.default.post(name: .toggleSettings, object: nil, userInfo: ["module": self.title]) } public func setCloseButton(_ state: Bool) { diff --git a/Kit/module/settings.swift b/Kit/module/settings.swift index cfdfc875..1ceccb54 100644 --- a/Kit/module/settings.swift +++ b/Kit/module/settings.swift @@ -81,7 +81,7 @@ open class Settings: NSView, Settings_p { titleView.canDrawSubviewsIntoLayer = true titleView.alignment = .natural titleView.font = NSFont.systemFont(ofSize: 18, weight: .light) - titleView.stringValue = self.config.pointee.name + titleView.stringValue = localizedString(self.config.pointee.name) var toggle: NSControl = NSControl() if #available(OSX 10.15, *) { diff --git a/Stats/Views/Settings.swift b/Stats/Views/Settings.swift index 77847e6b..9bc720fc 100644 --- a/Stats/Views/Settings.swift +++ b/Stats/Views/Settings.swift @@ -285,7 +285,16 @@ private class MenuView: NSView { super.init(frame: NSRect(x: 0, y: self.height*CGFloat(n), width: width, height: self.height)) self.wantsLayer = true self.layer?.backgroundColor = .clear - self.toolTip = title == "Stats" ? localizedString("Open application settings") : localizedString("Open moduleName settings", title) + + var toolTip = "" + if title == "State" { + toolTip = localizedString("Open application settings") + } else if title == "Dashboard" { + toolTip = localizedString("Open dashboard") + } else { + toolTip = localizedString("Open \(title) settings") + } + self.toolTip = toolTip let rect = NSRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height) let trackingArea = NSTrackingArea( @@ -302,13 +311,15 @@ private class MenuView: NSView { } imageView.frame = NSRect(x: 8, y: (self.height - 18)/2, width: 18, height: 18) imageView.wantsLayer = true - imageView.contentTintColor = .labelColor + if #available(OSX 10.14, *) { + imageView.contentTintColor = .labelColor + } let titleView = TextView(frame: NSRect(x: 34, y: (self.height - 16)/2, width: 100, height: 16)) titleView.alignment = .natural titleView.textColor = .labelColor titleView.font = NSFont.systemFont(ofSize: 13, weight: .regular) - titleView.stringValue = title + titleView.stringValue = localizedString(title) self.addSubview(imageView) self.addSubview(titleView)