allow language changing in prefs

avoided adding this in the past as on a multi user system it allows
one profile user to annoys others by changing the interface language,
but it comes at the expense of easily changing the language for users
who choose the wrong one on first startup
This commit is contained in:
Damien Elmes 2016-04-05 11:02:01 +10:00
parent e645ce5b65
commit 864a9135dc
3 changed files with 57 additions and 5 deletions

View File

@ -4,6 +4,7 @@
import datetime, time
from aqt.qt import *
import anki.lang
from aqt.utils import openFolder, showWarning, getText, openHelp, showInfo
import aqt
@ -22,6 +23,7 @@ class Preferences(QDialog):
self.form.buttonBox.button(QDialogButtonBox.Close).setAutoDefault(False)
self.connect(self.form.buttonBox, SIGNAL("helpRequested()"),
lambda: openHelp("profileprefs"))
self.setupLang()
self.setupCollection()
self.setupNetwork()
self.setupBackup()
@ -43,6 +45,28 @@ class Preferences(QDialog):
def reject(self):
self.accept()
# Language
######################################################################
def setupLang(self):
f = self.form
f.lang.addItems([x[0] for x in anki.lang.langs])
f.lang.setCurrentIndex(self.langIdx())
self.connect(f.lang, SIGNAL("currentIndexChanged(int)"),
self.onLangIdxChanged)
def langIdx(self):
codes = [x[1] for x in anki.lang.langs]
try:
return codes.index(anki.lang.getLang())
except:
return codes.index("en")
def onLangIdxChanged(self, idx):
code = anki.lang.langs[idx][1]
self.mw.pm.setLang(code)
showInfo(_("Please restart Anki to complete language change."), parent=self)
# Collection options
######################################################################

View File

@ -15,7 +15,7 @@ import re
from aqt.qt import *
from anki.db import DB
from anki.utils import isMac, isWin, intTime, checksum
from anki.lang import langs
import anki.lang
from aqt.utils import showWarning
from aqt import appHelpSite
import aqt.forms
@ -322,7 +322,7 @@ please see:
# find index
idx = None
en = None
for c, (name, code) in enumerate(langs):
for c, (name, code) in enumerate(anki.lang.langs):
if code == "en":
en = c
if code == lang:
@ -331,13 +331,13 @@ please see:
if idx is None:
idx = en
# update list
f.lang.addItems([x[0] for x in langs])
f.lang.addItems([x[0] for x in anki.lang.langs])
f.lang.setCurrentRow(idx)
d.exec_()
def _onLangSelected(self):
f = self.langForm
obj = langs[f.lang.currentRow()]
obj = anki.lang.langs[f.lang.currentRow()]
code = obj[1]
name = obj[0]
en = "Are you sure you wish to display Anki's interface in %s?"
@ -346,7 +346,11 @@ please see:
QMessageBox.No)
if r != QMessageBox.Yes:
return self._setDefaultLang()
self.setLang(code)
def setLang(self, code):
self.meta['defaultLang'] = code
sql = "update profiles set data = ? where name = ?"
self.db.execute(sql, cPickle.dumps(self.meta), "_global")
self.db.commit()
anki.lang.setLang(code, local=False)

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>405</width>
<height>450</height>
<height>455</height>
</rect>
</property>
<property name="windowTitle">
@ -30,6 +30,27 @@
<property name="spacing">
<number>12</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Interface language:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="lang">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="showEstimates">
<property name="text">
@ -413,6 +434,7 @@
</layout>
</widget>
<tabstops>
<tabstop>lang</tabstop>
<tabstop>showEstimates</tabstop>
<tabstop>showProgress</tabstop>
<tabstop>stripHTML</tabstop>
@ -429,6 +451,8 @@
<tabstop>numBackups</tabstop>
<tabstop>buttonBox</tabstop>
<tabstop>tabWidget</tabstop>
<tabstop>fullSync</tabstop>
<tabstop>compressBackups</tabstop>
</tabstops>
<resources/>
<connections>