forked from tisfeng/Easydict
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// Shortcut+Menu.swift | ||
// Easydict | ||
// | ||
// Created by Sharker on 2024/2/7. | ||
// Copyright © 2024 izual. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension Shortcut { | ||
func updateMenu(_ type: ShortcutType) { // update shortcut menu | ||
let shortcutTitle = String.localizedString(for: LocalizedStringKey(type.localizedStringKey()).stringKey ?? "") | ||
let shortcutMenu = NSApp.mainMenu?.items.first(where: { $0.title == "Shortcut" }) | ||
let clearInput = shortcutMenu?.submenu?.items.first(where: { $0.title == shortcutTitle }) | ||
clearInput?.keyEquivalent = "" | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Easydict/NewApp/Utility/Extensions/String/String+Localized.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// String+Localized.swift | ||
// Easydict | ||
// | ||
// Created by Sharker on 2024/2/7. | ||
// Copyright © 2024 izual. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
// ref: https://stackoverflow.com/questions/60841915/how-to-change-localizedstringkey-to-string-in-swiftui | ||
extension LocalizedStringKey { | ||
// This will mirror the `LocalizedStringKey` so it can access its | ||
// internal `key` property. Mirroring is rather expensive, but it | ||
// should be fine performance-wise, unless you are | ||
// using it too much or doing something out of the norm. | ||
var stringKey: String? { | ||
Mirror(reflecting: self).children.first(where: { $0.label == "key" })?.value as? String | ||
} | ||
} | ||
|
||
extension String { | ||
static func localizedString(for key: String, | ||
locale: Locale = .current) -> String | ||
{ | ||
let language = locale.languageCode | ||
let path = Bundle.main.path(forResource: language, ofType: "lproj")! | ||
let bundle = Bundle(path: path)! | ||
let localizedString = NSLocalizedString(key, bundle: bundle, comment: "") | ||
|
||
return localizedString | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,4 @@ struct EasyDictMainMenu: Commands { | |
// shortcut | ||
MainMenuShortcutCommand() | ||
} | ||
|
||
func showAPIWebSite() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters