MCPcopy Create free account
hub / github.com/OpenOrienteering/mapper / processSymbolSetTranslations

Method processSymbolSetTranslations

test/symbol_set_t.cpp:923–1062  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

921}
922
923void 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("&apos;", "'");
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;

Callers

nothing calls this directly

Calls 12

QLatin1StringClass · 0.85
readTsFileFunction · 0.85
writeObsoleteEntriesFunction · 0.85
saveIfDifferentFunction · 0.85
openMethod · 0.80
writeAttributeMethod · 0.80
clearMethod · 0.45
sizeMethod · 0.45
errorMethod · 0.45
isEmptyMethod · 0.45
containsMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected