KMTTSWindowController.swift 24 KB

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