Factorize lang settings UI

Julien LepillerMon Dec 06 15:04:06+0100 2021

2b34134

Factorize lang settings UI

offlate/locales/offlate_en.ts

350350
<context>
351351
    <name>PageCopyright</name>
352352
    <message>
353-
        <location filename="../ui/welcome.py" line="99"/>
353+
        <location filename="../ui/welcome.py" line="98"/>
354354
        <source>Copyright Settings</source>
355355
        <translation type="unfinished"></translation>
356356
    </message>
357357
    <message>
358-
        <location filename="../ui/welcome.py" line="100"/>
358+
        <location filename="../ui/welcome.py" line="99"/>
359359
        <source>Configuring how your copyright is added to files</source>
360360
        <translation type="unfinished"></translation>
361361
    </message>
362-
    <message>
363-
        <location filename="../ui/welcome.py" line="103"/>
364-
        <source>In some cases, we need to add a copyright line for you in the translation files we send upstream. Here, you can configure how you want the copyright line to look like. This information will most likely become public after your first contribution.</source>
365-
        <translation type="unfinished"></translation>
366-
    </message>
367-
    <message>
368-
        <location filename="../ui/welcome.py" line="120"/>
369-
        <source>Here is how your copyright line will look like:</source>
370-
        <translation type="unfinished"></translation>
371-
    </message>
372-
    <message>
373-
        <location filename="../ui/welcome.py" line="149"/>
374-
        <source>Your Name</source>
375-
        <translation type="unfinished"></translation>
376-
    </message>
377-
    <message>
378-
        <location filename="../ui/welcome.py" line="151"/>
379-
        <source>your@email</source>
380-
        <translation type="unfinished"></translation>
381-
    </message>
382-
    <message>
383-
        <location filename="../ui/welcome.py" line="152"/>
384-
        <source>Copyright &amp;copy; {} {} &amp;lt;{}&amp;gt;</source>
385-
        <translation type="unfinished"></translation>
386-
    </message>
387362
</context>
388363
<context>
389364
    <name>PageDownload</name>
390365
    <message>
391-
        <location filename="../ui/welcome.py" line="261"/>
366+
        <location filename="../ui/welcome.py" line="187"/>
392367
        <source>Project Fetch</source>
393368
        <translation type="unfinished"></translation>
394369
    </message>
395370
    <message>
396-
        <location filename="../ui/welcome.py" line="262"/>
371+
        <location filename="../ui/welcome.py" line="188"/>
397372
        <source>Downloading translation files</source>
398373
        <translation type="unfinished"></translation>
399374
    </message>
400375
    <message>
401-
        <location filename="../ui/welcome.py" line="265"/>
376+
        <location filename="../ui/welcome.py" line="191"/>
402377
        <source>We are now attempting to fetch the translation files of your project. This step should be pretty fast.</source>
403378
        <translation type="unfinished"></translation>
404379
    </message>
405380
    <message>
406-
        <location filename="../ui/welcome.py" line="295"/>
381+
        <location filename="../ui/welcome.py" line="221"/>
407382
        <source>Finished!</source>
408383
        <translation type="unfinished"></translation>
409384
    </message>

411386
<context>
412387
    <name>PageHints</name>
413388
    <message>
414-
        <location filename="../ui/welcome.py" line="375"/>
389+
        <location filename="../ui/welcome.py" line="301"/>
415390
        <source>You can always go back to the initial screen (called the project manager) from the editor, by using &lt;i&gt;file &gt; project manager&lt;/i&gt;</source>
416391
        <translation type="unfinished"></translation>
417392
    </message>
418393
    <message>
419-
        <location filename="../ui/welcome.py" line="384"/>
394+
        <location filename="../ui/welcome.py" line="310"/>
420395
        <source>Quickly switch to the next string with &lt;i&gt;Ctrl+Enter&lt;/i&gt;. Use &lt;i&gt;Ctrl+Shift+Enter&lt;/i&gt; to go back to the previous string instead.</source>
421396
        <translation type="unfinished"></translation>
422397
    </message>
