Skip to content

Commit

Permalink
pref: optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
AkaShark committed Feb 7, 2024
1 parent fc3b429 commit b338c15
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Easydict/NewApp/Feature/Shortcut/Shortcut+Menu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI

extension Shortcut {
func updateMenu(_ type: ShortcutType) { // update shortcut menu
let shortcutTitle = String.localizedString(for: LocalizedStringKey(type.localizedStringKey()).stringKey ?? "")
let shortcutTitle = LocalizedStringKey(type.localizedStringKey()).stringValue()
let shortcutMenu = NSApp.mainMenu?.items.first(where: { $0.title == "Shortcut" })
let clearInput = shortcutMenu?.submenu?.items.first(where: { $0.title == shortcutTitle })
clearInput?.keyEquivalent = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ extension LocalizedStringKey {
var stringKey: String? {
Mirror(reflecting: self).children.first(where: { $0.label == "key" })?.value as? String
}

func stringValue(locale: Locale = .current) -> String {
.localizedString(for: stringKey ?? "", locale: locale)
}
}

extension String {
Expand Down

0 comments on commit b338c15

Please sign in to comment.