24
24
#include " qgssettings.h"
25
25
#include < qgsmaplayer.h>
26
26
#include < qgsvectorlayer.h>
27
+ #include < qgslayertree.h>
28
+ #include < qgslayertreegroup.h>
29
+ #include " qgsrelationmanager.h"
27
30
28
31
class TestQgsTranslateProject : public QObject
29
32
{
@@ -48,12 +51,11 @@ class TestQgsTranslateProject : public QObject
48
51
49
52
void TestQgsTranslateProject::initTestCase ()
50
53
{
51
- // start application in german
54
+ // start application
52
55
QgsApplication::init ();
53
56
QgsApplication::initQgis ();
54
57
55
58
original_locale = settings.value ( QStringLiteral ( " locale/userLocale" ), " " ).toString () ;
56
- settings.setValue ( QStringLiteral ( " locale/userLocale" ), " de" );
57
59
}
58
60
59
61
void TestQgsTranslateProject::cleanupTestCase ()
@@ -76,10 +78,7 @@ void TestQgsTranslateProject::cleanupTestCase()
76
78
77
79
void TestQgsTranslateProject::init ()
78
80
{
79
- // open project
80
- QString projectFileName ( TEST_DATA_DIR );
81
- projectFileName = projectFileName + " /project_translation/points_translation.qgs" ;
82
- QgsProject::instance ()->read ( projectFileName );
81
+ // not needed
83
82
}
84
83
85
84
void TestQgsTranslateProject::cleanup ()
@@ -89,62 +88,149 @@ void TestQgsTranslateProject::cleanup()
89
88
90
89
void TestQgsTranslateProject::createTsFile ()
91
90
{
92
- // the base is points_translation_de.qgs and with german values
93
- // then we generate a ts file for spanish and the ts file with additional es postfix is created
91
+ // open project in english
92
+ settings.setValue ( QStringLiteral ( " locale/userLocale" ), " en" );
93
+ QString projectFileName ( TEST_DATA_DIR );
94
+ projectFileName = projectFileName + " /project_translation/points_translation.qgs" ;
95
+ QgsProject::instance ()->read ( projectFileName );
94
96
95
- // create ts- file
96
- QgsProject::instance ()->generateTsFile ( " es " );
97
+ // create ts file for german
98
+ QgsProject::instance ()->generateTsFile ( " de " );
97
99
98
- // check if tsfile is created
100
+ // check if ts file is created
99
101
QString tsFileName ( TEST_DATA_DIR );
100
- tsFileName = tsFileName + " /project_translation/points_translation_de_es .ts" ;
102
+ tsFileName = tsFileName + " /project_translation/points_translation_de .ts" ;
101
103
QFile tsFile ( tsFileName );
102
104
QVERIFY ( tsFile.exists () );
103
105
104
106
tsFile.open ( QIODevice::ReadWrite );
105
107
106
108
QString tsFileContent ( tsFile.readAll () );
107
109
108
- // check if tsFile contains layer name Punkte
109
- QVERIFY ( tsFileContent.contains ( " <source>Punkte</source>" ) );
110
-
111
- // check if tsFile contains layer group name
112
-
113
- // check if tsFile contains alias value
114
-
115
- // check if tsFile contains field name
116
- // QVERIFY( tsFileContent.contains( "<source>klaso</source>" ) );
117
-
118
- // check if tsFile contains relation name
110
+ // LAYER NAMES
111
+ // lines
112
+ QVERIFY ( tsFileContent.contains ( " <source>lines</source>" ) );
113
+ // points
114
+ QVERIFY ( tsFileContent.contains ( " <source>points</source>" ) );
115
+
116
+ // LAYER GROUPS AND SUBGROUPS
117
+ // Points:
118
+ // Planes and Roads
119
+ QVERIFY ( tsFileContent.contains ( " <source>Planes and Roads</source>" ) );
120
+ // Little bit of nothing
121
+ QVERIFY ( tsFileContent.contains ( " <source>Little bit of nothing</source>" ) );
122
+
123
+ // FIELDS AND ALIASES
124
+ // Lines:
125
+ // Name (Alias: Runwayid)
126
+ QVERIFY ( tsFileContent.contains ( " <source>Runwayid</source>" ) );
127
+ // Value (Alias: Name)
128
+ QVERIFY ( tsFileContent.contains ( " <source>Name</source>" ) );
129
+
130
+ // Points:
131
+ // Class (Alias: Level)
132
+ QVERIFY ( tsFileContent.contains ( " <source>Level</source>" ) );
133
+ // Heading
134
+ QVERIFY ( tsFileContent.contains ( " <source>Heading</source>" ) );
135
+ // Importance
136
+ QVERIFY ( tsFileContent.contains ( " <source>Importance</source>" ) );
137
+ // Pilots
138
+ QVERIFY ( tsFileContent.contains ( " <source>Pilots</source>" ) );
139
+ // Cabin Crew
140
+ QVERIFY ( tsFileContent.contains ( " <source>Cabin Crew</source>" ) );
141
+ // Staff
142
+ QVERIFY ( tsFileContent.contains ( " <source>Staff</source>" ) );
143
+
144
+ // FORMCONTAINERS
145
+ // Plane
146
+ QVERIFY ( tsFileContent.contains ( " <source>Plane</source>" ) );
147
+ // Employees
148
+ QVERIFY ( tsFileContent.contains ( " <source>Employees</source>" ) );
149
+ // Flightattends
150
+ QVERIFY ( tsFileContent.contains ( " <source>Flightattends</source>" ) );
151
+
152
+ // RELATIONS
153
+ // Runway
154
+ QVERIFY ( tsFileContent.contains ( " <source>Runway</source>" ) );
155
+ // Sheepwalk
156
+ QVERIFY ( tsFileContent.contains ( " <source>Sheepwalk</source>" ) );
119
157
120
158
tsFile.close ();
121
159
}
122
160
123
161
void TestQgsTranslateProject::translateProject ()
124
162
{
163
+ // open project in german
164
+ settings.setValue ( QStringLiteral ( " locale/userLocale" ), " de" );
165
+ QString projectFileName ( TEST_DATA_DIR );
166
+ projectFileName = projectFileName + " /project_translation/points_translation.qgs" ;
167
+ QgsProject::instance ()->read ( projectFileName );
168
+
125
169
// with the qm file containing translation from en to de, the project should be in german and renamed with postfix .de
126
170
QgsVectorLayer *points_layer = qobject_cast<QgsVectorLayer *>( QgsProject::instance ()->mapLayer ( " points_240d6bd6_9203_470a_994a_aae13cd9fa04" ) );
127
171
QgsVectorLayer *lines_layer = qobject_cast<QgsVectorLayer *>( QgsProject::instance ()->mapLayer ( " lines_a677672a_bf5d_410d_98c9_d326a5719a1b" ) );
128
172
129
- // check if layer names translated
130
- QCOMPARE ( points_layer-> name (), QStringLiteral ( " Punkte " ) );
173
+ // LAYER NAMES
174
+ // lines -> Linien
131
175
QCOMPARE ( lines_layer->name (), QStringLiteral ( " Linien" ) );
176
+ // points -> Punkte
177
+ QCOMPARE ( points_layer->name (), QStringLiteral ( " Punkte" ) );
132
178
133
- // check if group name translated
134
-
135
- // check if second group name translated
136
-
137
- // check if first alias value translated
138
-
139
- // check if second alias value translated
140
-
141
- // check if first field name translated to the alias
142
-
143
- // check if second field name translated to the alias
144
-
145
- // check if first relation name translated
146
-
147
- // check if second relation name translated
179
+ // LAYER GROUPS AND SUBGROUPS
180
+ // Points:
181
+ // Planes and Roads -> Flugzeuge und Strassen
182
+ QVERIFY ( QgsProject::instance ()->layerTreeRoot ()->findGroup ( QStringLiteral ( " Flugzeuge und Strassen" ) ) );
183
+ // Little bit of nothing -> Bisschen nichts
184
+ QVERIFY ( QgsProject::instance ()->layerTreeRoot ()->findGroup ( QStringLiteral ( " Bisschen nichts" ) ) );
185
+
186
+ // FIELDS AND ALIASES
187
+ // Lines:
188
+ const QgsFields lines_fields = lines_layer->fields ();
189
+ // Name (Alias: Runwayid) -> Pistenid
190
+ QCOMPARE ( lines_fields.field ( QStringLiteral ( " Name" ) ).alias (), QStringLiteral ( " Pistenid" ) );
191
+ // Value (Alias: Name) -> Pistenname
192
+ QCOMPARE ( lines_fields.field ( QStringLiteral ( " Value" ) ).alias (), QStringLiteral ( " Pistenname" ) );
193
+
194
+ // Points:
195
+ const QgsFields points_fields = points_layer->fields ();
196
+ // Class (Alias: Level) -> Klasse
197
+ QCOMPARE ( points_fields.field ( QStringLiteral ( " Class" ) ).alias (), QStringLiteral ( " Klasse" ) );
198
+ // Heading -> Titel
199
+ QCOMPARE ( points_fields.field ( QStringLiteral ( " Heading" ) ).alias (), QStringLiteral ( " Titel" ) );
200
+ // Importance -> Wichtigkeit
201
+ QCOMPARE ( points_fields.field ( QStringLiteral ( " Importance" ) ).alias (), QStringLiteral ( " Wichtigkeit" ) );
202
+ // Pilots -> Piloten
203
+ QCOMPARE ( points_fields.field ( QStringLiteral ( " Pilots" ) ).alias (), QStringLiteral ( " Piloten" ) );
204
+ // Cabin Crew -> Kabinenpersonal
205
+ QCOMPARE ( points_fields.field ( QStringLiteral ( " Cabin Crew" ) ).alias (), QStringLiteral ( " Kabinenpersonal" ) );
206
+ // Staff -> Mitarbeiter
207
+ QCOMPARE ( points_fields.field ( QStringLiteral ( " Staff" ) ).alias (), QStringLiteral ( " Mitarbeiter" ) );
208
+
209
+ // FORMCONTAINERS
210
+ QList<QgsAttributeEditorElement *> elements = points_layer->editFormConfig ().invisibleRootContainer ()->children ();
211
+ QList<QgsAttributeEditorContainer *> containers;
212
+ for ( QgsAttributeEditorElement *element : elements )
213
+ {
214
+ if ( element->type () == QgsAttributeEditorElement::AeTypeContainer )
215
+ containers.append ( dynamic_cast <QgsAttributeEditorContainer *>( element ) );
216
+ }
217
+
218
+ // Plane -> Flugzeug
219
+ QCOMPARE ( containers.at ( 0 )->name (), QStringLiteral ( " Flugzeug" ) );
220
+ // Employees -> Angestellte
221
+ QCOMPARE ( containers.at ( 1 )->name (), QStringLiteral ( " Angestellte" ) );
222
+ // Flightattends -> Flugbegleitung
223
+ for ( QgsAttributeEditorElement *element : containers.at ( 1 )->children () )
224
+ {
225
+ if ( element->type () == QgsAttributeEditorElement::AeTypeContainer )
226
+ QCOMPARE ( element->name (), QStringLiteral ( " Flugbegleitung" ) );
227
+ }
228
+
229
+ // RELATIONS
230
+ // Runway -> Piste
231
+ QCOMPARE ( QgsProject::instance ()->relationManager ()->relation ( QStringLiteral ( " points_240_Importance_lines_a677_Value" ) ).name (), QStringLiteral ( " Piste" ) );
232
+ // Sheepwalk -> Schafweide
233
+ QCOMPARE ( QgsProject::instance ()->relationManager ()->relation ( QStringLiteral ( " points_240_Importance_lines_a677_Value_1" ) ).name (), QStringLiteral ( " Schafweide" ) );
148
234
149
235
QString deProjectFileName ( TEST_DATA_DIR );
150
236
deProjectFileName = deProjectFileName + " /project_translation/points_translation_de.qgs" ;
0 commit comments