423398
    <message>
424-
        <location filename="../ui/welcome.py" line="393"/>
399+
        <location filename="../ui/welcome.py" line="319"/>
425400
        <source>With these hints, you are now ready to start working on your project! We will now open the project manager, from which you can add more projects, change your settings, etc. Have fun!</source>
426401
        <translation type="unfinished"></translation>
427402
    </message>

429404
<context>
430405
    <name>PageLang</name>
431406
    <message>
432-
        <location filename="../ui/welcome.py" line="163"/>
407+
        <location filename="../ui/welcome.py" line="117"/>
433408
        <source>Language Settings</source>
434409
        <translation type="unfinished"></translation>
435410
    </message>
436411
    <message>
437-
        <location filename="../ui/welcome.py" line="164"/>
412+
        <location filename="../ui/welcome.py" line="118"/>
438413
        <source>Configuring the default language for new projects</source>
439414
        <translation type="unfinished"></translation>
440415
    </message>
441-
    <message>
442-
        <location filename="../ui/welcome.py" line="167"/>
443-
        <source>Which language will you most frequently translate projects into? This setting can be changed later. It can also be overriden by individual projects.</source>
444-
        <translation type="unfinished"></translation>
445-
    </message>
446-
    <message>
447-
        <location filename="../ui/welcome.py" line="174"/>
448-
        <source>None</source>
449-
        <translation type="unfinished"></translation>
450-
    </message>
451-
    <message>
452-
        <location filename="../ui/welcome.py" line="186"/>
453-
        <source>Note that you should only translate into native language or to a language you are extremely familiar with, to avoid weird or nonsensical translations.</source>
454-
        <translation type="unfinished"></translation>
455-
    </message>
456416
</context>
457417
<context>
458418
    <name>PageProjectSelection</name>
459419
    <message>
460-
        <location filename="../ui/welcome.py" line="214"/>
420+
        <location filename="../ui/welcome.py" line="140"/>
461421
        <source>First Project</source>
462422
        <translation type="unfinished"></translation>
463423
    </message>
464424
    <message>
465-
        <location filename="../ui/welcome.py" line="215"/>
425+
        <location filename="../ui/welcome.py" line="141"/>
466426
        <source>Choosing a first project</source>
467427
        <translation type="unfinished"></translation>
468428
    </message>

470430
<context>
471431
    <name>PageSuccess</name>
472432
    <message>
473-
        <location filename="../ui/welcome.py" line="352"/>
433+
        <location filename="../ui/welcome.py" line="278"/>
474434
        <source>Congratulations! We&apos;ve just set up your first project! Initial setup is now complete, and you can always change the settings you&apos;ve set here from the Offlate welcome screen. After a few explanations you will be able to work on your project right away!</source>
475435
        <translation type="unfinished"></translation>
476436
    </message>

478438
<context>
479439
    <name>PageSystemSettings</name>
480440
    <message>
481-
        <location filename="../ui/welcome.py" line="237"/>
441+
        <location filename="../ui/welcome.py" line="163"/>
482442
        <source>System Configuration</source>
483443
        <translation type="unfinished"></translation>
484444
    </message>
485445
    <message>
486-
        <location filename="../ui/welcome.py" line="238"/>
446+
        <location filename="../ui/welcome.py" line="164"/>
487447
        <source>Getting an account on the project&apos;s platform</source>
488448
        <translation type="unfinished"></translation>
489449
    </message>

491451
<context>
492452
    <name>PageWelcome</name>
493453
    <message>
494-
        <location filename="../ui/welcome.py" line="82"/>
454+
        <location filename="../ui/welcome.py" line="81"/>
495455
        <source>Offlate is a tool to help you localise free and open source software. Before you start contributing translations to a project though, there are a few things we need to set up and talk about. Let&apos;s get started!</source>
496456
        <translation type="unfinished"></translation>
497457
    </message>

753713
<context>
754714
    <name>WelcomeWindow</name>
755715
    <message>
756-
        <location filename="../ui/welcome.py" line="63"/>
