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 import datetime, time
from aqt.qt import * from aqt.qt import *
import anki.lang
from aqt.utils import openFolder, showWarning, getText, openHelp, showInfo from aqt.utils import openFolder, showWarning, getText, openHelp, showInfo
import aqt import aqt
@ -22,6 +23,7 @@ class Preferences(QDialog):
self.form.buttonBox.button(QDialogButtonBox.Close).setAutoDefault(False) self.form.buttonBox.button(QDialogButtonBox.Close).setAutoDefault(False)
self.connect(self.form.buttonBox, SIGNAL("helpRequested()"), self.connect(self.form.buttonBox, SIGNAL("helpRequested()"),
lambda: openHelp("profileprefs")) lambda: openHelp("profileprefs"))
self.setupLang()
self.setupCollection() self.setupCollection()
self.setupNetwork() self.setupNetwork()
self.setupBackup() self.setupBackup()
@ -43,6 +45,28 @@ class Preferences(QDialog):
def reject(self): def reject(self):
self.accept() 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 # Collection options
###################################################################### ######################################################################

View file

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

View file

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>405</width> <width>405</width>
<height>450</height> <height>455</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -30,6 +30,27 @@
<property name="spacing"> <property name="spacing">
<number>12</number> <number>12</number>
</property> </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> <item>
<widget class="QCheckBox" name="showEstimates"> <widget class="QCheckBox" name="showEstimates">
<property name="text"> <property name="text">
@ -413,6 +434,7 @@
</layout> </layout>
</widget> </widget>
<tabstops> <tabstops>
<tabstop>lang</tabstop>
<tabstop>showEstimates</tabstop> <tabstop>showEstimates</tabstop>
<tabstop>showProgress</tabstop> <tabstop>showProgress</tabstop>
<tabstop>stripHTML</tabstop> <tabstop>stripHTML</tabstop>
@ -429,6 +451,8 @@
<tabstop>numBackups</tabstop> <tabstop>numBackups</tabstop>
<tabstop>buttonBox</tabstop> <tabstop>buttonBox</tabstop>
<tabstop>tabWidget</tabstop> <tabstop>tabWidget</tabstop>
<tabstop>fullSync</tabstop>
<tabstop>compressBackups</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections> <connections>