Wed, 21 Sep 2022 16:30:15 +0200
Reformatted source code with 'Black'.
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
66
0d3168d0e310
Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
64
diff
changeset
|
3 | # Copyright (c) 2020 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing the project support for flask-babel. |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
10 | import os |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | import re |
61
fe1e8783a95f
- implemented some code simplifications
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
60
diff
changeset
|
12 | import contextlib |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
14 | from PyQt6.QtCore import pyqtSlot, QObject, QProcess |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
15 | from PyQt6.QtWidgets import QDialog, QMenu |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
17 | from EricWidgets import EricMessageBox |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
18 | from EricWidgets.EricApplication import ericApp |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
19 | from EricGui.EricAction import EricAction |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | from .PyBabelCommandDialog import PyBabelCommandDialog |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | import Utilities |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | class PyBabelProject(QObject): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | """ |
29
a8817ea36587
Started implementing support for the 'flask-migrate' extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
27
diff
changeset
|
28 | Class implementing the flask-babel project support. |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | """ |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
30 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | def __init__(self, plugin, project, parent=None): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | Constructor |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
34 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | @param plugin reference to the plugin object |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | @type ProjectFlaskPlugin |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | @param project reference to the project object |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | @type Project |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | @param parent parent |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | @type QObject |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | """ |
61
fe1e8783a95f
- implemented some code simplifications
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
60
diff
changeset
|
42 | super().__init__(parent) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
43 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | self.__plugin = plugin |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | self.__project = project |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
46 | |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
47 | self.__ericProject = ericApp().getObject("Project") |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
48 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | self.__hooksInstalled = False |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
50 | |
26
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
51 | def initActions(self): |
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
52 | """ |
29
a8817ea36587
Started implementing support for the 'flask-migrate' extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
27
diff
changeset
|
53 | Public method to define the flask-babel actions. |
26
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
54 | """ |
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
55 | self.actions = [] |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
56 | |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
57 | self.pybabelConfigAct = EricAction( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
58 | self.tr("Configure flask-babel"), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
59 | self.tr("&Configure flask-babel"), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
60 | 0, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
61 | 0, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
62 | self, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
63 | "flask_config_pybabel", |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
64 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
65 | self.pybabelConfigAct.setStatusTip( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
66 | self.tr("Shows a dialog to edit the configuration for flask-babel") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
67 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
68 | self.pybabelConfigAct.setWhatsThis( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
69 | self.tr( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
70 | """<b>Configure flask-babel</b>""" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
71 | """<p>Shows a dialog to edit the configuration for """ |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
72 | """flask-babel.</p>""" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
73 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
74 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
75 | self.pybabelConfigAct.triggered.connect(self.__configurePyBabel) |
26
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
76 | self.actions.append(self.pybabelConfigAct) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
77 | |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
78 | self.pybabelInstallAct = EricAction( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
79 | self.tr("Install flask-babel"), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
80 | self.tr("&Install flask-babel"), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
81 | 0, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
82 | 0, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
83 | self, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
84 | "flask_install_pybabel", |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
85 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
86 | self.pybabelInstallAct.setStatusTip( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
87 | self.tr( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
88 | "Installs the flask-babel extension into the configured" " environment" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
89 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
90 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
91 | self.pybabelInstallAct.setWhatsThis( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
92 | self.tr( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
93 | """<b>Install flask-babel</b>""" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
94 | """<p>Installs the flask-babel extension into the configured""" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
95 | """ environment using the pip interface.</p>""" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
96 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
97 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
98 | self.pybabelInstallAct.triggered.connect(self.__installFlaskBabel) |
27
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
99 | self.actions.append(self.pybabelInstallAct) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
100 | |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
101 | self.pybabelAvailabilityAct = EricAction( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
102 | self.tr("Check flask-babel Availability"), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
103 | self.tr("Check flask-babel &Availability"), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
104 | 0, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
105 | 0, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
106 | self, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
107 | "flask_check_pybabel", |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
108 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
109 | self.pybabelAvailabilityAct.setStatusTip( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
110 | self.tr("Check the availability of the flask-babel extension") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
111 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
112 | self.pybabelAvailabilityAct.setWhatsThis( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
113 | self.tr( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
114 | """<b>Check flask-babel Availability</b>""" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
115 | """<p>Check the availability of the flask-babel extension.</p>""" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
116 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
117 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
118 | self.pybabelAvailabilityAct.triggered.connect(self.__checkAvailability) |
27
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
119 | self.actions.append(self.pybabelAvailabilityAct) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
120 | |
26
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
121 | def initMenu(self): |
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
122 | """ |
29
a8817ea36587
Started implementing support for the 'flask-migrate' extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
27
diff
changeset
|
123 | Public method to initialize the flask-babel menu. |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
124 | |
26
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
125 | @return the menu generated |
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
126 | @rtype QMenu |
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
127 | """ |
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
128 | menu = QMenu(self.tr("Translations")) |
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
129 | menu.setTearOffEnabled(True) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
130 | |
26
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
131 | menu.addAction(self.pybabelConfigAct) |
27
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
132 | menu.addSeparator() |
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
133 | menu.addAction(self.pybabelAvailabilityAct) |
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
134 | menu.addAction(self.pybabelInstallAct) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
135 | |
26
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
136 | return menu |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
137 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | def registerOpenHook(self): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | Public method to register the open hook to open a translations file |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
141 | in a translations editor. |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | if self.__hooksInstalled: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
144 | editor = self.__plugin.getPreferences("TranslationsEditor") |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
145 | if editor: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
146 | self.__translationsBrowser.addHookMethodAndMenuEntry( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
147 | "open", |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
148 | self.openPOEditor, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
149 | self.tr("Open with {0}").format(os.path.basename(editor)), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
150 | ) |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
151 | else: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
152 | self.__translationsBrowser.removeHookMethod("open") |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
153 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
154 | def projectOpenedHooks(self): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
155 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
156 | Public method to add our hook methods. |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | """ |
46
e700f73e1c6f
Fine tuned some internal data structures.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
38
diff
changeset
|
158 | if self.__project.hasCapability("flask-babel"): |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
159 | self.__ericProject.projectLanguageAddedByCode.connect( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
160 | self.__projectLanguageAdded |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
161 | ) |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
162 | self.__translationsBrowser = ( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
163 | ericApp().getObject("ProjectBrowser").getProjectBrowser("translations") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
164 | ) |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
165 | self.__translationsBrowser.addHookMethodAndMenuEntry( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
166 | "extractMessages", self.extractMessages, self.tr("Extract Messages") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
167 | ) |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
168 | self.__translationsBrowser.addHookMethodAndMenuEntry( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
169 | "releaseAll", self.compileCatalogs, self.tr("Compile All Catalogs") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
170 | ) |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
171 | self.__translationsBrowser.addHookMethodAndMenuEntry( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
172 | "releaseSelected", |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
173 | self.compileSelectedCatalogs, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
174 | self.tr("Compile Selected Catalogs"), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
175 | ) |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | self.__translationsBrowser.addHookMethodAndMenuEntry( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
177 | "generateAll", self.updateCatalogs, self.tr("Update All Catalogs") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
178 | ) |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
179 | self.__translationsBrowser.addHookMethodAndMenuEntry( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
180 | "generateAllWithObsolete", |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
181 | self.updateCatalogsObsolete, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
182 | self.tr("Update All Catalogs (with obsolete)"), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
183 | ) |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
184 | self.__translationsBrowser.addHookMethodAndMenuEntry( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
185 | "generateSelected", |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
186 | self.updateSelectedCatalogs, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
187 | self.tr("Update Selected Catalogs"), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
188 | ) |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
189 | self.__translationsBrowser.addHookMethodAndMenuEntry( |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
190 | "generateSelectedWithObsolete", |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
191 | self.updateSelectedCatalogsObsolete, |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
192 | self.tr("Update Selected Catalogs (with obsolete)"), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
193 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
194 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
195 | self.__hooksInstalled = True |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
196 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
197 | self.registerOpenHook() |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
198 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
199 | def projectClosedHooks(self): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
200 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
201 | Public method to remove our hook methods. |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
202 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
203 | if self.__hooksInstalled: |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
204 | self.__ericProject.projectLanguageAddedByCode.disconnect( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
205 | self.__projectLanguageAdded |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
206 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
207 | self.__translationsBrowser.removeHookMethod("extractMessages") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
208 | self.__translationsBrowser.removeHookMethod("releaseAll") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
209 | self.__translationsBrowser.removeHookMethod("releaseSelected") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
210 | self.__translationsBrowser.removeHookMethod("generateAll") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
211 | self.__translationsBrowser.removeHookMethod("generateAllWithObsolete") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
212 | self.__translationsBrowser.removeHookMethod("generateSelected") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
213 | self.__translationsBrowser.removeHookMethod("generateSelectedWithObsolete") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
214 | self.__translationsBrowser.removeHookMethod("open") |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
215 | self.__translationsBrowser = None |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
216 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
217 | self.__hooksInstalled = False |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
218 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
219 | def determineCapability(self): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
220 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
221 | Public method to determine the availability of flask-babel. |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
222 | """ |
61
fe1e8783a95f
- implemented some code simplifications
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
60
diff
changeset
|
223 | available = ( |
fe1e8783a95f
- implemented some code simplifications
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
60
diff
changeset
|
224 | self.__project.getData("flask", "flask_babel_available") |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
225 | if self.__project.getData("flask", "flask_babel_override") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
226 | else self.__flaskBabelAvailable() |
61
fe1e8783a95f
- implemented some code simplifications
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
60
diff
changeset
|
227 | ) |
46
e700f73e1c6f
Fine tuned some internal data structures.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
38
diff
changeset
|
228 | self.__project.setCapability("flask-babel", available) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
229 | |
26
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
230 | self.pybabelConfigAct.setEnabled(available) |
27
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
231 | self.pybabelInstallAct.setEnabled(not available) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
232 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
233 | ################################################################## |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
234 | ## slots and methods below implement general functionality |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
235 | ################################################################## |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
236 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
237 | def getBabelCommand(self): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
238 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
239 | Public method to build the Babel command. |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
240 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
241 | @return full pybabel command |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
242 | @rtype str |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
243 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
244 | return self.__project.getFullCommand("pybabel") |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
245 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
246 | ################################################################## |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
247 | ## slots and methods below implement i18n and l10n support |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
248 | ################################################################## |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
249 | |
29
a8817ea36587
Started implementing support for the 'flask-migrate' extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
27
diff
changeset
|
250 | def __flaskBabelAvailable(self): |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
251 | """ |
29
a8817ea36587
Started implementing support for the 'flask-migrate' extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
27
diff
changeset
|
252 | Private method to check, if the 'flask-babel' package is available. |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
253 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
254 | @return flag indicating the availability of 'flask-babel' |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
255 | @rtype bool |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
256 | """ |
30
76c86fe13f36
Moved all code dealing with virtual environments to the main Project class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
29
diff
changeset
|
257 | interpreter = self.__project.getVirtualenvInterpreter() |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
258 | if interpreter and Utilities.isinpath(interpreter): |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
259 | detector = os.path.join(os.path.dirname(__file__), "FlaskBabelDetector.py") |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
260 | proc = QProcess() |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
261 | proc.setProcessChannelMode(QProcess.ProcessChannelMode.MergedChannels) |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
262 | proc.start(interpreter, [detector]) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
263 | finished = proc.waitForFinished(30000) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
264 | if finished and proc.exitCode() == 0: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
265 | return True |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
266 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
267 | return False |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
268 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
269 | @pyqtSlot() |
26
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
270 | def __configurePyBabel(self): |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
271 | """ |
26
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
272 | Private slot to show a dialog to edit the pybabel configuration. |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
273 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
274 | from .PyBabelConfigDialog import PyBabelConfigDialog |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
275 | |
46
e700f73e1c6f
Fine tuned some internal data structures.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
38
diff
changeset
|
276 | config = self.__project.getData("flask-babel", "") |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
277 | dlg = PyBabelConfigDialog(config) |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
278 | if dlg.exec() == QDialog.DialogCode.Accepted: |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
279 | config = dlg.getConfiguration() |
46
e700f73e1c6f
Fine tuned some internal data structures.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
38
diff
changeset
|
280 | self.__project.setData("flask-babel", "", config) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
281 | |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
282 | self.__ericProject.setTranslationPattern( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
283 | os.path.join( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
284 | config["translationsDirectory"], |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
285 | "%language%", |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
286 | "LC_MESSAGES", |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
287 | "{0}.po".format(config["domain"]), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
288 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
289 | ) |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
290 | self.__ericProject.setDirty(True) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
291 | |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
292 | cfgFileName = self.__ericProject.getAbsoluteUniversalPath( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
293 | config["configFile"] |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
294 | ) |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
295 | if not os.path.exists(cfgFileName): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
296 | self.__createBabelCfg(cfgFileName) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
297 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
298 | def __ensurePybabelConfigured(self): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
299 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
300 | Private method to ensure, that PyBabel has been configured. |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
301 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
302 | @return flag indicating successful configuration |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
303 | @rtype bool |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
304 | """ |
46
e700f73e1c6f
Fine tuned some internal data structures.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
38
diff
changeset
|
305 | config = self.__project.getData("flask-babel", "") |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
306 | if not config: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
307 | self.__configurePybabel() |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
308 | return True |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
309 | |
46
e700f73e1c6f
Fine tuned some internal data structures.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
38
diff
changeset
|
310 | configFileName = self.__project.getData("flask-babel", "configFile") |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
311 | if configFileName: |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
312 | cfgFileName = self.__ericProject.getAbsoluteUniversalPath(configFileName) |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
313 | if os.path.exists(cfgFileName): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
314 | return True |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
315 | else: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
316 | return self.__createBabelCfg(cfgFileName) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
317 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
318 | return False |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
319 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
320 | def __createBabelCfg(self, configFile): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
321 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
322 | Private method to create a template pybabel configuration file. |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
323 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
324 | @param configFile name of the configuration file to be created |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
325 | @type str |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
326 | @return flag indicating successful configuration file creation |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
327 | @rtype bool |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
328 | """ |
26
5aac667c4f0f
Moved the pybabel config action and menu into a 'Translations' menu of the flask-babel extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
329 | _, app = self.__project.getApplication() |
61
fe1e8783a95f
- implemented some code simplifications
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
60
diff
changeset
|
330 | template = ( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
331 | ( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
332 | "[python: {0}]\n" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
333 | "[jinja2: templates/**.html]\n" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
334 | "extensions=jinja2.ext.autoescape,jinja2.ext.with_\n" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
335 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
336 | if app.endswith(".py") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
337 | else ( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
338 | "[python: {0}/**.py]\n" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
339 | "[jinja2: {0}/templates/**.html]\n" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
340 | "extensions=jinja2.ext.autoescape,jinja2.ext.with_\n" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
341 | ) |
61
fe1e8783a95f
- implemented some code simplifications
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
60
diff
changeset
|
342 | ) |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
343 | try: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
344 | with open(configFile, "w") as f: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
345 | f.write(template.format(app)) |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
346 | self.__ericProject.appendFile(configFile) |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
347 | EricMessageBox.information( |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
348 | None, |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
349 | self.tr("Generate PyBabel Configuration File"), |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
350 | self.tr( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
351 | """The PyBabel configuration file was created.""" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
352 | """ Please edit it to adjust the entries as""" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
353 | """ required.""" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
354 | ), |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
355 | ) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
356 | return True |
18
d76a0939be6a
Added code ot create template web pages of selectable kinds.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
17
diff
changeset
|
357 | except OSError as err: |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
358 | EricMessageBox.warning( |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
359 | None, |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
360 | self.tr("Generate PyBabel Configuration File"), |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
361 | self.tr( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
362 | """<p>The PyBabel Configuration File could not be""" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
363 | """ generated.</p><p>Reason: {0}</p>""" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
364 | ).format(str(err)), |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
365 | ) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
366 | return False |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
367 | |
27
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
368 | @pyqtSlot() |
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
369 | def __installFlaskBabel(self): |
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
370 | """ |
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
371 | Private slot to install the flask-babel extension into the configured |
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
372 | environment. |
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
373 | """ |
48
14d8d24e24da
PyBabelProjectExtension, MigrateProjectExtension: moved determination of the virtual environment to the man project support.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
47
diff
changeset
|
374 | venvName = self.__project.getVirtualEnvironment() |
27
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
375 | if venvName: |
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
376 | interpreter = self.__project.getFullCommand("python") |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
377 | pip = ericApp().getObject("Pip") |
27
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
378 | pip.installPackages(["flask-babel"], interpreter=interpreter) |
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
379 | self.determineCapability() |
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
380 | else: |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
381 | EricMessageBox.critical( |
27
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
382 | None, |
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
383 | self.tr("Install flask-babel"), |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
384 | self.tr( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
385 | "The 'flask-babel' extension could not be installed" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
386 | " because no virtual environment has been" |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
387 | " configured." |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
388 | ), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
389 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
390 | |
27
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
391 | @pyqtSlot() |
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
392 | def __checkAvailability(self): |
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
393 | """ |
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
394 | Private slot to check the availability of the 'flask-babel' extension. |
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
395 | """ |
b73e9af0d496
Added actions to check the availability of the flask-babel extension and to install it.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
26
diff
changeset
|
396 | self.determineCapability() |
61
fe1e8783a95f
- implemented some code simplifications
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
60
diff
changeset
|
397 | msg = ( |
fe1e8783a95f
- implemented some code simplifications
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
60
diff
changeset
|
398 | self.tr("The 'flask-babel' extension is installed.") |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
399 | if self.__project.hasCapability("flask-babel") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
400 | else self.tr("The 'flask-babel' extension is not installed.") |
61
fe1e8783a95f
- implemented some code simplifications
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
60
diff
changeset
|
401 | ) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
402 | EricMessageBox.information(None, self.tr("flask-babel Availability"), msg) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
403 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
404 | def __getLocale(self, filename): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
405 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
406 | Private method to extract the locale out of a file name. |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
407 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
408 | @param filename name of the file used for extraction |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
409 | @type str |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
410 | @return extracted locale |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
411 | @rtype str or None |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
412 | """ |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
413 | if self.__ericProject.getTranslationPattern(): |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
414 | filename = os.path.splitext(filename)[0] + ".po" |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
415 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
416 | # On Windows, path typically contains backslashes. This leads |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
417 | # to an invalid search pattern '...\(' because the opening bracket |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
418 | # will be escaped. |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
419 | pattern = self.__ericProject.getTranslationPattern() |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
420 | pattern = os.path.normpath(pattern) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
421 | pattern = pattern.replace("%language%", "(.*?)") |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
422 | pattern = pattern.replace("\\", "\\\\") |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
423 | match = re.search(pattern, filename) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
424 | if match is not None: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
425 | return match.group(1) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
426 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
427 | return None |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
428 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
429 | def openPOEditor(self, poFile): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
430 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
431 | Public method to edit the given file in an external .po editor. |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
432 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
433 | @param poFile name of the .po file |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
434 | @type str |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
435 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
436 | editor = self.__plugin.getPreferences("TranslationsEditor") |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
437 | if poFile.endswith(".po") and editor: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
438 | workdir = self.__project.getApplication()[0] |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
439 | started, pid = QProcess.startDetached(editor, [poFile], workdir) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
440 | if not started: |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
441 | EricMessageBox.critical( |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
442 | None, |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
443 | self.tr("Process Generation Error"), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
444 | self.tr( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
445 | "The translations editor process ({0}) could" " not be started." |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
446 | ).format(os.path.basename(editor)), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
447 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
448 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
449 | def extractMessages(self): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
450 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
451 | Public method to extract the messages catalog template file. |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
452 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
453 | title = self.tr("Extract messages") |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
454 | if self.__ensurePybabelConfigured(): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
455 | workdir = self.__project.getApplication()[0] |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
456 | potFile = self.__ericProject.getAbsoluteUniversalPath( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
457 | self.__project.getData("flask-babel", "catalogFile") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
458 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
459 | |
61
fe1e8783a95f
- implemented some code simplifications
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
60
diff
changeset
|
460 | with contextlib.suppress(OSError): |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
461 | potFilePath = os.path.dirname(potFile) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
462 | os.makedirs(potFilePath) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
463 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
464 | args = [ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
465 | "-F", |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
466 | os.path.relpath( |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
467 | self.__ericProject.getAbsoluteUniversalPath( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
468 | self.__project.getData("flask-babel", "configFile") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
469 | ), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
470 | workdir, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
471 | ), |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
472 | ] |
46
e700f73e1c6f
Fine tuned some internal data structures.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
38
diff
changeset
|
473 | if self.__project.getData("flask-babel", "markersList"): |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
474 | for marker in self.__project.getData("flask-babel", "markersList"): |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
475 | args += ["-k", marker] |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
476 | args += ["-o", os.path.relpath(potFile, workdir), "."] |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
477 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
478 | dlg = PyBabelCommandDialog( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
479 | self, title, msgSuccess=self.tr("\nMessages extracted successfully.") |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
480 | ) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
481 | res = dlg.startCommand("extract", args, workdir) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
482 | if res: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
483 | dlg.exec() |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
484 | self.__ericProject.appendFile(potFile) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
485 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
486 | def __projectLanguageAdded(self, code): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
487 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
488 | Private slot handling the addition of a new language. |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
489 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
490 | @param code language code of the new language |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
491 | @type str |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
492 | """ |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
493 | title = self.tr("Initializing message catalog for '{0}'").format(code) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
494 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
495 | if self.__ensurePybabelConfigured(): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
496 | workdir = self.__project.getApplication()[0] |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
497 | langFile = self.__ericProject.getAbsoluteUniversalPath( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
498 | self.__ericProject.getTranslationPattern().replace("%language%", code) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
499 | ) |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
500 | potFile = self.__ericProject.getAbsoluteUniversalPath( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
501 | self.__project.getData("flask-babel", "catalogFile") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
502 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
503 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
504 | args = [ |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
505 | "--domain={0}".format(self.__project.getData("flask-babel", "domain")), |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
506 | "--input-file={0}".format(os.path.relpath(potFile, workdir)), |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
507 | "--output-file={0}".format(os.path.relpath(langFile, workdir)), |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
508 | "--locale={0}".format(code), |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
509 | ] |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
510 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
511 | dlg = PyBabelCommandDialog( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
512 | self, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
513 | title, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
514 | msgSuccess=self.tr("\nMessage catalog initialized successfully."), |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
515 | ) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
516 | res = dlg.startCommand("init", args, workdir) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
517 | if res: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
518 | dlg.exec() |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
519 | |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
520 | self.__ericProject.appendFile(langFile) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
521 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
522 | def compileCatalogs(self, filenames): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
523 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
524 | Public method to compile the message catalogs. |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
525 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
526 | @param filenames list of filenames (not used) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
527 | @type list of str |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
528 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
529 | title = self.tr("Compiling message catalogs") |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
530 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
531 | if self.__ensurePybabelConfigured(): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
532 | workdir = self.__project.getApplication()[0] |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
533 | translationsDirectory = self.__ericProject.getAbsoluteUniversalPath( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
534 | self.__project.getData("flask-babel", "translationsDirectory") |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
535 | ) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
536 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
537 | args = [ |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
538 | "--domain={0}".format(self.__project.getData("flask-babel", "domain")), |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
539 | "--directory={0}".format( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
540 | os.path.relpath(translationsDirectory, workdir) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
541 | ), |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
542 | "--use-fuzzy", |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
543 | "--statistics", |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
544 | ] |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
545 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
546 | dlg = PyBabelCommandDialog( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
547 | self, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
548 | title, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
549 | msgSuccess=self.tr("\nMessage catalogs compiled successfully."), |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
550 | ) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
551 | res = dlg.startCommand("compile", args, workdir) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
552 | if res: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
553 | dlg.exec() |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
554 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
555 | for entry in os.walk(translationsDirectory): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
556 | for fileName in entry[2]: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
557 | fullName = os.path.join(entry[0], fileName) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
558 | if fullName.endswith(".mo"): |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
559 | self.__ericProject.appendFile(fullName) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
560 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
561 | def compileSelectedCatalogs(self, filenames): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
562 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
563 | Public method to update the message catalogs. |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
564 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
565 | @param filenames list of file names |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
566 | @type list of str |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
567 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
568 | title = self.tr("Compiling message catalogs") |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
569 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
570 | locales = {self.__getLocale(f) for f in filenames} |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
571 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
572 | if len(locales) == 0: |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
573 | EricMessageBox.warning( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
574 | self.__ui, title, self.tr("No locales detected. Aborting...") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
575 | ) |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
576 | return |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
577 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
578 | if self.__ensurePybabelConfigured(): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
579 | workdir = self.__project.getApplication()[0] |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
580 | translationsDirectory = self.__ericProject.getAbsoluteUniversalPath( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
581 | self.__project.getData("flask-babel", "translationsDirectory") |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
582 | ) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
583 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
584 | argsList = [] |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
585 | for loc in locales: |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
586 | argsList.append( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
587 | [ |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
588 | "compile", |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
589 | "--domain={0}".format( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
590 | self.__project.getData("flask-babel", "domain") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
591 | ), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
592 | "--directory={0}".format( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
593 | os.path.relpath(translationsDirectory, workdir) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
594 | ), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
595 | "--use-fuzzy", |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
596 | "--statistics", |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
597 | "--locale={0}".format(loc), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
598 | ] |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
599 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
600 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
601 | dlg = PyBabelCommandDialog( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
602 | self, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
603 | title=title, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
604 | msgSuccess=self.tr("\nMessage catalogs compiled successfully."), |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
605 | ) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
606 | res = dlg.startBatchCommand(argsList, workdir) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
607 | if res: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
608 | dlg.exec() |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
609 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
610 | for entry in os.walk(translationsDirectory): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
611 | for fileName in entry[2]: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
612 | fullName = os.path.join(entry[0], fileName) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
613 | if fullName.endswith(".mo"): |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
614 | self.__ericProject.appendFile(fullName) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
615 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
616 | def updateCatalogs(self, filenames, withObsolete=False): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
617 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
618 | Public method to update the message catalogs. |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
619 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
620 | @param filenames list of filenames (not used) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
621 | @type list of str |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
622 | @param withObsolete flag indicating to keep obsolete translations |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
623 | @type bool |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
624 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
625 | title = self.tr("Updating message catalogs") |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
626 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
627 | if self.__ensurePybabelConfigured(): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
628 | workdir = self.__project.getApplication()[0] |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
629 | translationsDirectory = self.__ericProject.getAbsoluteUniversalPath( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
630 | self.__project.getData("flask-babel", "translationsDirectory") |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
631 | ) |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
632 | potFile = self.__ericProject.getAbsoluteUniversalPath( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
633 | self.__project.getData("flask-babel", "catalogFile") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
634 | ) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
635 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
636 | args = [ |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
637 | "--domain={0}".format(self.__project.getData("flask-babel", "domain")), |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
638 | "--input-file={0}".format(os.path.relpath(potFile, workdir)), |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
639 | "--output-dir={0}".format( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
640 | os.path.relpath(translationsDirectory, workdir) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
641 | ), |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
642 | ] |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
643 | if not withObsolete: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
644 | args.append("--ignore-obsolete") |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
645 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
646 | dlg = PyBabelCommandDialog( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
647 | self, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
648 | title, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
649 | msgSuccess=self.tr("\nMessage catalogs updated successfully."), |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
650 | ) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
651 | res = dlg.startCommand("update", args, workdir) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
652 | if res: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
653 | dlg.exec() |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
654 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
655 | def updateCatalogsObsolete(self, filenames): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
656 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
657 | Public method to update the message catalogs keeping obsolete |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
658 | translations. |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
659 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
660 | @param filenames list of filenames (not used) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
661 | @type list of str |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
662 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
663 | self.updateCatalogs(filenames, withObsolete=True) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
664 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
665 | def updateSelectedCatalogs(self, filenames, withObsolete=False): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
666 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
667 | Public method to update the selected message catalogs. |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
668 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
669 | @param filenames list of filenames |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
670 | @type list of str |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
671 | @param withObsolete flag indicating to keep obsolete translations |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
672 | @type bool |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
673 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
674 | title = self.tr("Updating message catalogs") |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
675 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
676 | locales = {self.__getLocale(f) for f in filenames} |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
677 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
678 | if len(locales) == 0: |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
679 | EricMessageBox.warning( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
680 | self.__ui, title, self.tr("No locales detected. Aborting...") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
681 | ) |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
682 | return |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
683 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
684 | if self.__ensurePybabelConfigured(): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
685 | workdir = self.__project.getApplication()[0] |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
686 | translationsDirectory = self.__ericProject.getAbsoluteUniversalPath( |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
687 | self.__project.getData("flask-babel", "translationsDirectory") |
64
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
688 | ) |
0ee58185b8df
Ported the plug-in to PyQt6 for eric7.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
61
diff
changeset
|
689 | potFile = self.__ericProject.getAbsoluteUniversalPath( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
690 | self.__project.getData("flask-babel", "catalogFile") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
691 | ) |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
692 | argsList = [] |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
693 | for loc in locales: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
694 | args = [ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
695 | "update", |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
696 | "--domain={0}".format( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
697 | self.__project.getData("flask-babel", "domain") |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
698 | ), |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
699 | "--input-file={0}".format(os.path.relpath(potFile, workdir)), |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
700 | "--output-dir={0}".format( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
701 | os.path.relpath(translationsDirectory, workdir) |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
702 | ), |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
703 | "--locale={0}".format(loc), |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
704 | ] |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
705 | if not withObsolete: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
706 | args.append("--ignore-obsolete") |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
707 | argsList.append(args) |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
708 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
709 | dlg = PyBabelCommandDialog( |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
710 | self, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
711 | title=title, |
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
712 | msgSuccess=self.tr("\nMessage catalogs updated successfully."), |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
713 | ) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
714 | res = dlg.startBatchCommand(argsList, workdir) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
715 | if res: |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
716 | dlg.exec() |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
717 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
718 | def updateSelectedCatalogsObsolete(self, filenames): |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
719 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
720 | Public method to update the message catalogs keeping obsolete |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
721 | translations. |
70
22e1d0f69668
Reformatted source code with 'Black'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
66
diff
changeset
|
722 | |
17
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
723 | @param filenames list of filenames (not used) |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
724 | @type list of str |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
725 | """ |
f31df56510a1
Moved the flask-babel support into its own package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
726 | self.updateSelectedCatalogs(filenames, withObsolete=True) |