AppMenuLocalizer.swift 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // AppMenuLocalizer.swift
  3. // App for Indeed
  4. //
  5. import Cocoa
  6. /// Applies in-app language to the main menu and window chrome (storyboard defaults are English).
  7. enum AppMenuLocalizer {
  8. static func apply() {
  9. let appName = AppMarketingLinks.appDisplayName
  10. if let window = AppWindowConfiguration.mainWindow() {
  11. window.title = appName
  12. }
  13. if let item = NSApp.delegate as? AppDelegate {
  14. item.refreshMainWindowMenuItemTitle()
  15. }
  16. guard let mainMenu = NSApp.mainMenu,
  17. let appMenuItem = mainMenu.items.first,
  18. let appMenu = appMenuItem.submenu else { return }
  19. appMenuItem.title = appName
  20. for item in appMenu.items {
  21. let action = item.action
  22. if action == #selector(NSApplication.orderFrontStandardAboutPanel(_:)) {
  23. item.title = String(format: L("About %@"), appName)
  24. } else if action == #selector(NSApplication.hide(_:)) {
  25. item.title = String(format: L("Hide %@"), appName)
  26. } else if action == #selector(NSApplication.terminate(_:)) {
  27. item.title = String(format: L("Quit %@"), appName)
  28. } else if item.keyEquivalent == "," {
  29. item.title = L("Preferences…")
  30. }
  31. }
  32. }
  33. }