716+
        <location filename="../ui/welcome.py" line="62"/>
757717
        <source>Welcome to Offlate</source>
758718
        <translation type="unfinished"></translation>
759719
    </message>

offlate/locales/offlate_fr.ts

352352
<context>
353353
    <name>PageCopyright</name>
354354
    <message>
355-
        <location filename="../ui/welcome.py" line="99"/>
355+
        <location filename="../ui/welcome.py" line="98"/>
356356
        <source>Copyright Settings</source>
357357
        <translation type="unfinished"></translation>
358358
    </message>
359359
    <message>
360-
        <location filename="../ui/welcome.py" line="100"/>
360+
        <location filename="../ui/welcome.py" line="99"/>
361361
        <source>Configuring how your copyright is added to files</source>
362362
        <translation type="unfinished"></translation>
363363
    </message>
364-
    <message>
365-
        <location filename="../ui/welcome.py" line="103"/>
366-
        <source>In some cases, we need to add a copyright line for you in the translation files we send upstream. Here, you can configure how you want the copyright line to look like. This information will most likely become public after your first contribution.</source>
367-
        <translation type="unfinished"></translation>
368-
    </message>
369-
    <message>
370-
        <location filename="../ui/welcome.py" line="120"/>
371-
        <source>Here is how your copyright line will look like:</source>
372-
        <translation type="unfinished"></translation>
373-
    </message>
374-
    <message>
375-
        <location filename="../ui/welcome.py" line="149"/>
376-
        <source>Your Name</source>
377-
        <translation type="unfinished"></translation>
378-
    </message>
379-
    <message>
380-
        <location filename="../ui/welcome.py" line="151"/>
381-
        <source>your@email</source>
382-
        <translation type="unfinished"></translation>
383-
    </message>
384-
    <message>
385-
        <location filename="../ui/welcome.py" line="152"/>
386-
        <source>Copyright &amp;copy; {} {} &amp;lt;{}&amp;gt;</source>
387-
        <translation type="unfinished"></translation>
388-
    </message>
389364
</context>
390365
<context>
391366
    <name>PageDownload</name>
392367
    <message>
393-
        <location filename="../ui/welcome.py" line="261"/>
368+
        <location filename="../ui/welcome.py" line="187"/>
394369
        <source>Project Fetch</source>
395370
        <translation type="unfinished"></translation>
396371
    </message>
397372
    <message>
398-
        <location filename="../ui/welcome.py" line="262"/>
373+
        <location filename="../ui/welcome.py" line="188"/>
399374
        <source>Downloading translation files</source>
400375
        <translation type="unfinished"></translation>
401376
    </message>
402377
    <message>
403-
        <location filename="../ui/welcome.py" line="265"/>
378+
        <location filename="../ui/welcome.py" line="191"/>
404379
        <source>We are now attempting to fetch the translation files of your project. This step should be pretty fast.</source>
405380
        <translation type="unfinished"></translation>
406381
    </message>
407382
    <message>
408-
        <location filename="../ui/welcome.py" line="295"/>
383+
        <location filename="../ui/welcome.py" line="221"/>
409384
        <source>Finished!</source>
410385
        <translation type="unfinished"></translation>
411386
    </message>

413388
<context>
414389
    <name>PageHints</name>
415390
    <message>
416-
        <location filename="../ui/welcome.py" line="375"/>
391+
        <location filename="../ui/welcome.py" line="301"/>
417392
        <source>You can always go back to the initial screen (called the project manager) from the editor, by using &lt;i&gt;file &gt; project manager&lt;/i&gt;</source>
418393
        <translation type="unfinished"></translation>
419394
    </message>
420395
    <message>
421-
        <location filename="../ui/welcome.py" line="384"/>
396+
        <location filename="../ui/welcome.py" line="310"/>
422397
        <source>Quickly switch to the next string with &lt;i&gt;Ctrl+Enter&lt;/i&gt;. Use &lt;i&gt;Ctrl+Shift+Enter&lt;/i&gt; to go back to the previous string instead.</source>
