KMTTSWindowController.swift 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. //
  2. // KMTTSWindowController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by liujiajie on 2023/12/12.
  6. //
  7. import Cocoa
  8. typealias TTSCloseWindowCallback = (_ isCloseWindow: Bool) -> Void
  9. let minSpeed: Float = 0.6
  10. let maxSpeed: Float = 5.0
  11. let standardSpeed: Float = 175.0
  12. class KMTTSWindowController: NSWindowController, KMTTSManagerDelegate, NSWindowDelegate, NSTextFieldDelegate{
  13. var pdfView: CPDFView!
  14. var closeWindowCallback: TTSCloseWindowCallback?
  15. @IBOutlet var sontinuouButton: NSButton!
  16. @IBOutlet var speedLabel: NSTextField!
  17. @IBOutlet var languageLabel: NSTextField!
  18. @IBOutlet var languageComboBox: NSPopUpButton!
  19. @IBOutlet var speedTextField: NSTextField!
  20. @IBOutlet var speedSlider: NSSlider!
  21. @IBOutlet var speedStepper: NSStepper!
  22. @IBOutlet var nextButton: KMToolbarItem!
  23. @IBOutlet var forwardButton: KMToolbarItem!
  24. @IBOutlet var playButton: KMToolbarItem!
  25. @IBOutlet var speedBox: NSBox!
  26. @IBOutlet var sppendCountLabel: NSTextField!
  27. var pdfSelection: CPDFSelection?
  28. var currentPageIndex: Int = 0
  29. var isChangePage = false
  30. var voiceArrays = NSMutableArray()
  31. static let share = KMTTSWindowController()
  32. convenience init() {
  33. self.init(windowNibName: "KMTTSWindowController")
  34. }
  35. deinit {
  36. DistributedNotificationCenter.default().removeObserver(self)
  37. NotificationCenter.default.removeObserver(self)
  38. }
  39. override func windowDidLoad() {
  40. super.windowDidLoad()
  41. self.window?.title = NSLocalizedString("TTS", comment: "")
  42. self.speedStepper.minValue = Double(minSpeed)
  43. self.speedStepper.maxValue = Double(maxSpeed);
  44. self.speedSlider.minValue = Double(minSpeed);
  45. self.speedSlider.maxValue = Double(maxSpeed);
  46. self.nextButton.toolTip = KMLocalizedString("Next Page", nil)
  47. self.forwardButton.toolTip = KMLocalizedString("Previous Page", nil)
  48. self.speedSlider.isEnabled = true
  49. self.speedStepper.isEnabled = true
  50. self.playButton.toolTip = KMLocalizedString("Play", nil)
  51. self.sppendCountLabel.stringValue = KMLocalizedString("SpeedX", nil)
  52. let str = String(format: "%.1f", KMTTSManager.defalutManager.rate/Float(standardSpeed))
  53. self.speedStepper.stringValue = str
  54. self.speedTextField.stringValue = str
  55. self.speedSlider.stringValue = str
  56. self.sontinuouButton.title = KMLocalizedString("Continuous Reading", nil);
  57. self.speedLabel.stringValue = KMLocalizedString("Speed", nil) + ":"
  58. self.languageLabel.stringValue = KMLocalizedString("Language", nil) + ":"
  59. let array = KMTTSManager.defalutManager.availableVoices()
  60. let currentVoicName = KMTTSManager.defalutManager.voice()
  61. var currentIndex = 0
  62. let menu = NSMenu()
  63. for voiceType: NSSpeechSynthesizer.VoiceName in array {
  64. let voiceDic = NSMutableDictionary()
  65. // let dic = KMTTSManager.defalutManager.attributesForVoice(voiceType)
  66. let voiceLocaleIdentifier = ( NSSpeechSynthesizer.attributes( forVoice: voiceType )[ NSSpeechSynthesizer.VoiceAttributeKey.localeIdentifier ] as! String )
  67. let name = self.switchLanguage(withCode: voiceLocaleIdentifier)
  68. voiceDic["voiceType"] = voiceType
  69. voiceDic["voiceName"] = name
  70. voiceArrays.add(voiceDic)
  71. }
  72. voiceArrays = self.sortArray(voiceArrays)
  73. for i in 0..<voiceArrays.count {
  74. let voiceDic = voiceArrays[i] as! NSDictionary
  75. let voiceType = voiceDic.object(forKey: "voiceType") as! NSSpeechSynthesizer.VoiceName
  76. if currentVoicName == voiceType {
  77. currentIndex = i
  78. }
  79. let dic = KMTTSManager.defalutManager.attributesForVoice(voiceType) as NSDictionary
  80. let code = ( NSSpeechSynthesizer.attributes( forVoice: voiceType )[ NSSpeechSynthesizer.VoiceAttributeKey.localeIdentifier ] as! String )
  81. var languageStaring: String? = nil
  82. let voiceName = ( NSSpeechSynthesizer.attributes( forVoice: voiceType )[ NSSpeechSynthesizer.VoiceAttributeKey.name ] as! String )
  83. let name = self.switchLanguage(withCode: code)
  84. if voiceName.count > 0 {
  85. languageStaring = "\(name)(\(voiceName))"
  86. }
  87. let font = NSFont.systemFont(ofSize: 12.0)
  88. let namefont = NSFont.systemFont(ofSize: 10.0)
  89. let textRowSpace = NSMutableAttributedString(string: languageStaring ?? "")
  90. textRowSpace.addAttribute(.font, value: font, range: NSRange(location: 0, length: name.count))
  91. textRowSpace.addAttribute(.font, value: namefont, range: NSRange(location: name.count, length: languageStaring!.count - name.count))
  92. let item = NSMenuItem()
  93. item.attributedTitle = textRowSpace
  94. menu.addItem(item)
  95. }
  96. self.languageComboBox.menu = menu
  97. self.languageComboBox.selectItem(at: currentIndex)
  98. KMTTSManager.defalutManager.delegate = self
  99. self.updateViewColor()
  100. self.window?.standardWindowButton(.zoomButton)?.isHidden = true
  101. if KMTTSManager.defalutManager.isContinue {
  102. self.sontinuouButton.state = .on
  103. } else {
  104. self.sontinuouButton.state = .off
  105. }
  106. DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChanged(notification:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
  107. NotificationCenter.default.addObserver(self, selector: #selector(handlePageChangedNotification), name: NSNotification.Name.CPDFViewPageChanged, object: self.pdfView)
  108. }
  109. func updateViewColor() {
  110. var viewBackcolor = NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
  111. var textColor = NSColor(red: 51.0/255.0, green: 51.0/255.0, blue: 51.0/255.0, alpha: 1.0)
  112. var contentColor = NSColor(red: 102.0/255.0, green: 102.0/255.0, blue: 102.0/255.0, alpha: 1.0)
  113. var fillColor = NSColor.white
  114. if #available(macOS 10.14, *) {
  115. let appearanceName = NSApp.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua])
  116. if appearanceName == .darkAqua {
  117. viewBackcolor = NSColor(red: 69.0/255.0, green: 69.0/255.0, blue: 71.0/255.0, alpha: 1.0)
  118. textColor = NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
  119. contentColor = NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 0.6)
  120. fillColor = NSColor(red: 101.0/255.0, green: 101.0/255.0, blue: 101.0/255.0, alpha: 1.0)
  121. }
  122. }
  123. self.window?.backgroundColor = viewBackcolor
  124. self.window?.isMovableByWindowBackground = true
  125. self.languageLabel.textColor = contentColor
  126. self.speedLabel.textColor = contentColor
  127. self.speedTextField.textColor = textColor
  128. self.speedBox.fillColor = fillColor
  129. self.sontinuouButton.setTitleColor(contentColor)
  130. }
  131. @objc func themeChanged(notification: NSNotification) {
  132. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  133. self.updateViewColor()
  134. }
  135. }
  136. @objc func handlePageChangedNotification(notification: NSNotification) {
  137. guard let PDFView = notification.object as? CPDFView else { return }
  138. if PDFView == self.pdfView {
  139. if self.pdfView.canGoToNextPage() {
  140. self.nextButton.isEnabled = true
  141. } else{
  142. self.nextButton.isEnabled = false
  143. }
  144. if self.pdfView.canGoToPreviousPage() {
  145. self.forwardButton.isEnabled = true
  146. } else {
  147. self.forwardButton.isEnabled = false
  148. }
  149. }
  150. }
  151. func sortArray(_ array: NSArray) -> NSMutableArray {
  152. let sortDesc = [NSSortDescriptor(key: "voiceName", ascending: true)]
  153. let sortedArr = array.sortedArray(using: sortDesc) as NSArray
  154. let tArray = NSMutableArray(array: sortedArr)
  155. return tArray
  156. }
  157. func windowShouldClose(_ sender: NSWindow) -> Bool {
  158. self.stopSpeaking()
  159. if let callBlack = closeWindowCallback {
  160. callBlack(true)
  161. }
  162. return true
  163. }
  164. override func showWindow(_ sender: Any?) {
  165. super.showWindow(sender)
  166. self.isChangePage = false
  167. if self.pdfView.canGoToNextPage() {
  168. self.nextButton.isEnabled = true
  169. } else{
  170. self.nextButton.isEnabled = false
  171. }
  172. if self.pdfView.canGoToPreviousPage() {
  173. self.forwardButton.isEnabled = true
  174. } else {
  175. self.forwardButton.isEnabled = false
  176. }
  177. }
  178. func stopSpeaking() {
  179. if KMTTSManager.defalutManager.isSpeaking() || KMTTSManager.defalutManager.isPaused {
  180. self.isChangePage = true
  181. KMTTSManager.defalutManager.stopSpeaking()
  182. self.speedSlider.isEnabled = true
  183. self.speedStepper.isEnabled = true
  184. self.playButton.image = NSImage(named: "KMImageNameTTSStop")
  185. self.playButton.toolTip = NSLocalizedString("Play", comment: "")
  186. self.pdfView.setHighlightedSelections([])
  187. }
  188. self.pdfSelection = nil
  189. self.pdfView = nil
  190. }
  191. func quikeStartSpeakingPDFPage(_ page: CPDFPage) {
  192. if KMTTSManager.defalutManager.isSpeaking() || KMTTSManager.defalutManager.isPaused {
  193. KMTTSManager.defalutManager.stopSpeaking()
  194. self.isChangePage = true
  195. }
  196. self.currentPageIndex = Int(self.pdfView.document?.index(for: page) ?? 0)
  197. self.startSpeakingPDFPage(page)
  198. }
  199. func startSpeakingPDFPage(_ page: CPDFPage) {
  200. let dex = self.languageComboBox.indexOfSelectedItem
  201. if dex >= 0 && dex < self.voiceArrays.count {
  202. let dic: NSMutableDictionary = self.voiceArrays[dex] as! NSMutableDictionary
  203. if let voiceName = dic["voiceType"] {
  204. KMTTSManager.defalutManager.setVoice(voice: voiceName as! NSSpeechSynthesizer.VoiceName)
  205. }
  206. }
  207. KMTTSManager.defalutManager.rate = self.speedSlider.floatValue * Float(standardSpeed)
  208. let isSuccess = KMTTSManager.defalutManager.startSpeakingPDFPage(page)
  209. if isSuccess {
  210. self.playButton.image = NSImage(named: "KMImageNameTTSPause")
  211. self.playButton.toolTip = NSLocalizedString("Pause", comment: "")
  212. self.speedSlider.isEnabled = false
  213. self.speedStepper.isEnabled = false
  214. } else {
  215. self.playButton.image = NSImage(named: "KMImageNameTTSStop")
  216. self.playButton.toolTip = NSLocalizedString("Play", comment: "")
  217. self.speedSlider.isEnabled = true
  218. self.speedStepper.isEnabled = true
  219. }
  220. }
  221. func startSpeakingPDFSelection(_ selection: CPDFSelection) {
  222. if KMTTSManager.defalutManager.isSpeaking() || KMTTSManager.defalutManager.isPaused {
  223. KMTTSManager.defalutManager.stopSpeaking()
  224. self.isChangePage = true
  225. }
  226. self.pdfSelection = selection
  227. self.pdfView?.setCurrentSelection(nil, animate: false)
  228. let dex = self.languageComboBox.indexOfSelectedItem
  229. if dex >= 0 && dex < self.voiceArrays.count {
  230. let dic: NSMutableDictionary = self.voiceArrays[dex] as! NSMutableDictionary
  231. if let voiceName = dic["voiceType"] as? NSSpeechSynthesizer.VoiceName {
  232. KMTTSManager.defalutManager.setVoice(voice: voiceName)
  233. }
  234. }
  235. KMTTSManager.defalutManager.rate = self.speedSlider.floatValue * Float(standardSpeed)
  236. let isSuccess = KMTTSManager.defalutManager.startSpeakingPDFSelection(selection)
  237. if isSuccess {
  238. self.speedSlider.isEnabled = false
  239. self.speedStepper.isEnabled = false
  240. self.playButton.image = NSImage(named: "KMImageNameTTSPause")
  241. self.playButton.toolTip = NSLocalizedString("Pause", comment: "")
  242. } else {
  243. self.speedSlider.isEnabled = true
  244. self.speedStepper.isEnabled = true
  245. self.playButton.image = NSImage(named: "KMImageNameTTSStop")
  246. self.playButton.toolTip = NSLocalizedString("Play", comment: "")
  247. }
  248. }
  249. @IBAction func buttonItemClick_Next(_ sender: NSButton) {
  250. if (KMTTSManager.defalutManager.isSpeaking()) {
  251. var currentPageNum = self.currentPageIndex;
  252. var page: CPDFPage?
  253. if (currentPageNum + 1 < self.pdfView.document.pageCount) {
  254. page = self.pdfView.document.page(at: UInt(currentPageNum+1))
  255. self.currentPageIndex = currentPageNum + 1;
  256. } else {
  257. page = self.pdfView.document.page(at: self.pdfView.document.pageCount - 1)
  258. self.currentPageIndex = Int(self.pdfView.document.pageCount - 1)
  259. }
  260. self.pdfView.go(to: page)
  261. self.isChangePage = true
  262. self.startSpeakingPDFPage(page!)
  263. }
  264. }
  265. @IBAction func buttonItemClick_Forward(_ sender: NSButton) {
  266. if (KMTTSManager.defalutManager.isSpeaking()) {
  267. var currentPageNum = self.currentPageIndex;
  268. var page: CPDFPage?
  269. if (currentPageNum - 1 < 0) {
  270. page = self.pdfView.document.page(at: 0)
  271. self.currentPageIndex = 0;
  272. } else {
  273. page = self.pdfView.document.page(at: UInt(currentPageNum - 1))
  274. self.currentPageIndex = currentPageNum - 1
  275. }
  276. self.pdfView.go(to: page)
  277. self.isChangePage = true
  278. self.startSpeakingPDFPage(page!)
  279. }
  280. }
  281. @IBAction func buttonItemClick_Play(_ sender: KMToolbarItem) {
  282. if (KMTTSManager.defalutManager.isPaused) {
  283. self.playButton.image = NSImage(named: "KMImageNameTTSPause")
  284. self.playButton.toolTip = KMLocalizedString("Pause", nil)
  285. self.speedSlider.isEnabled = false
  286. self.speedStepper.isEnabled = false
  287. KMTTSManager.defalutManager.continueSpeaking()
  288. } else if (KMTTSManager.defalutManager.isSpeaking()) {
  289. self.isChangePage = true
  290. self.playButton.image = NSImage(named: "KMImageNameTTSStop")
  291. self.playButton.toolTip = KMLocalizedString("Play", nil)
  292. self.speedSlider.isEnabled = true
  293. self.speedStepper.isEnabled = true
  294. self.pdfView.setHighlightedSelection(nil, animated: false)
  295. KMTTSManager.defalutManager.pauseSpeaking()
  296. } else {
  297. if ((self.pdfSelection) != nil) {
  298. self.startSpeakingPDFSelection(self.pdfSelection!)
  299. } else {
  300. let page = self.pdfView.currentPage()
  301. self.currentPageIndex = self.pdfView.currentPageIndex
  302. if page != nil {
  303. self.startSpeakingPDFPage(page!)
  304. }
  305. }
  306. }
  307. }
  308. @IBAction func buttonItemClick_Continue(_ sender: NSButton) {
  309. KMTTSManager.defalutManager.isContinue = !(KMTTSManager.defalutManager.isContinue)
  310. }
  311. @IBAction func stepperItemClick_Speed(_ sender: NSButton) {
  312. var rate = self.speedStepper.floatValue
  313. let str = String(format: "%.1f", rate)
  314. self.speedStepper.stringValue = str
  315. self.speedTextField.stringValue = str
  316. self.speedSlider.stringValue = str
  317. rate = Float(standardSpeed) * rate
  318. KMTTSManager.defalutManager.rate = rate
  319. }
  320. @IBAction func sliderItemClick_Speed(_ sender: NSButton) {
  321. var rate: CGFloat = CGFloat(self.speedSlider.floatValue)
  322. let str = String(format: "%.1f", rate)
  323. self.speedStepper.stringValue = str
  324. self.speedTextField.stringValue = str
  325. self.speedSlider.stringValue = str
  326. rate = CGFloat(standardSpeed) * rate
  327. KMTTSManager.defalutManager.rate = Float(rate)
  328. }
  329. @IBAction func buttonItemClick_Language(_ sender: NSButton) {
  330. if KMTTSManager.defalutManager.isSpeaking() {
  331. self.isChangePage = true
  332. if let pdfSelection = self.pdfSelection {
  333. self.startSpeakingPDFSelection(pdfSelection)
  334. } else {
  335. let currentPageInd = self.currentPageIndex
  336. if currentPageInd < (self.pdfView.document.pageCount - 1) {
  337. let page = self.pdfView.document.page(at: UInt(currentPageInd))
  338. self.startSpeakingPDFPage(page!)
  339. }
  340. }
  341. }
  342. }
  343. override func mouseDown(with event: NSEvent) {
  344. super.mouseDown(with: event)
  345. self.window?.makeFirstResponder(self)
  346. }
  347. //MARK: KMTTSManagerDelegate
  348. func ttsMananger(_ tts: KMTTSManager, willSpeak selection: CPDFSelection) {
  349. // if (selection != nil) {
  350. self.pdfView?.setHighlightedSelection(selection, animated: false)
  351. // }
  352. }
  353. func ttsManangerDidFinishSpeech(_ tts: KMTTSManager) -> Bool {
  354. var isFinish = true
  355. if self.pdfSelection != nil {
  356. self.pdfSelection = nil
  357. self.pdfView.setHighlightedSelections(nil)
  358. self.playButton.image = NSImage(named: "KMImageNameTTSStop")
  359. self.speedSlider.isEnabled = true
  360. self.speedStepper.isEnabled = true
  361. self.playButton.toolTip = KMLocalizedString("Play", nil)
  362. } else {
  363. if KMTTSManager.defalutManager.isContinue {
  364. if !isChangePage {
  365. if let pdfSelection = self.pdfSelection {
  366. self.pdfView.setHighlightedSelections(nil)
  367. self.playButton.image = NSImage(named: "KMImageNameTTSStop")
  368. self.speedSlider.isEnabled = true
  369. self.speedStepper.isEnabled = true
  370. self.playButton.toolTip = KMLocalizedString("Play", nil)
  371. } else {
  372. let currentPageIndex = self.currentPageIndex
  373. if currentPageIndex + 1 < self.pdfView.document.pageCount {
  374. let page = self.pdfView.document.page(at: UInt(currentPageIndex+1))
  375. self.currentPageIndex = currentPageIndex+1
  376. self.pdfView.go(to: page)
  377. self.startSpeakingPDFPage(page!)
  378. isFinish = false
  379. } else {
  380. self.pdfView.setHighlightedSelections(nil)
  381. self.playButton.image = NSImage(named: "KMImageNameTTSStop")
  382. self.speedSlider.isEnabled = true
  383. self.speedStepper.isEnabled = true
  384. self.playButton.toolTip = KMLocalizedString("Play", nil)
  385. }
  386. }
  387. }
  388. } else {
  389. if !isChangePage {
  390. self.speedSlider.isEnabled = true
  391. self.speedStepper.isEnabled = true
  392. self.pdfView.setHighlightedSelections(nil)
  393. self.playButton.image = NSImage(named: "KMImageNameTTSStop")
  394. self.playButton.toolTip = KMLocalizedString("Play", nil)
  395. }
  396. }
  397. if isChangePage {
  398. isChangePage = false
  399. }
  400. }
  401. return isFinish
  402. }
  403. func ttsManangerdidErrorSpeech(_ tts: KMTTSManager, message: String) {
  404. }
  405. //MARK: NSTextFieldDelegate
  406. func controlTextDidEndEditing(_ obj: Notification) {
  407. if let textField = obj.object as? NSTextField {
  408. if textField == self.speedTextField {
  409. var rate: Float = Float(textField.stringValue) ?? 0
  410. if maxSpeed - rate < 0 {
  411. rate = maxSpeed
  412. } else if rate - minSpeed < 0 {
  413. rate = minSpeed
  414. }
  415. self.speedStepper.stringValue = String(format: "%.1f", rate)
  416. self.speedTextField.stringValue = String(format: "%.1f", rate)
  417. self.speedSlider.stringValue = String(format: "%.1f", rate)
  418. rate = standardSpeed * rate
  419. KMTTSManager.defalutManager.rate = rate
  420. }
  421. }
  422. }
  423. func switchLanguage(withCode code: String) -> String {
  424. var language = code
  425. if code == "ar_SA" {
  426. language = "Arabic (Saudi Arabia)"
  427. } else if code == "cs_CZ" {
  428. language = "Czech (Czech republic)"
  429. } else if code == "da_DK" {
  430. language = "Danish (Denmark)"
  431. } else if code == "de_DE" {
  432. language = "German (Germany)"
  433. } else if code == "el_GR" {
  434. language = "Greek (Greece)"
  435. } else if code == "en_AU" {
  436. language = "English (Australia)"
  437. } else if code == "en_GB" {
  438. language = "English (UK)"
  439. } else if code == "en_IE" {
  440. language = "English (Ireland)"
  441. } else if code == "en_US" {
  442. language = "English"
  443. } else if code == "en_ZA" {
  444. language = "English (South Africa)"
  445. } else if code == "es_ES" {
  446. language = "Spanish (Spain)"
  447. } else if code == "es_MX" {
  448. language = "Spanish (Mexico)"
  449. } else if code == "fi_FI" {
  450. language = "Finnish (Finland)"
  451. } else if code == "fr_CA" {
  452. language = "French (Canada)"
  453. } else if code == "fr_FR" {
  454. language = "French (France)"
  455. } else if code == "he_IL" {
  456. language = "Hebrew"
  457. } else if code == "hi_IN" {
  458. language = "Hindi (India)"
  459. } else if code == "hu_HU" {
  460. language = "Hungarian (Hungary)"
  461. } else if code == "id_ID" {
  462. language = "Indonesian (Indonesia)"
  463. } else if code == "it_IT" {
  464. language = "Italian (Italy)"
  465. } else if code == "ja_JP" {
  466. language = "日本語"
  467. } else if code == "ko_KR" {
  468. language = "Korean (South Korea)"
  469. } else if code == "nl_BE" {
  470. language = "Dutch (Belgium)"
  471. } else if code == "nl_NL" {
  472. language = "Dutch (Holland)"
  473. } else if code == "nb_NO" {
  474. language = "Norwegian (Norway)"
  475. } else if code == "pl_PL" {
  476. language = "Polish (Poland)"
  477. } else if code == "pt_BR" {
  478. language = "Portuguese (Brazil)"
  479. } else if code == "pt_PT" {
  480. language = "Portuguese (Portugal)"
  481. } else if code == "ro_RO" {
  482. language = "Romanian (Romania)"
  483. } else if code == "ru_RU" {
  484. language = "Russian (Russia)"
  485. } else if code == "sk_SK" {
  486. language = "Slovakia (Slovakia)"
  487. } else if code == "sv_SE" {
  488. language = "Swe (Sweden)"
  489. } else if code == "th_TH" {
  490. language = "Thai (Thailand)"
  491. } else if code == "tr_TR" {
  492. language = "Turkish (Turkey)"
  493. } else if code == "zh_CN" {
  494. language = "简体中文"
  495. } else if code == "zh_HK" {
  496. language = "繁體中文 (香港)"
  497. } else if code == "zh_TW" {
  498. language = "繁體中文 (台灣)"
  499. } else if code == "en_IN" {
  500. language = "English"
  501. }
  502. return language
  503. }
  504. }