Merge PR #192: Autogenerate the ts file
This commit is contained in:
commit
39fa425e42
@ -63,8 +63,9 @@ QMAKE_EXTRA_TARGETS += clean plugininfo_clean
|
||||
# Install translation files
|
||||
TRANSLATIONS *= $$files($${_PRO_FILE_PWD_}/translations/*ts, true)
|
||||
lupdate.depends = FORCE
|
||||
lupdate.depends += plugininfo
|
||||
lupdate.commands = lupdate -recursive -no-obsolete $${_PRO_FILE_PWD_}/"$$TARGET".pro;
|
||||
lupdate.depends += qmake_all
|
||||
lupdate.commands = nymea-plugininfocompiler $${JSONFILE} --translation $${_PRO_FILE_PWD_}/translations/; \
|
||||
lupdate -recursive -no-obsolete $${_PRO_FILE_PWD_}/"$$TARGET".pro;
|
||||
QMAKE_EXTRA_TARGETS += lupdate
|
||||
|
||||
# make lrelease to build .qm from .ts
|
||||
|
||||
@ -36,6 +36,7 @@ int main(int argc, char *argv[])
|
||||
parser.addHelpOption();
|
||||
parser.addOption({{"o", "output"}, "Write generated output header to <file>.", "file"});
|
||||
parser.addOption({{"e", "extern"}, "Write generated output header (extern definitions) to <file>.", "file"});
|
||||
parser.addOption({{"t", "translations"}, "Write generated output header (extern definitions) to <directory>.", "directory"});
|
||||
parser.addPositionalArgument("input", "The input json file");
|
||||
|
||||
parser.process(a);
|
||||
@ -47,7 +48,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
PluginInfoCompiler pic;
|
||||
|
||||
int ret = pic.compile(parser.positionalArguments().first(), parser.value("output"), parser.value("extern"));
|
||||
int ret = pic.compile(parser.positionalArguments().first(), parser.value("output"), parser.value("extern"), parser.value("translations"));
|
||||
|
||||
return ret;
|
||||
|
||||
|
||||
@ -27,13 +27,14 @@
|
||||
#include <QJsonParseError>
|
||||
#include <QDataStream>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
|
||||
PluginInfoCompiler::PluginInfoCompiler()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int PluginInfoCompiler::compile(const QString &inputFile, const QString &outputFile, const QString outputFileExtern)
|
||||
int PluginInfoCompiler::compile(const QString &inputFile, const QString &outputFile, const QString outputFileExtern, const QString &translationsPath)
|
||||
{
|
||||
// First, process the input json...
|
||||
QFile jsonFile(inputFile);
|
||||
@ -90,6 +91,33 @@ int PluginInfoCompiler::compile(const QString &inputFile, const QString &outputF
|
||||
}
|
||||
}
|
||||
|
||||
if (!translationsPath.isEmpty()) {
|
||||
QDir dir;
|
||||
if (!dir.exists(translationsPath)) {
|
||||
if(!dir.mkpath(translationsPath)) {
|
||||
qWarning() << "Error creating translation file directory" << translationsPath;
|
||||
return 1;
|
||||
}
|
||||
qDebug() << "Created translations dir";
|
||||
}
|
||||
|
||||
QFile f(translationsPath + '/' + metadata.pluginId().toString().remove(QRegExp("[{}]")) + "-en_US.ts");
|
||||
QByteArray translationsStub = "<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE TS><TS version=\"2.1\"></TS>";
|
||||
if (!f.exists()) {
|
||||
if (!f.open(QFile::WriteOnly | QFile::Text)) {
|
||||
qWarning() << "Error creating translation file";
|
||||
return 1;
|
||||
}
|
||||
if (f.write(translationsStub) == -1) {
|
||||
qWarning() << "Error writing translation file";
|
||||
return 1;
|
||||
}
|
||||
f.close();
|
||||
qDebug() << "Created translations stub";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Files are open. Ready to write content.
|
||||
|
||||
QString header;
|
||||
|
||||
@ -34,7 +34,7 @@ class PluginInfoCompiler
|
||||
public:
|
||||
PluginInfoCompiler();
|
||||
|
||||
int compile(const QString &inputFile, const QString &outputFile, const QString outputFileExtern);
|
||||
int compile(const QString &inputFile, const QString &outputFile, const QString outputFileExtern, const QString &translationsPath);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user