423398
        <translation type="unfinished"></translation>
424399
    </message>
425400
    <message>
426-
        <location filename="../ui/welcome.py" line="393"/>
401+
        <location filename="../ui/welcome.py" line="319"/>
427402
        <source>With these hints, you are now ready to start working on your project! We will now open the project manager, from which you can add more projects, change your settings, etc. Have fun!</source>
428403
        <translation type="unfinished"></translation>
429404
    </message>

431406
<context>
432407
    <name>PageLang</name>
433408
    <message>
434-
        <location filename="../ui/welcome.py" line="163"/>
409+
        <location filename="../ui/welcome.py" line="117"/>
435410
        <source>Language Settings</source>
436411
        <translation type="unfinished"></translation>
437412
    </message>
438413
    <message>
439-
        <location filename="../ui/welcome.py" line="164"/>
414+
        <location filename="../ui/welcome.py" line="118"/>
440415
        <source>Configuring the default language for new projects</source>
441416
        <translation type="unfinished"></translation>
442417
    </message>
443-
    <message>
444-
        <location filename="../ui/welcome.py" line="167"/>
445-
        <source>Which language will you most frequently translate projects into? This setting can be changed later. It can also be overriden by individual projects.</source>
446-
        <translation type="unfinished"></translation>
447-
    </message>
448-
    <message>
449-
        <location filename="../ui/welcome.py" line="174"/>
450-
        <source>None</source>
451-
        <translation type="unfinished"></translation>
452-
    </message>
453-
    <message>
454-
        <location filename="../ui/welcome.py" line="186"/>
455-
        <source>Note that you should only translate into native language or to a language you are extremely familiar with, to avoid weird or nonsensical translations.</source>
456-
        <translation type="unfinished"></translation>
457-
    </message>
458418
</context>
459419
<context>
460420
    <name>PageProjectSelection</name>
461421
    <message>
462-
        <location filename="../ui/welcome.py" line="214"/>
422+
        <location filename="../ui/welcome.py" line="140"/>
463423
        <source>First Project</source>
464424
        <translation type="unfinished"></translation>
465425
    </message>
466426
    <message>
467-
        <location filename="../ui/welcome.py" line="215"/>
427+
        <location filename="../ui/welcome.py" line="141"/>
468428
        <source>Choosing a first project</source>
469429
        <translation type="unfinished"></translation>
470430
    </message>

472432
<context>
473433
    <name>PageSuccess</name>
474434
    <message>
475-
        <location filename="../ui/welcome.py" line="352"/>
435+
        <location filename="../ui/welcome.py" line="278"/>
476436
        <source>Congratulations! We&apos;ve just set up your first project! Initial setup is now complete, and you can always change the settings you&apos;ve set here from the Offlate welcome screen. After a few explanations you will be able to work on your project right away!</source>
477437
        <translation type="unfinished"></translation>
478438
    </message>

480440
<context>
481441
    <name>PageSystemSettings</name>
482442
    <message>
483-
        <location filename="../ui/welcome.py" line="237"/>
443+
        <location filename="../ui/welcome.py" line="163"/>
484444
        <source>System Configuration</source>
485445
        <translation type="unfinished"></translation>
486446
    </message>
487447
    <message>
488-
        <location filename="../ui/welcome.py" line="238"/>
448+
        <location filename="../ui/welcome.py" line="164"/>
489449
        <source>Getting an account on the project&apos;s platform</source>
490450
        <translation type="unfinished"></translation>
491451
    </message>

493453
<context>
494454
    <name>PageWelcome</name>
495455
    <message>
496-
        <location filename="../ui/welcome.py" line="82"/>
456+
        <location filename="../ui/welcome.py" line="81"/>
497457
        <source>Offlate is a tool to help you localise free and open source software. Before you start contributing translations to a project though, there are a few things we need to set up and talk about. Let&apos;s get started!</source>
498458
        <translation type="unfinished"></translation>
499459
    </message>

755715
<context>
756716
    <name>WelcomeWindow</name>
757717
    <message>
