forked from guerinoni/qTsConverter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Federico Guerinoni <[email protected]>
- Loading branch information
Showing
13 changed files
with
120 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "3rd-party/qtcsv"] | ||
path = 3rd-party/qtcsv | ||
url = https://github.com/iamantony/qtcsv.git | ||
[submodule "3rd-party/qtxlsx"] | ||
path = 3rd-party/qtxlsx | ||
url = https://github.com/VSRonin/QtXlsxWriter.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "Ts2XlsxConverter.hpp" | ||
|
||
#include "XlsxBuilder.hpp" | ||
|
||
Ts2XlsxConverter::Ts2XlsxConverter(const std::string &input, | ||
const std::string &output, | ||
const std::string &field_sep, | ||
const std::string &string_sep) : | ||
Converter{ input, output } | ||
{ | ||
m_builder = std::make_shared<XlsxBuilder>(); | ||
} | ||
|
||
void Ts2XlsxConverter::process() const | ||
{ | ||
if (m_inputFile.empty() || m_outputDir.empty()) { | ||
return; | ||
} | ||
|
||
auto trs = m_parser.parse(m_inputFile); | ||
m_builder->build(m_outputDir + "/output.xlsx", trs); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include "Converter.hpp" | ||
#include "TsParser.hpp" | ||
|
||
#include <memory> | ||
|
||
class XlsxBuilder; | ||
|
||
class Ts2XlsxConverter : public Converter | ||
{ | ||
public: | ||
explicit Ts2XlsxConverter(const std::string &input, | ||
const std::string &output, | ||
const std::string &field_sep, | ||
const std::string &string_sep); | ||
|
||
void process() const override; | ||
|
||
private: | ||
TsParser m_parser; | ||
std::shared_ptr<XlsxBuilder> m_builder; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "XlsxBuilder.hpp" | ||
|
||
#include <QFile> | ||
#include <QTextStream> | ||
#include <QtDebug> | ||
#include <xlsx/xlsxdocument.h> | ||
|
||
void XlsxBuilder::build(const std::string &output_filename, | ||
Translations trs) const | ||
{ | ||
QXlsx::Document xlsx; | ||
xlsx.write(1, 1, "Context"); | ||
xlsx.write(1, 2, "Source"); | ||
xlsx.write(1, 3, "Translation"); | ||
xlsx.write(1, 4, "Location"); | ||
|
||
int row{ 2 }; | ||
int col{ 1 }; | ||
for (const auto &tr : trs) { | ||
for (const auto &msg : tr.messages) { | ||
xlsx.write(row, col++, tr.name); | ||
xlsx.write(row, col++, msg.source); | ||
xlsx.write(row, col++, msg.translation); | ||
|
||
for (const auto &loc : msg.locations) { | ||
xlsx.write( | ||
row, col++, | ||
QString(loc.first + " - " + QString::number(loc.second))); | ||
} | ||
++row; | ||
col = 1; | ||
} | ||
} | ||
|
||
if (!xlsx.saveAs(output_filename.c_str())) { | ||
qWarning() << "error writing file"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include "TranslationObject.hpp" | ||
|
||
class XlsxBuilder | ||
{ | ||
public: | ||
void build(const std::string &output_filename, Translations trs) const; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters