Skip to content

Commit

Permalink
aligned tst_ts2csv
Browse files Browse the repository at this point in the history
  • Loading branch information
s-t-e-f-a-n committed Jul 2, 2024
1 parent 11da4d6 commit a14fc34
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 54 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ Example of supported TS file:
<TS version="2.1" language="de" sourcelanguage="en">
<context>
<name>context a</name>
<message>
<message id="my-id">
<location filename="../dir/file.ui" line="26"/>
<source>source example</source>
<comment>comment example</comment>
<extracomment>extra comment example</extracomment>
<translatorcomment>translator comment example</translatorcomment>
<translation>translation example</translation>
<translation type="unfinished"></translation>
<translation type="vanished">Beispiel1</translation>
<translation type="obsolete">Beispiel2</translation>
<translation type="vanished">example 1: type is optional and maximum one type</translation>
<translation type="obsolete">example 2</translation>
</message>
</context>
</TS>
Expand Down
19 changes: 11 additions & 8 deletions src/internal/CsvBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ CsvBuilder::CsvBuilder(InOutParameter &&parameter) : 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));
Expand All @@ -50,18 +53,18 @@ 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();
const auto currentVersion = QVersionNumber::fromString(appVersion);
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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/internal/CsvBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
31 changes: 26 additions & 5 deletions src/internal/CsvParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ auto CsvParser::parse() const -> Result
}

removeEmptyFrontBack(list);
splitByRow(list);
//splitByRow(list);

RootAttr root;

Expand All @@ -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();
}

Expand All @@ -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; });
Expand Down
11 changes: 8 additions & 3 deletions src/internal/CsvParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};
14 changes: 7 additions & 7 deletions tests/files/scenario_after_version_4_5_0.csv
Original file line number Diff line number Diff line change
@@ -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"
12 changes: 7 additions & 5 deletions tests/files/scenario_multiline.csv
Original file line number Diff line number Diff line change
@@ -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"
16 changes: 9 additions & 7 deletions tests/files/scenario_multilocation.csv
Original file line number Diff line number Diff line change
@@ -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"
12 changes: 7 additions & 5 deletions tests/files/scenario_simple.csv
Original file line number Diff line number Diff line change
@@ -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"
17 changes: 10 additions & 7 deletions tests/files/scenario_simple.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1">
<TS version="2.1" language="it" sourcelanguage="en">
<context>
<name>MenuBar</name>
<message>
<location filename="../src/app/qml/MenuBar.qml" line="17"/>
<source>text</source>
<translation></translation>
<comment>my comment</comment>
<translation type="unfinished"></translation>
</message>
<message>
<message id="1abc">
<location filename="../src/app/qml/MenuBar.qml" line="28"/>
<source>map</source>
<translation></translation>
<extracomment>extra comment test</extracomment>
<translatorcomment>translatorcomment</translatorcomment>
<translation type="vanished">whatever</translation>
</message>
<message>
<location filename="../src/app/qml/MenuBar.qml" line="43"/>
<source>cam</source>
<translation></translation>
<translation type="obsolete">whichever</translation>
</message>
<message>
<location filename="../src/app/qml/MenuBar.qml" line="58"/>
<source>checklist</source>
<translation></translation>
<translation>mytranslation</translation>
</message>
</context>
</TS>
Expand Down
2 changes: 1 addition & 1 deletion tests/tst_csv2ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion tests/tst_ts2csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/tst_ts2xlsx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(ret);
Expand Down

0 comments on commit a14fc34

Please sign in to comment.