758-
        <location filename="../ui/welcome.py" line="63"/>
718+
        <location filename="../ui/welcome.py" line="62"/>
759719
        <source>Welcome to Offlate</source>
760720
        <translation type="unfinished"></translation>
761721
    </message>

offlate/ui/config/settings.py

2323
from PyQt5.QtGui import *
2424
from PyQt5.QtCore import *
2525
26+
from translate.lang.data import languages, tr_lang
27+
2628
from ...systems.list import systems
2729
from ...core.manager import ProjectManager
2830
from ...core.config import *

4345
4446
    def initUI(self):
4547
        center = QDesktopWidget().availableGeometry().center()
46-
        self.setGeometry(center.x()-200, center.y()-400, 400, 600)
48+
        self.setGeometry(center.x()-200, center.y()-400, 400, 800)
4749
        self.setWindowTitle(self.tr('Offlate Settings'))
4850
        self.welcomeWidget = SettingsWidget(self, self.manager)
4951
        self.setCentralWidget(self.welcomeWidget)
5052
53+
    def show(self):
54+
        self.welcomeWidget.show()
55+
        super().show()
56+
5157
class SystemSettingsWidget(QWidget):
5258
    def __init__(self, manager, system = -1, parent=None):
5359
        super().__init__(parent)

146152
        self.nameWidget.setPlaceholderText(self.tr("John Doe"))
147153
        self.emailWidget = QLineEdit()
148154
        self.emailWidget.setText(self.email)
149-
        self.nameWidget.setPlaceholderText(self.tr("john@doe.me"))
155+
        self.emailWidget.setPlaceholderText(self.tr("john@doe.me"))
150156
        form.addRow(QLabel("Name:"), self.nameWidget)
151157
        form.addRow(QLabel("Email:"), self.emailWidget)
152158
        layout.addLayout(form)

186192
        self.previewLine.setText(self.tr("Copyright &copy; {} {} &lt;{}&gt;").format(year,
187193
            name if name != "" else nameHolder, email if email != "" else emailHolder))
188194
195+
class LangSettingsWidget(QWidget):
196+
    changed = pyqtSignal(str)
197+
198+
    def __init__(self, lang="", parent=None):
199+
        super().__init__(parent)
200+
        self.lang = lang
201+
        self.initUI()
202+
203+
    def initUI(self):
204+
        layout = QVBoxLayout()
205+
206+
        explainText = QLabel(self)
