| 921 | } |
| 922 | |
| 923 | void SymbolSetTool::processSymbolSetTranslations() const |
| 924 | { |
| 925 | auto translation_filename = QString::fromLatin1(QTest::currentDataTag()); |
| 926 | auto language = translation_filename.mid(int(qstrlen("map_symbols_"))); |
| 927 | language.chop(int(qstrlen(".ts"))); |
| 928 | if (language == QLatin1String("template")) |
| 929 | language.clear(); |
| 930 | |
| 931 | QByteArray new_data; |
| 932 | QByteArray existing_data; |
| 933 | QFile file(translations_dir.absoluteFilePath(translation_filename)); |
| 934 | if (file.exists()) |
| 935 | { |
| 936 | QVERIFY(file.open(QIODevice::ReadOnly)); |
| 937 | existing_data.reserve(int(file.size()+1)); |
| 938 | existing_data = file.readAll(); |
| 939 | QCOMPARE(file.error(), QFileDevice::NoError); |
| 940 | file.close(); |
| 941 | |
| 942 | // Workaround Weblate quirk |
| 943 | existing_data.replace("\n </message>", "\n </message>"); |
| 944 | existing_data.replace("'", "'"); |
| 945 | |
| 946 | new_data.reserve(existing_data.size()*2); |
| 947 | } |
| 948 | |
| 949 | QBuffer buffer(&existing_data); |
| 950 | auto translations_from_ts = readTsFile(buffer); |
| 951 | QVERIFY(!buffer.isOpen()); |
| 952 | |
| 953 | buffer.setBuffer(&new_data); |
| 954 | QVERIFY(buffer.open(QIODevice::WriteOnly | QIODevice::Truncate)); |
| 955 | QXmlStreamWriter xml(&buffer); |
| 956 | xml.setAutoFormatting(true); |
| 957 | xml.writeStartDocument(); |
| 958 | xml.writeDTD(QLatin1String("<!DOCTYPE TS>")); |
| 959 | xml.writeStartElement(QLatin1String("TS")); |
| 960 | xml.writeAttribute(QLatin1String("version"), QLatin1String("2.1")); |
| 961 | if (!language.isEmpty()) |
| 962 | xml.writeAttribute(QLatin1String("language"), language); |
| 963 | |
| 964 | auto context = QString{}; |
| 965 | for (auto it = begin(translation_entries), last = end(translation_entries); it != last; ++it) |
| 966 | { |
| 967 | auto entry = TranslationEntry{*it}; // copy, don't touch original entry. |
| 968 | entry.type = NeedsReview; |
| 969 | entry.obsolete = false; |
| 970 | |
| 971 | if (context != entry.context) |
| 972 | { |
| 973 | if (!context.isEmpty()) |
| 974 | { |
| 975 | writeObsoleteEntries(xml, translations_from_ts, context); |
| 976 | xml.writeEndElement(); // context |
| 977 | } |
| 978 | xml.writeStartElement(QLatin1String("context")); |
| 979 | xml.writeTextElement(QLatin1String("name"), entry.context); |
| 980 | context = entry.context; |
nothing calls this directly
no test coverage detected