9 changed files with 426 additions and 0 deletions
@ -0,0 +1,46 @@ |
|||||||
|
/****************************************************************************
|
||||||
|
* |
||||||
|
* (c) 2021 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||||
|
* |
||||||
|
* QGroundControl is licensed according to the terms in the file |
||||||
|
* COPYING.md in the root of the source code directory. |
||||||
|
* |
||||||
|
****************************************************************************/ |
||||||
|
|
||||||
|
|
||||||
|
#include "ComponentInformationTranslationTest.h" |
||||||
|
|
||||||
|
void ComponentInformationTranslationTest::_basic_test() |
||||||
|
{ |
||||||
|
QString translationJson = ":/unittest/TranslationTest.json"; |
||||||
|
QString translationTs = ":/unittest/TranslationTest_de_DE.ts"; |
||||||
|
ComponentInformationTranslation* translation = new ComponentInformationTranslation(this, new QGCCachedFileDownload(this, "")); |
||||||
|
QString tempFilename = translation->translateJsonUsingTS(translationJson, translationTs); |
||||||
|
|
||||||
|
QVERIFY(!tempFilename.isEmpty()); |
||||||
|
|
||||||
|
// Compare json files
|
||||||
|
QFile translationJsonFile(translationJson); |
||||||
|
QVERIFY(translationJsonFile.open(QFile::ReadOnly | QFile::Text)); |
||||||
|
QByteArray expectedOutput = translationJsonFile.readAll().replace("translate-me", "TRANSLATED"); |
||||||
|
|
||||||
|
QJsonDocument expectedJson; |
||||||
|
readJson(expectedOutput, expectedJson); |
||||||
|
|
||||||
|
QFile tempJson(tempFilename); |
||||||
|
QVERIFY(tempJson.open(QFile::ReadOnly | QFile::Text)); |
||||||
|
QByteArray translatedOutput = tempJson.readAll(); |
||||||
|
QJsonDocument translatedJson; |
||||||
|
readJson(translatedOutput, translatedJson); |
||||||
|
|
||||||
|
QVERIFY(expectedJson == translatedJson); |
||||||
|
} |
||||||
|
|
||||||
|
void ComponentInformationTranslationTest::readJson(const QByteArray& bytes, QJsonDocument& jsonDoc) |
||||||
|
{ |
||||||
|
QJsonParseError parseError; |
||||||
|
jsonDoc = QJsonDocument::fromJson(bytes, &parseError); |
||||||
|
QTEST_ASSERT(parseError.error == QJsonParseError::NoError); |
||||||
|
QVERIFY(!jsonDoc.isEmpty()); |
||||||
|
} |
||||||
|
|
@ -0,0 +1,34 @@ |
|||||||
|
/****************************************************************************
|
||||||
|
* |
||||||
|
* (c) 2021 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
||||||
|
* |
||||||
|
* QGroundControl is licensed according to the terms in the file |
||||||
|
* COPYING.md in the root of the source code directory. |
||||||
|
* |
||||||
|
****************************************************************************/ |
||||||
|
|
||||||
|
|
||||||
|
#pragma once |
||||||
|
|
||||||
|
#include "ComponentInformationTranslation.h" |
||||||
|
|
||||||
|
#include "UnitTest.h" |
||||||
|
|
||||||
|
#include <QString> |
||||||
|
#include <QJsonDocument> |
||||||
|
#include <QByteArray> |
||||||
|
|
||||||
|
class ComponentInformationTranslationTest : public UnitTest |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
|
||||||
|
public: |
||||||
|
ComponentInformationTranslationTest() = default; |
||||||
|
virtual ~ComponentInformationTranslationTest() = default; |
||||||
|
|
||||||
|
private slots: |
||||||
|
void _basic_test(); |
||||||
|
private: |
||||||
|
void readJson(const QByteArray& bytes, QJsonDocument& jsonDoc); |
||||||
|
}; |
||||||
|
|
@ -0,0 +1,151 @@ |
|||||||
|
{ |
||||||
|
"version": 1, |
||||||
|
"translation": { |
||||||
|
"items": { |
||||||
|
"first_element": { |
||||||
|
"items": { |
||||||
|
"first_list_element": { |
||||||
|
"list": { |
||||||
|
"key": "name", |
||||||
|
"translate": ["label", "text"] |
||||||
|
} |
||||||
|
}, |
||||||
|
"second_list_element": { |
||||||
|
"list": { |
||||||
|
"translate": ["label", "text"] |
||||||
|
} |
||||||
|
}, |
||||||
|
"object1": { |
||||||
|
"translate": ["list_of_strings"] |
||||||
|
}, |
||||||
|
"object2": { |
||||||
|
"items": { |
||||||
|
"*": { |
||||||
|
"translate": ["name"] |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"second_element": { |
||||||
|
"items": { |
||||||
|
"*": { |
||||||
|
"translate-global": ["category"] |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"third_element": { |
||||||
|
"items": { |
||||||
|
"subgroups": { |
||||||
|
"$ref": "#/$defs/recursive-def" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"$defs": { |
||||||
|
"recursive-def": { |
||||||
|
"list": { |
||||||
|
"translate": ["description"], |
||||||
|
"items": { |
||||||
|
"subgroups": { |
||||||
|
"$ref": "#/$defs/recursive-def" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
|
||||||
|
"first_element": { |
||||||
|
"first_list_element": [ |
||||||
|
{ |
||||||
|
"name": "1. element", |
||||||
|
"label": "translate-me-list1-1.0", |
||||||
|
"text": "translate-me-list1-1.1" |
||||||
|
}, |
||||||
|
{ |
||||||
|
"name": "2. element", |
||||||
|
"label": "translate-me-list1-2.0", |
||||||
|
"text": "translate-me-list1-2.1" |
||||||
|
}, |
||||||
|
{ |
||||||
|
"name": "3. element", |
||||||
|
"label": "translate-me-list1-3.0", |
||||||
|
"text": "translate-me-list1-3.1" |
||||||
|
} |
||||||
|
], |
||||||
|
"second_list_element": [ |
||||||
|
{ |
||||||
|
"name": "1. element", |
||||||
|
"label": "translate-me-list2-1.0", |
||||||
|
"text": "translate-me-list2-1.1" |
||||||
|
}, |
||||||
|
{ |
||||||
|
"name": "2. element", |
||||||
|
"label": "translate-me-list2-2.0", |
||||||
|
"text": "translate-me-list2-2.1" |
||||||
|
}, |
||||||
|
{ |
||||||
|
"name": "3. element", |
||||||
|
"label": "translate-me-list2-3.0", |
||||||
|
"text": "translate-me-list2-3.1" |
||||||
|
} |
||||||
|
], |
||||||
|
"object1": { |
||||||
|
"list_of_strings": ["translate-me-list-of-strings-1", "translate-me-list-of-strings-2", "translate-me-list-of-strings-3"] |
||||||
|
}, |
||||||
|
"object2": { |
||||||
|
"key1": { |
||||||
|
"name": "translate-me-name1" |
||||||
|
}, |
||||||
|
"key2": { |
||||||
|
"name": "translate-me-name2" |
||||||
|
}, |
||||||
|
"key3": { |
||||||
|
"name": "translate-me-name3" |
||||||
|
} |
||||||
|
} |
||||||
|
}, |
||||||
|
"second_element": { |
||||||
|
"element1": { |
||||||
|
"category": "translate-me-global-cat1" |
||||||
|
}, |
||||||
|
"element2": { |
||||||
|
"category": "translate-me-global-cat2" |
||||||
|
}, |
||||||
|
"element3": { |
||||||
|
"category": "translate-me-global-cat1" |
||||||
|
}, |
||||||
|
"element4": { |
||||||
|
"category": "translate-me-global-cat2" |
||||||
|
}, |
||||||
|
"element5": { |
||||||
|
"category": "translate-me-global-cat <> special symbol" |
||||||
|
} |
||||||
|
}, |
||||||
|
"third_element": { |
||||||
|
"subgroups": [ |
||||||
|
{ |
||||||
|
"description": "translate-me-subgroup1", |
||||||
|
"subgroups": [ |
||||||
|
{ |
||||||
|
"description": "translate-me-subgroup1-1", |
||||||
|
"subgroups": [ |
||||||
|
{ |
||||||
|
"description": "translate-me-subgroup1-1-1" |
||||||
|
} |
||||||
|
] |
||||||
|
}, |
||||||
|
{ |
||||||
|
"description": "translate-me-subgroup1-2", |
||||||
|
"subgroups": [ |
||||||
|
{ |
||||||
|
"description": "translate-me-subgroup1-2-1" |
||||||
|
} |
||||||
|
] |
||||||
|
} |
||||||
|
] |
||||||
|
} |
||||||
|
] |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,186 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<!DOCTYPE TS> |
||||||
|
<TS version="2.1"> |
||||||
|
<context> |
||||||
|
<name>/first_element/first_list_element/1. element/label</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-list1-1.0</source> |
||||||
|
<translation>TRANSLATED-list1-1.0</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/first_element/first_list_element/1. element/text</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-list1-1.1</source> |
||||||
|
<translation>TRANSLATED-list1-1.1</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/first_element/first_list_element/2. element/label</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-list1-2.0</source> |
||||||
|
<translation>TRANSLATED-list1-2.0</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/first_element/first_list_element/2. element/text</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-list1-2.1</source> |
||||||
|
<translation>TRANSLATED-list1-2.1</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/first_element/first_list_element/3. element/label</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-list1-3.0</source> |
||||||
|
<translation>TRANSLATED-list1-3.0</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/first_element/first_list_element/3. element/text</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-list1-3.1</source> |
||||||
|
<translation>TRANSLATED-list1-3.1</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/first_element/second_list_element/0/label</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-list2-1.0</source> |
||||||
|
<translation>TRANSLATED-list2-1.0</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/first_element/second_list_element/0/text</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-list2-1.1</source> |
||||||
|
<translation>TRANSLATED-list2-1.1</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/first_element/second_list_element/1/label</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-list2-2.0</source> |
||||||
|
<translation>TRANSLATED-list2-2.0</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/first_element/second_list_element/1/text</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-list2-2.1</source> |
||||||
|
<translation>TRANSLATED-list2-2.1</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/first_element/second_list_element/2/label</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-list2-3.0</source> |
||||||
|
<translation>TRANSLATED-list2-3.0</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/first_element/second_list_element/2/text</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-list2-3.1</source> |
||||||
|
<translation>TRANSLATED-list2-3.1</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/first_element/object1/list_of_strings/0</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-list-of-strings-1</source> |
||||||
|
<translation>TRANSLATED-list-of-strings-1</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/first_element/object1/list_of_strings/1</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-list-of-strings-2</source> |
||||||
|
<translation>TRANSLATED-list-of-strings-2</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/first_element/object1/list_of_strings/2</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-list-of-strings-3</source> |
||||||
|
<translation>TRANSLATED-list-of-strings-3</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/first_element/object2/key1/name</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-name1</source> |
||||||
|
<translation>TRANSLATED-name1</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/first_element/object2/key2/name</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-name2</source> |
||||||
|
<translation>TRANSLATED-name2</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/first_element/object2/key3/name</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-name3</source> |
||||||
|
<translation>TRANSLATED-name3</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/third_element/subgroups/0/description</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-subgroup1</source> |
||||||
|
<translation>TRANSLATED-subgroup1</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/third_element/subgroups/0/subgroups/0/description</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-subgroup1-1</source> |
||||||
|
<translation>TRANSLATED-subgroup1-1</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/third_element/subgroups/0/subgroups/0/subgroups/0/description</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-subgroup1-1-1</source> |
||||||
|
<translation>TRANSLATED-subgroup1-1-1</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/third_element/subgroups/0/subgroups/1/description</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-subgroup1-2</source> |
||||||
|
<translation>TRANSLATED-subgroup1-2</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>/third_element/subgroups/0/subgroups/1/subgroups/0/description</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-subgroup1-2-1</source> |
||||||
|
<translation>TRANSLATED-subgroup1-2-1</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>$globals/category/translate-me-global-cat <> special symbol</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-global-cat <> special symbol</source> |
||||||
|
<translation>TRANSLATED-global-cat <> special symbol</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>$globals/category/translate-me-global-cat2</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-global-cat2</source> |
||||||
|
<translation>TRANSLATED-global-cat2</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
<context> |
||||||
|
<name>$globals/category/translate-me-global-cat1</name> |
||||||
|
<message> |
||||||
|
<source>translate-me-global-cat1</source> |
||||||
|
<translation>TRANSLATED-global-cat1</translation> |
||||||
|
</message> |
||||||
|
</context> |
||||||
|
</TS> |
Loading…
Reference in new issue