207+
        explainText.setText(self.tr("Which language will you most frequently \
208+
translate projects into? This setting can be overriden in each individual \
209+
projects."))
210+
        explainText.setWordWrap(True)
211+
        layout.addWidget(explainText)
212+
213+
        self.languageCombo = QComboBox()
214+
        self.languageCombo.addItem(self.tr("None"), userData="")
215+
        i = 1
216+
        langIndex = 0
217+
        for lang in languages:
218+
            langtag = lang
219+
            lang = languages[lang]
220+
            langname = lang[0]
221+
            self.languageCombo.addItem(tr_lang()(langname), userData=langtag)
222+
            if langtag == self.lang:
223+
                langIndex = i
224+
            i += 1
225+
        self.languageCombo.setCurrentIndex(langIndex)
226+
        self.languageCombo.currentIndexChanged.connect(self.comboChanged)
227+
        layout.addWidget(self.languageCombo)
228+
229+
        layout.addSpacing(15)
230+
231+
        warnText = QLabel(self)
232+
        warnText.setText(self.tr("Note that you should only translate into \
233+
native language or to a language you are extremely familiar with, to avoid \
234+
weird or nonsensical translations."))
235+
        warnText.setWordWrap(True)
236+
        layout.addWidget(warnText)
237+
238+
        # TODO: Add information about the selected language, to redirect users
239+
        # to translation teams, resources, etc
240+
241+
        # TODO: Allow users to select an unlisted language, by providing
242+
        # language codes.
243+
244+
        self.setLayout(layout)
245+
246+
    def comboChanged(self, index):
247+
        self.changed.emit(self.languageCombo.itemData(index))
248+
249+
    def getLang(self):
250+
        return self.languageCombo.itemData(self.languageCombo.currentIndex())
251+
189252
class SettingsWidget(QWidget):
190253
    def __init__(self, parent=None, manager=None):
191254
        super().__init__(parent)
192255
        self.parent = parent
193256
        self.manager = manager
257+
258+
    def show(self):
194259
        self.initUI()
260+
        super().show()
195261
196262
    def initUI(self):
197263
        vbox = QVBoxLayout()

200266
                self.manager.getConf(['Generic', 'email']))
201267
        vbox.addWidget(self.copyright)
202268
269+
        self.lang = LangSettingsWidget(self.manager.getConf(['Generic', 'lang']))
270+
        vbox.addWidget(self.lang)
271+
203272
        systemsbox = QGridLayout()
204273
        x = 0
205274
        y = 0

249318
    def done(self):
250319
        name = self.copyright.nameWidget.text()
251320
        email = self.copyright.emailWidget.text()
321+
        lang = self.lang.getLang()
252322
        if name == None or name == "":
253323
            return
254324
        if email == None or email == "":
255325
            return
256326
257-
        self.manager.updateSettings({'Generic': {'name': name, 'email': email, 'new': 'False'}})
327+
        self.manager.updateSettings({'Generic': {'name': name, 'email': email,
328+
            'lang': lang, 'new': 'False'}})
258329
        self.quit()
259330
260331
    def quit(self):

offlate/ui/welcome.py

2121
import sys
2222
import os
2323
24-
from translate.lang.data import languages, tr_lang
2524
from .new import PredefinedProjectWidget, AdvancedProjectWidget
2625
from .manager import NewRunnable
27-
from .config.settings import SystemSettingsWidget
26+
from .config.settings import SystemSettingsWidget, CopyrightSettingsWidget, \
27+
    LangSettingsWidget
2828
2929
WelcomePage = 1
3030
CopyrightPage = 2

117117
        self.setTitle(self.tr("Language Settings"))
118118
        self.setSubTitle(self.tr("Configuring the default language for new projects"))
119119
120-
        explainText = QLabel(self)
121-
        explainText.setText(self.tr("Which language will you most frequently \
122-
translate projects into? This setting can be changed later. It can also be \
123-
overriden by individual projects."))
124-
        explainText.setWordWrap(True)
125-
        layout.addWidget(explainText)
126-
127-
        self.languageCombo = QComboBox()
128-
        self.languageCombo.addItem(self.tr("None"), userData="")
129-
        for lang in languages:
130-
            langtag = lang
131-
            lang = languages[lang]
132-
            langname = lang[0]
133-
            self.languageCombo.addItem(tr_lang()(langname), userData=langtag)
134-
        self.languageCombo.currentIndexChanged.connect(self.comboChanged)
135-
        layout.addWidget(self.languageCombo)
136-
137-
        layout.addSpacing(15)
138-
139-
        warnText = QLabel(self)
140-
        warnText.setText(self.tr("Note that you should only translate into \
141-
native language or to a language you are extremely familiar with, to avoid \
142-
weird or nonsensical translations."))
143-
        warnText.setWordWrap(True)
144-
        layout.addWidget(warnText)
145-
146-
        # TODO: Add information about the selected language, to redirect users
147-
        # to translation teams, resources, etc
148-
149-
        # TODO: Allow users to select an unlisted language, by providing
150-
        # language codes.
120+
        self.lang = LangSettingsWidget()
121+
        layout.addWidget(self.lang)
122+
        self.lang.changed.connect(self.langChanged)
151123
152124
        self.setLayout(layout)
153125
154126
        self.langEdit = QLineEdit()
155127
        self.registerField("lang*", self.langEdit)
156128
157-
    def comboChanged(self, index):
158-
        self.langEdit.setText(self.languageCombo.itemData(index))
129+
    def langChanged(self, lang):
130+
        self.langEdit.setText(lang)
159131
160132
class PageProjectSelection(QWizardPage):
161133
    def __init__(self, parent):