diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-07-17 19:41:23 +0200 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2009-07-17 19:43:50 +0200 |
commit | 1185386dfe9727ed591da442e97084907f0a6735 (patch) | |
tree | df4a70d8132e4f2d3005160c68130a2c176e5636 /tools/linguist | |
parent | 74c0b4300b538b24c56abf2be2d5e09b9c59a845 (diff) | |
download | qt4-tools-1185386dfe9727ed591da442e97084907f0a6735.tar.gz |
don't rely on system codec when handling PO files
- make -input-codec affect PO files, default to UTF-8
- add -output-codec for PO files, same default
Diffstat (limited to 'tools/linguist')
-rw-r--r-- | tools/linguist/lconvert/main.cpp | 12 | ||||
-rw-r--r-- | tools/linguist/shared/po.cpp | 5 | ||||
-rw-r--r-- | tools/linguist/shared/qm.cpp | 3 | ||||
-rw-r--r-- | tools/linguist/shared/translator.h | 3 |
4 files changed, 16 insertions, 7 deletions
diff --git a/tools/linguist/lconvert/main.cpp b/tools/linguist/lconvert/main.cpp index 553ce6e635..fe8d529054 100644 --- a/tools/linguist/lconvert/main.cpp +++ b/tools/linguist/lconvert/main.cpp @@ -86,8 +86,11 @@ static int usage(const QStringList &args) " --output-format <outformat>\n" " Specify output format. See -if.\n\n" " --input-codec <codec>\n" - " Specify encoding for .qm input files. Default is 'Latin1'.\n" - " UTF-8 is always tried as well, corresponding to the trUtf8() function.\n\n" + " Specify encoding for .qm and .po input files. Default is 'Latin1'\n" + " for .qm and 'UTF-8' for .po files. UTF-8 is always tried as well for\n" + " .qm, corresponding to the possible use of the trUtf8() function.\n\n" + " --output-codec <codec>\n" + " Specify encoding for .po output files. Default is 'UTF-8'.\n\n" " --drop-tags <regexp>\n" " Drop named extra tags when writing 'ts' or 'xlf' files.\n" " May be specified repeatedly.\n\n" @@ -139,7 +142,6 @@ int main(int argc, char *argv[]) bool verbose = false; ConversionData cd; - cd.m_codecForSource = "Latin1"; Translator tr; for (int i = 1; i < args.size(); ++i) { @@ -172,6 +174,10 @@ int main(int argc, char *argv[]) if (++i >= args.size()) return usage(args); cd.m_codecForSource = args[i].toLatin1(); + } else if (args[i] == QLatin1String("-output-codec")) { + if (++i >= args.size()) + return usage(args); + cd.m_outputCodec = args[i].toLatin1(); } else if (args[i] == QLatin1String("-drop-tag")) { if (++i >= args.size()) return usage(args); diff --git a/tools/linguist/shared/po.cpp b/tools/linguist/shared/po.cpp index a197b25896..4850cfdeeb 100644 --- a/tools/linguist/shared/po.cpp +++ b/tools/linguist/shared/po.cpp @@ -359,6 +359,7 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd) const QChar quote = QLatin1Char('"'); const QChar newline = QLatin1Char('\n'); QTextStream in(&dev); + in.setCodec(cd.m_codecForSource.isEmpty() ? "UTF-8" : cd.m_codecForSource); bool error = false; // format of a .po file entry: @@ -547,11 +548,11 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd) return !error && cd.errors().isEmpty(); } -bool savePO(const Translator &translator, QIODevice &dev, ConversionData &) +bool savePO(const Translator &translator, QIODevice &dev, ConversionData &cd) { bool ok = true; QTextStream out(&dev); - //qDebug() << "OUT CODEC: " << out.codec()->name(); + out.setCodec(cd.m_outputCodec.isEmpty() ? "UTF-8" : cd.m_outputCodec); bool first = true; if (translator.messages().isEmpty() || !translator.messages().first().sourceText().isEmpty()) { diff --git a/tools/linguist/shared/qm.cpp b/tools/linguist/shared/qm.cpp index 323bd29e8f..381f5c5df2 100644 --- a/tools/linguist/shared/qm.cpp +++ b/tools/linguist/shared/qm.cpp @@ -545,7 +545,8 @@ bool loadQM(Translator &translator, QIODevice &dev, ConversionData &cd) size_t numItems = offsetLength / (2 * sizeof(quint32)); //qDebug() << "NUMITEMS: " << numItems; - QTextCodec *codec = QTextCodec::codecForName(cd.m_codecForSource); + QTextCodec *codec = QTextCodec::codecForName( + cd.m_codecForSource.isEmpty() ? "Latin1" : cd.m_codecForSource); QTextCodec *utf8Codec = 0; if (codec->name() != "UTF-8") utf8Codec = QTextCodec::codecForName("UTF-8"); diff --git a/tools/linguist/shared/translator.h b/tools/linguist/shared/translator.h index 01778d7899..762a77baf3 100644 --- a/tools/linguist/shared/translator.h +++ b/tools/linguist/shared/translator.h @@ -81,7 +81,8 @@ public: public: QString m_defaultContext; - QByteArray m_codecForSource; // CPP specific + QByteArray m_codecForSource; // CPP, PO & QM specific + QByteArray m_outputCodec; // PO specific QString m_sourceFileName; QString m_targetFileName; QDir m_sourceDir; |