diff --git a/README.md b/README.md index 3d4350b..e3932e0 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ Example of supported TS file: context a - + source example comment example @@ -114,8 +114,8 @@ Example of supported TS file: translator comment example translation example - Beispiel1 - Beispiel2 + example 1: type is optional and maximum one type + example 2 diff --git a/src/internal/CsvBuilder.cpp b/src/internal/CsvBuilder.cpp index ccb5d25..37de9ab 100644 --- a/src/internal/CsvBuilder.cpp +++ b/src/internal/CsvBuilder.cpp @@ -19,18 +19,21 @@ CsvBuilder::CsvBuilder(InOutParameter &¶meter) : Builder{ parameter } auto CsvBuilder::build(const Result &res) const -> bool { - auto strData = addTsSupport(); + auto strData = addTsSupport(res); QStringList strList; - strList << TitleHeader::Context << TitleHeader::Source - << TitleHeader::Translation << TitleHeader::Location; - + strList << TitleHeader::Context << TitleHeader::ID << TitleHeader::Source + << TitleHeader::Translation << TitleHeader::TranslationType + << TitleHeader::Comment << TitleHeader::ExtraComment << TitleHeader::TranslatorComment + << TitleHeader::Location; strData.addRow(strList); for (const auto &tr : res.translantions) { for (const auto &msg : tr.messages) { strList.clear(); - strList << tr.name << msg.source << msg.translation; + strList << tr.name << msg.identifier << msg.source + << msg.translation << msg.translationtype + << msg.comment << msg.extracomment << msg.translatorcomment; for (const auto &loc : msg.locations) { strList << QString(loc.first + " - " + QString::number(loc.second)); @@ -50,7 +53,7 @@ auto CsvBuilder::build(const Result &res) const -> bool return true; } -QtCSV::StringData CsvBuilder::addTsSupport() const +QtCSV::StringData CsvBuilder::addTsSupport(const Result &res) const { QtCSV::StringData strData; const auto appVersion = qApp->applicationVersion(); @@ -58,10 +61,10 @@ QtCSV::StringData CsvBuilder::addTsSupport() const const auto TsSupportVersion = QVersionNumber(4, 5, 0); if (QVersionNumber::compare(currentVersion, TsSupportVersion) >= 0) { QStringList strList; - strList << TitleHeader::TsVersion; + strList << TitleHeader::TsVersion << TitleHeader::SourceLanguage << TitleHeader::Language; strData.addRow(strList); strList.clear(); - strList << m_ioParameter.tsVersion; + strList << res.root.tsVersion << res.root.sourcelanguage << res.root.language; strData.addRow(strList); strList.clear(); } diff --git a/src/internal/CsvBuilder.hpp b/src/internal/CsvBuilder.hpp index 6f449ab..82c690c 100644 --- a/src/internal/CsvBuilder.hpp +++ b/src/internal/CsvBuilder.hpp @@ -19,5 +19,5 @@ class CsvBuilder : public Builder bool build(const Result &res) const override; private: - QtCSV::StringData addTsSupport() const; + QtCSV::StringData addTsSupport(const Result &res) const; }; diff --git a/src/internal/CsvParser.cpp b/src/internal/CsvParser.cpp index 74144f3..8926c05 100644 --- a/src/internal/CsvParser.cpp +++ b/src/internal/CsvParser.cpp @@ -23,7 +23,7 @@ auto CsvParser::parse() const -> Result } removeEmptyFrontBack(list); - splitByRow(list); + //splitByRow(list); RootAttr root; @@ -33,7 +33,14 @@ auto CsvParser::parse() const -> Result InOutParameter p{ "", "", m_ioParameter.tsVersion, {} }; if (QVersionNumber::compare(currentVersion, TsSupportVersion) >= 0) { list.pop_front(); - p.tsVersion = list.first().first(); + root.tsVersion = list.first().at(0); + qDebug() << root.tsVersion; + //list.pop_front(); + root.sourcelanguage = list.first().at(1); + qDebug() << root.sourcelanguage; + //list.pop_front(); + root.language = list.first().at(2); + qDebug() << root.language; list.pop_front(); } @@ -45,18 +52,32 @@ auto CsvParser::parse() const -> Result removeQuote(list); for (const QStringList &l : qAsConst(list)) { + qDebug("---newline---"); for (const auto &value : l) { context.name = l.at(kNameIndex); + qDebug() << context.name; } - msg.source = l.at(kSourceIndex); - msg.translation = l.at(kTranslationIndex); + msg.identifier = l.at(kIdIndex); + qDebug() << msg.identifier; + msg.source = l.at(kSourceIndex); + qDebug() << msg.source; + msg.translation = l.at(kTranslationIndex); + qDebug() << msg.translation; + msg.translationtype = l.at(kTranslationTypeIndex); + qDebug() << msg.translationtype; + msg.comment = l.at(kCommentIndex); + qDebug() << msg.comment; + msg.extracomment = l.at(kExtraCommentIndex); + qDebug() << msg.extracomment; + msg.translatorcomment = l.at(kTranslatorCommentIndex); + qDebug() << msg.translatorcomment; + msg.locations.emplace_back(decodeLocation(l.at(kLocationsIndex))); for (int i = kLocationsIndex + 1; i < l.size(); i++) { msg.locations.emplace_back(decodeLocation(l.at(i))); } - auto it = std::find_if(translations.begin(), translations.end(), [&](const auto &c) { return c.name == context.name; }); diff --git a/src/internal/CsvParser.hpp b/src/internal/CsvParser.hpp index 6ac5f7d..92f8589 100644 --- a/src/internal/CsvParser.hpp +++ b/src/internal/CsvParser.hpp @@ -25,8 +25,13 @@ class CsvParser : public Parser static bool isLocation(const QString &value); const int kNameIndex{ 0 }; - const int kSourceIndex{ 1 }; - const int kTranslationIndex{ 2 }; - const int kLocationsIndex{ 3 }; + const int kIdIndex{ 1 }; + const int kSourceIndex{ 2 }; + const int kTranslationIndex{ 3 }; + const int kTranslationTypeIndex{ 4 }; + const int kCommentIndex{ 5 }; + const int kExtraCommentIndex{ 6 }; + const int kTranslatorCommentIndex{ 7 }; + const int kLocationsIndex{ 8 }; const int kRowSize{ 8 }; }; diff --git a/tests/files/scenario_after_version_4_5_0.csv b/tests/files/scenario_after_version_4_5_0.csv index 354e286..dd83a9d 100644 --- a/tests/files/scenario_after_version_4_5_0.csv +++ b/tests/files/scenario_after_version_4_5_0.csv @@ -1,11 +1,11 @@ -"TsVersion" -"2.1" -"Context";"Source";"Translation";"Location" -"main";"Hello +"TsVersion";"sourcelanguage";"language" +"2.1";"";"" +"Context";"ID";"Source";"Translation";"TranslationType";"comment";"extracomment";"translatorcomment";"Location" +"main";"";"Hello world multiline -0";"";"main.qml - 15" -"main";"Hello +0";"";"";"";"";"";"main.qml - 15" +"main";"";"Hello world multiline -1";"";"main.qml - 24" +1";"";"";"";"";"";"main.qml - 24" diff --git a/tests/files/scenario_multiline.csv b/tests/files/scenario_multiline.csv index 74ace79..dd83a9d 100644 --- a/tests/files/scenario_multiline.csv +++ b/tests/files/scenario_multiline.csv @@ -1,9 +1,11 @@ -"Context";"Source";"Translation";"Location" -"main";"Hello +"TsVersion";"sourcelanguage";"language" +"2.1";"";"" +"Context";"ID";"Source";"Translation";"TranslationType";"comment";"extracomment";"translatorcomment";"Location" +"main";"";"Hello world multiline -0";"";"main.qml - 15" -"main";"Hello +0";"";"";"";"";"";"main.qml - 15" +"main";"";"Hello world multiline -1";"";"main.qml - 24" +1";"";"";"";"";"";"main.qml - 24" diff --git a/tests/files/scenario_multilocation.csv b/tests/files/scenario_multilocation.csv index ba81a3c..14eb9c2 100644 --- a/tests/files/scenario_multilocation.csv +++ b/tests/files/scenario_multilocation.csv @@ -1,7 +1,9 @@ -"Context";"Source";"Translation";"Location" -"ThemeWidget";"Series";"";"../themewidget.cpp - 289";"../themewidget.cpp - 290";"../themewidget.cpp - 291" -"Test";"SourceValue";"";"../themewidget.cpp - 89";"../themewidget.cpp - 90";"../themewidget.cpp - 91" -"ThemeWidgetForm";"Theme:";"";"../themewidget.ui - 19" -"ThemeWidgetForm";"Animation:";"";"../themewidget.ui - 29" -"ThemeWidgetForm";"Legend:";"";"../themewidget.ui - 39" -"ThemeWidgetForm";"Anti-aliasing";"";"../themewidget.ui - 49" +"TsVersion";"sourcelanguage";"language" +"2.1";"";"" +"Context";"ID";"Source";"Translation";"TranslationType";"comment";"extracomment";"translatorcomment";"Location" +"ThemeWidget";"";"Series";"";"";"";"";"";"../themewidget.cpp - 289";"../themewidget.cpp - 290";"../themewidget.cpp - 291" +"Test";"";"SourceValue";"";"";"";"";"";"../themewidget.cpp - 89";"../themewidget.cpp - 90";"../themewidget.cpp - 91" +"ThemeWidgetForm";"";"Theme:";"";"";"";"";"";"../themewidget.ui - 19" +"ThemeWidgetForm";"";"Animation:";"";"";"";"";"";"../themewidget.ui - 29" +"ThemeWidgetForm";"";"Legend:";"";"";"";"";"";"../themewidget.ui - 39" +"ThemeWidgetForm";"";"Anti-aliasing";"";"";"";"";"";"../themewidget.ui - 49" diff --git a/tests/files/scenario_simple.csv b/tests/files/scenario_simple.csv index 9d1fdcd..125a471 100644 --- a/tests/files/scenario_simple.csv +++ b/tests/files/scenario_simple.csv @@ -1,5 +1,7 @@ -"Context";"Source";"Translation";"Location" -"MenuBar";"text";"";"../src/app/qml/MenuBar.qml - 17" -"MenuBar";"map";"";"../src/app/qml/MenuBar.qml - 28" -"MenuBar";"cam";"";"../src/app/qml/MenuBar.qml - 43" -"MenuBar";"checklist";"";"../src/app/qml/MenuBar.qml - 58" +"TsVersion";"sourcelanguage";"language" +"2.1";"en";"it" +"Context";"ID";"Source";"Translation";"TranslationType";"comment";"extracomment";"translatorcomment";"Location" +"MenuBar";"";"text";"";"unfinished";"my comment";"";"";"../src/app/qml/MenuBar.qml - 17" +"MenuBar";"1abc";"map";"whatever";"vanished";"";"extra comment test";"translatorcomment";"../src/app/qml/MenuBar.qml - 28" +"MenuBar";"";"cam";"whichever";"obsolete";"";"";"";"../src/app/qml/MenuBar.qml - 43" +"MenuBar";"";"checklist";"mytranslation";"";"";"";"";"../src/app/qml/MenuBar.qml - 58" diff --git a/tests/files/scenario_simple.ts b/tests/files/scenario_simple.ts index 828f2ce..3a056c3 100644 --- a/tests/files/scenario_simple.ts +++ b/tests/files/scenario_simple.ts @@ -1,27 +1,30 @@ - + - + MenuBar text - + my comment + - + map - + extra comment test + translatorcomment + whatever cam - + whichever checklist - + mytranslation diff --git a/tests/tst_csv2ts.cpp b/tests/tst_csv2ts.cpp index 87b4854..a15d728 100644 --- a/tests/tst_csv2ts.cpp +++ b/tests/tst_csv2ts.cpp @@ -7,6 +7,7 @@ auto main() -> int { bool ret = false; + QApplication::setApplicationVersion("5.0.0"); ret |= !test_conversion("scenario_simple.csv", "scenario_simple.ts", ConverterFactory::ConversionType::Csv2Ts); @@ -17,7 +18,6 @@ auto main() -> int ret |= !test_conversion("scenario_multiline.csv", "scenario_multiline.ts", ConverterFactory::ConversionType::Csv2Ts); - QApplication::setApplicationVersion("4.5.0"); ret |= !test_conversion("scenario_ts_version.csv", "scenario_ts_version.ts", ConverterFactory::ConversionType::Csv2Ts); diff --git a/tests/tst_ts2csv.cpp b/tests/tst_ts2csv.cpp index d7be217..81a1b47 100644 --- a/tests/tst_ts2csv.cpp +++ b/tests/tst_ts2csv.cpp @@ -7,6 +7,7 @@ auto main() -> int { bool ret = false; + QApplication::setApplicationVersion("5.0.0"); ret |= !test_conversion("scenario_simple.ts", "scenario_simple.csv", ConverterFactory::ConversionType::Ts2Csv); @@ -17,7 +18,6 @@ auto main() -> int ret |= !test_conversion("scenario_multiline.ts", "scenario_multiline.csv", ConverterFactory::ConversionType::Ts2Csv); - QApplication::setApplicationVersion("4.5.0"); ret |= !test_conversion("scenario_multiline.ts", "scenario_after_version_4_5_0.csv", ConverterFactory::ConversionType::Ts2Csv); diff --git a/tests/tst_ts2xlsx.cpp b/tests/tst_ts2xlsx.cpp index 610aef0..e7fbea2 100644 --- a/tests/tst_ts2xlsx.cpp +++ b/tests/tst_ts2xlsx.cpp @@ -142,11 +142,11 @@ auto main() -> int { bool ret = false; + QApplication::setApplicationVersion("5.0.0"); ret |= !scenario_simple(); ret |= !scenario_multiLocation(); - QApplication::setApplicationVersion("4.5.0"); ret |= !scenario_ts_version(); return static_cast(ret);