Skip to content

Commit

Permalink
#44
Browse files Browse the repository at this point in the history
language picker displays the current language after choosing and restart editor
  • Loading branch information
Casey committed Jan 5, 2021
1 parent e1b67d0 commit 4f5b2f4
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions widgets/ToolBar.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def __init__(self, actionManager, parent=None):
self.cb = QComboBox()
self.cb.addItems(["Chinese", "English", "Tibetan"])
self.cb.currentIndexChanged.connect(self.onSelectionchange)

self.addWidget(self.cb)

if self.cb.currentText() == 'Chinese':
Expand All @@ -33,13 +32,21 @@ def __init__(self, actionManager, parent=None):
else:
value = 'tibetan'

language = Setting.objects.filter(key='language')
if not language:
if not Setting.objects.filter(key='language').exists():
Setting.objects.create(
key='language',
value=value
)

# 一開始的,也要顯示上次選擇後的當前語言
language = Setting.objects.get(key='language')
if language.value == 'zh-hant':
self.cb.setCurrentIndex(0)
elif language.value == 'en':
self.cb.setCurrentIndex(1)
else:
self.cb.setCurrentIndex(2)

def onSelectionchange(self,i):
if self.cb.currentText() == 'Chinese':
value = 'zh-hant'
Expand All @@ -49,14 +56,29 @@ def onSelectionchange(self,i):
value = 'tibetan'

language = Setting.objects.get(key='language')
oldLanguage = language.value
newLanguage = value

# # 選擇語言後,依然顯示當前語言?
# languageN = language.value
# if languageN == 'zh-hant':
# self.cb.setCurrentIndex(0)
# elif languageN == 'en':
# self.cb.setCurrentIndex(1)
# else:
# self.cb.setCurrentIndex(2)

# 設定所選擇的語言
if language:
language.value=value
language.save()

msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setText(str(_("You can change the language until you activate the editor next time.")))
retval = msg.exec_()
# 需要更換語言時才顯示提醒
if oldLanguage != newLanguage:
msg = QMessageBox()
msg.setIcon(QMessageBox.Information)
msg.setText(str(_("You can change the language until you activate the editor next time.") + '\n' + f'language:{value}'))
retval = msg.exec_()

translation.activate(value)

Expand Down

0 comments on commit 4f5b2f4

Please sign in to comment.