Repo // Simplify handling of localized strings.

This commit is contained in:
ShikiSuen 2022-09-01 15:31:39 +08:00
parent 8df60b8cdd
commit 667cd84441
13 changed files with 129 additions and 176 deletions

View File

@ -60,6 +60,7 @@ class AppDelegate: NSWindowController, NSApplicationDelegate {
guard
let installingVersion = Bundle.main.infoDictionary?[kCFBundleVersionKey as String]
as? String,
let window = window,
let versionString = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
else {
return
@ -71,7 +72,7 @@ class AppDelegate: NSWindowController, NSApplicationDelegate {
cancelButton.nextKeyView = installButton
installButton.nextKeyView = cancelButton
if let cell = installButton.cell as? NSButtonCell {
window?.defaultButtonCell = cell
window.defaultButtonCell = cell
}
if let copyrightLabel = Bundle.main.localizedInfoDictionary?["NSHumanReadableCopyright"]
@ -82,17 +83,12 @@ class AppDelegate: NSWindowController, NSApplicationDelegate {
if let eulaContent = Bundle.main.localizedInfoDictionary?["CFEULAContent"] as? String {
appEULAContent.string = eulaContent
}
appVersionLabel.stringValue = String(
format: "%@ Build %@", versionString, installingVersion
)
appVersionLabel.stringValue = "\(versionString) Build \(installingVersion)"
window?.title = String(
format: NSLocalizedString("%@ (for version %@, r%@)", comment: ""), window?.title ?? "",
versionString, installingVersion
)
window?.standardWindowButton(.closeButton)?.isHidden = true
window?.standardWindowButton(.miniaturizeButton)?.isHidden = true
window?.standardWindowButton(.zoomButton)?.isHidden = true
window.title = "\(window.title) (v\(versionString), Build \(installingVersion))"
window.standardWindowButton(.closeButton)?.isHidden = true
window.standardWindowButton(.miniaturizeButton)?.isHidden = true
window.standardWindowButton(.zoomButton)?.isHidden = true
if FileManager.default.fileExists(
atPath: kTargetPartialPath)
@ -114,8 +110,8 @@ class AppDelegate: NSWindowController, NSApplicationDelegate {
installButton.title = NSLocalizedString("Upgrade", comment: "")
}
window?.center()
window?.orderFront(self)
window.center()
window.orderFront(self)
NSApp.activate(ignoringOtherApps: true)
}
@ -126,14 +122,15 @@ class AppDelegate: NSWindowController, NSApplicationDelegate {
}
@objc func timerTick(_ timer: Timer) {
guard let window = window else { return }
let elapsed = Date().timeIntervalSince(translocationRemovalStartTime ?? Date())
if elapsed >= kTranslocationRemovalDeadline {
timer.invalidate()
window?.endSheet(progressSheet, returnCode: .cancel)
window.endSheet(progressSheet, returnCode: .cancel)
} else if isAppBundleTranslocated(atPath: kTargetPartialPath) == false {
progressIndicator.doubleValue = 1.0
timer.invalidate()
window?.endSheet(progressSheet, returnCode: .continue)
window.endSheet(progressSheet, returnCode: .continue)
}
}
@ -145,15 +142,17 @@ class AppDelegate: NSWindowController, NSApplicationDelegate {
// return
// }
guard let window = window else { return }
let shouldWaitForTranslocationRemoval =
isAppBundleTranslocated(atPath: kTargetPartialPath)
&& (window?.responds(to: #selector(NSWindow.beginSheet(_:completionHandler:))) ?? false)
&& window.responds(to: #selector(NSWindow.beginSheet(_:completionHandler:)))
//
do {
let sourceDir = kDestinationPartial
let fileManager = FileManager.default
let fileURLString = String(format: "%@/%@", sourceDir, kTargetBundle)
let fileURLString = sourceDir + "/" + kTargetBundle
let fileURL = URL(fileURLWithPath: fileURLString)
//
@ -176,7 +175,7 @@ class AppDelegate: NSWindowController, NSApplicationDelegate {
if shouldWaitForTranslocationRemoval {
progressIndicator.startAnimation(self)
window?.beginSheet(progressSheet) { returnCode in
window.beginSheet(progressSheet) { returnCode in
DispatchQueue.main.async {
if returnCode == .continue {
self.installInputMethod(

View File

@ -17,5 +17,3 @@
"Warning" = "Warning";
"Input method may not be fully enabled. Please enable it through System Preferences > Keyboard > Input Sources." = "Input method may not be fully enabled. Please enable it through System Preferences > Keyboard > Input Sources.";
"Continue" = "Continue";
"%@ (for version %@, r%@)" = "%@ (for version %@, r%@)";

View File

@ -17,5 +17,3 @@
"Warning" = "お知らせ";
"Input method may not be fully enabled. Please enable it through System Preferences > Keyboard > Input Sources." = "入力アプリの自動起動はうまく出来なかったかもしれません。ご自分で「システム環境設定→キーボード→入力ソース」で起動してください。";
"Continue" = "続行";
"%@ (for version %@, r%@)" = "%@ (for version %@, r%@)";

View File

@ -17,5 +17,3 @@
"Warning" = "安装不完整";
"Input method may not be fully enabled. Please enable it through System Preferences > Keyboard > Input Sources." = "输入法已经安装好,但可能没有完全启用。请从「系统偏好设定」 > 「键盘」 > 「输入方式」分页加入输入法。";
"Continue" = "继续";
"%@ (for version %@, r%@)" = "%@ (for version %@, r%@)";

View File

@ -17,5 +17,3 @@
"Warning" = "安裝不完整";
"Input method may not be fully enabled. Please enable it through System Preferences > Keyboard > Input Sources." = "輸入法已經安裝好,但可能沒有完全啟用。請從「系統偏好設定」 > 「鍵盤」 > 「輸入方式」分頁加入輸入法。";
"Continue" = "繼續";
"%@ (for version %@, r%@)" = "%@ (for version %@, r%@)";

View File

@ -24,12 +24,12 @@ extension ctlInputMethod {
if ShiftKeyUpChecker.check(event), !mgrPrefs.disableShiftTogglingAlphanumericalMode {
if !shouldUseHandle || (!rencentKeyHandledByKeyHandler && shouldUseHandle) {
NotifierController.notify(
message: String(
format: "%@%@%@", NSLocalizedString("Alphanumerical Mode", comment: ""), "\n",
toggleASCIIMode()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
)
message: NSLocalizedString("Alphanumerical Mode", comment: "") + "\n"
+ {
toggleASCIIMode()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
}()
)
}
if shouldUseHandle {

View File

@ -114,12 +114,13 @@ class ctlInputMethod: IMKInputController {
isASCIIMode = false
} else {
NotifierController.notify(
message: String(
format: "%@%@%@", NSLocalizedString("Alphanumerical Mode", comment: ""), "\n",
isASCIIMode
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
))
message: NSLocalizedString("Alphanumerical Mode", comment: "") + "\n"
+ {
isASCIIMode
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
}()
)
}
}

View File

@ -211,102 +211,109 @@ extension ctlInputMethod {
@objc func toggleSCPCTypingMode(_: Any? = nil) {
resetKeyHandler()
NotifierController.notify(
message: String(
format: "%@%@%@", NSLocalizedString("Per-Char Select Mode", comment: ""), "\n",
mgrPrefs.toggleSCPCTypingModeEnabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
))
message: NSLocalizedString("Per-Char Select Mode", comment: "") + "\n"
+ {
mgrPrefs.toggleSCPCTypingModeEnabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
}()
)
}
@objc func toggleChineseConverter(_: Any?) {
resetKeyHandler()
NotifierController.notify(
message: String(
format: "%@%@%@", NSLocalizedString("Force KangXi Writing", comment: ""), "\n",
mgrPrefs.toggleChineseConversionEnabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
))
message: NSLocalizedString("Force KangXi Writing", comment: "") + "\n"
+ {
mgrPrefs.toggleChineseConversionEnabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
}()
)
}
@objc func toggleShiftJISShinjitaiOutput(_: Any?) {
resetKeyHandler()
NotifierController.notify(
message: String(
format: "%@%@%@", NSLocalizedString("JIS Shinjitai Output", comment: ""), "\n",
mgrPrefs.toggleShiftJISShinjitaiOutputEnabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
))
message: NSLocalizedString("JIS Shinjitai Output", comment: "") + "\n"
+ {
mgrPrefs.toggleShiftJISShinjitaiOutputEnabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
}()
)
}
@objc func toggleCurrencyNumerals(_: Any?) {
resetKeyHandler()
NotifierController.notify(
message: String(
format: "%@%@%@", NSLocalizedString("Currency Numeral Output", comment: ""), "\n",
mgrPrefs.toggleCurrencyNumeralsEnabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
))
message: NSLocalizedString("Currency Numeral Output", comment: "") + "\n"
+ {
mgrPrefs.toggleCurrencyNumeralsEnabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
}()
)
}
@objc func toggleHalfWidthPunctuation(_: Any?) {
resetKeyHandler()
NotifierController.notify(
message: String(
format: "%@%@%@", NSLocalizedString("Half-Width Punctuation Mode", comment: ""),
"\n",
mgrPrefs.toggleHalfWidthPunctuationEnabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
))
message: NSLocalizedString("Half-Width Punctuation Mode", comment: "") + "\n"
+ {
mgrPrefs.toggleHalfWidthPunctuationEnabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
}()
)
}
@objc func toggleCNS11643Enabled(_: Any?) {
resetKeyHandler()
NotifierController.notify(
message: String(
format: "%@%@%@", NSLocalizedString("CNS11643 Mode", comment: ""), "\n",
mgrPrefs.toggleCNS11643Enabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
))
message: NSLocalizedString("CNS11643 Mode", comment: "") + "\n"
+ {
mgrPrefs.toggleCNS11643Enabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
}()
)
}
@objc func toggleSymbolEnabled(_: Any?) {
resetKeyHandler()
NotifierController.notify(
message: String(
format: "%@%@%@", NSLocalizedString("Symbol & Emoji Input", comment: ""), "\n",
mgrPrefs.toggleSymbolInputEnabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
))
message: NSLocalizedString("Symbol & Emoji Input", comment: "") + "\n"
+ {
mgrPrefs.toggleSymbolInputEnabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
}()
)
}
@objc func toggleAssociatedPhrasesEnabled(_: Any?) {
resetKeyHandler()
NotifierController.notify(
message: String(
format: "%@%@%@", NSLocalizedString("Per-Char Associated Phrases", comment: ""),
"\n",
mgrPrefs.toggleAssociatedPhrasesEnabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
))
message: NSLocalizedString("Per-Char Associated Phrases", comment: "") + "\n"
+ {
mgrPrefs.toggleAssociatedPhrasesEnabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
}()
)
}
@objc func togglePhraseReplacement(_: Any?) {
resetKeyHandler()
NotifierController.notify(
message: String(
format: "%@%@%@", NSLocalizedString("Use Phrase Replacement", comment: ""), "\n",
mgrPrefs.togglePhraseReplacementEnabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
))
message: NSLocalizedString("Use Phrase Replacement", comment: "") + "\n"
+ {
mgrPrefs.togglePhraseReplacementEnabled()
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
}()
)
}
@objc func selfUninstall(_: Any?) {

View File

@ -54,54 +54,30 @@ class SymbolNode {
// MARK: - Static data.
static let catCommonSymbols = String(
format: NSLocalizedString("catCommonSymbols", comment: ""))
static let catHoriBrackets = String(
format: NSLocalizedString("catHoriBrackets", comment: ""))
static let catVertBrackets = String(
format: NSLocalizedString("catVertBrackets", comment: ""))
static let catAlphabets = String(
format: NSLocalizedString("catAlphabets", comment: ""))
static let catSpecialNumbers = String(
format: NSLocalizedString("catSpecialNumbers", comment: ""))
static let catMathSymbols = String(
format: NSLocalizedString("catMathSymbols", comment: ""))
static let catCurrencyUnits = String(
format: NSLocalizedString("catCurrencyUnits", comment: ""))
static let catSpecialSymbols = String(
format: NSLocalizedString("catSpecialSymbols", comment: ""))
static let catUnicodeSymbols = String(
format: NSLocalizedString("catUnicodeSymbols", comment: ""))
static let catCircledKanjis = String(
format: NSLocalizedString("catCircledKanjis", comment: ""))
static let catCircledKataKana = String(
format: NSLocalizedString("catCircledKataKana", comment: ""))
static let catBracketKanjis = String(
format: NSLocalizedString("catBracketKanjis", comment: ""))
static let catSingleTableLines = String(
format: NSLocalizedString("catSingleTableLines", comment: ""))
static let catDoubleTableLines = String(
format: NSLocalizedString("catDoubleTableLines", comment: ""))
static let catFillingBlocks = String(
format: NSLocalizedString("catFillingBlocks", comment: ""))
static let catLineSegments = String(
format: NSLocalizedString("catLineSegments", comment: ""))
static let catKana = String(
format: NSLocalizedString("catKana", comment: ""))
static let catCombinations = String(
format: NSLocalizedString("catCombinations", comment: ""))
static let catPhonabets = String(
format: NSLocalizedString("catPhonabets", comment: ""))
static let catCircledASCII = String(
format: NSLocalizedString("catCircledASCII", comment: ""))
static let catBracketedASCII = String(
format: NSLocalizedString("catBracketedASCII", comment: ""))
static let catMusicSymbols = String(
format: NSLocalizedString("catMusicSymbols", comment: ""))
static let catThai = String(
format: NSLocalizedString("catThai", comment: ""))
static let catYi = String(
format: NSLocalizedString("catYi", comment: ""))
static let catCommonSymbols = NSLocalizedString("catCommonSymbols", comment: "")
static let catHoriBrackets = NSLocalizedString("catHoriBrackets", comment: "")
static let catVertBrackets = NSLocalizedString("catVertBrackets", comment: "")
static let catAlphabets = NSLocalizedString("catAlphabets", comment: "")
static let catSpecialNumbers = NSLocalizedString("catSpecialNumbers", comment: "")
static let catMathSymbols = NSLocalizedString("catMathSymbols", comment: "")
static let catCurrencyUnits = NSLocalizedString("catCurrencyUnits", comment: "")
static let catSpecialSymbols = NSLocalizedString("catSpecialSymbols", comment: "")
static let catUnicodeSymbols = NSLocalizedString("catUnicodeSymbols", comment: "")
static let catCircledKanjis = NSLocalizedString("catCircledKanjis", comment: "")
static let catCircledKataKana = NSLocalizedString("catCircledKataKana", comment: "")
static let catBracketKanjis = NSLocalizedString("catBracketKanjis", comment: "")
static let catSingleTableLines = NSLocalizedString("catSingleTableLines", comment: "")
static let catDoubleTableLines = NSLocalizedString("catDoubleTableLines", comment: "")
static let catFillingBlocks = NSLocalizedString("catFillingBlocks", comment: "")
static let catLineSegments = NSLocalizedString("catLineSegments", comment: "")
static let catKana = NSLocalizedString("catKana", comment: "")
static let catCombinations = NSLocalizedString("catCombinations", comment: "")
static let catPhonabets = NSLocalizedString("catPhonabets", comment: "")
static let catCircledASCII = NSLocalizedString("catCircledASCII", comment: "")
static let catBracketedASCII = NSLocalizedString("catBracketedASCII", comment: "")
static let catMusicSymbols = NSLocalizedString("catMusicSymbols", comment: "")
static let catThai = NSLocalizedString("catThai", comment: "")
static let catYi = NSLocalizedString("catYi", comment: "")
private(set) static var root: SymbolNode = .init("/")

View File

@ -63,28 +63,20 @@ enum mgrLangModel {
}
if !gLangModelCHT.isLanguageModelLoaded {
NotifierController.notify(
message: String(
format: "%@", NSLocalizedString("Loading CHT Core Dict...", comment: "")
)
message: NSLocalizedString("Loading CHT Core Dict...", comment: "")
)
loadCoreLanguageModelFile(filenameSansExtension: "data-cht", langModel: &gLangModelCHT)
NotifierController.notify(
message: String(
format: "%@", NSLocalizedString("Core Dict loading complete.", comment: "")
)
message: NSLocalizedString("Core Dict loading complete.", comment: "")
)
}
if !gLangModelCHS.isLanguageModelLoaded {
NotifierController.notify(
message: String(
format: "%@", NSLocalizedString("Loading CHS Core Dict...", comment: "")
)
message: NSLocalizedString("Loading CHS Core Dict...", comment: "")
)
loadCoreLanguageModelFile(filenameSansExtension: "data-chs", langModel: &gLangModelCHS)
NotifierController.notify(
message: String(
format: "%@", NSLocalizedString("Core Dict loading complete.", comment: "")
)
message: NSLocalizedString("Core Dict loading complete.", comment: "")
)
}
}
@ -102,15 +94,11 @@ enum mgrLangModel {
}
if !gLangModelCHS.isLanguageModelLoaded {
NotifierController.notify(
message: String(
format: "%@", NSLocalizedString("Loading CHS Core Dict...", comment: "")
)
message: NSLocalizedString("Loading CHS Core Dict...", comment: "")
)
loadCoreLanguageModelFile(filenameSansExtension: "data-chs", langModel: &gLangModelCHS)
NotifierController.notify(
message: String(
format: "%@", NSLocalizedString("Core Dict loading complete.", comment: "")
)
message: NSLocalizedString("Core Dict loading complete.", comment: "")
)
}
} else if mode == InputMode.imeModeCHT {
@ -125,15 +113,11 @@ enum mgrLangModel {
}
if !gLangModelCHT.isLanguageModelLoaded {
NotifierController.notify(
message: String(
format: "%@", NSLocalizedString("Loading CHT Core Dict...", comment: "")
)
message: NSLocalizedString("Loading CHT Core Dict...", comment: "")
)
loadCoreLanguageModelFile(filenameSansExtension: "data-cht", langModel: &gLangModelCHT)
NotifierController.notify(
message: String(
format: "%@", NSLocalizedString("Core Dict loading complete.", comment: "")
)
message: NSLocalizedString("Core Dict loading complete.", comment: "")
)
}
}

View File

@ -36,9 +36,7 @@ class ctlAboutWindow: NSWindowController {
if let eulaContent = Bundle.main.localizedInfoDictionary?["CFEULAContent"] as? String {
appEULAContent.string = eulaContent
}
appVersionLabel.stringValue = String(
format: "%@ Build %@", versionString, installingVersion
)
appVersionLabel.stringValue = "\(versionString) Build \(installingVersion)"
}
@IBAction func btnBugReport(_: NSButton) {

View File

@ -100,15 +100,13 @@ class ctlPrefWindow: NSWindowController {
basicKeyboardLayoutButton.menu?.removeAllItems()
let itmAppleZhuyinBopomofo = NSMenuItem()
itmAppleZhuyinBopomofo.title = String(
format: NSLocalizedString("Apple Zhuyin Bopomofo (Dachen)", comment: ""))
itmAppleZhuyinBopomofo.title = NSLocalizedString("Apple Zhuyin Bopomofo (Dachen)", comment: "")
itmAppleZhuyinBopomofo.representedObject = String(
"com.apple.keylayout.ZhuyinBopomofo")
basicKeyboardLayoutButton.menu?.addItem(itmAppleZhuyinBopomofo)
let itmAppleZhuyinEten = NSMenuItem()
itmAppleZhuyinEten.title = String(
format: NSLocalizedString("Apple Zhuyin Eten (Traditional)", comment: ""))
itmAppleZhuyinEten.title = NSLocalizedString("Apple Zhuyin Eten (Traditional)", comment: "")
itmAppleZhuyinEten.representedObject = String("com.apple.keylayout.ZhuyinEten")
basicKeyboardLayoutButton.menu?.addItem(itmAppleZhuyinEten)

View File

@ -36,9 +36,7 @@ import Cocoa
if let eulaContent = Bundle.main.localizedInfoDictionary?["CFEULAContent"] as? String {
appEULAContent.string = eulaContent
}
appVersionLabel.stringValue = String(
format: "%@ Build %@", versionString, installingVersion
)
appVersionLabel.stringValue = "\(versionString) Build \(installingVersion)"
}
@IBAction func btnWebsite(_: NSButton) {