21 #include <QCoreApplication>
29 #include <QStringList>
30 #include <QTextStream>
33 class LangListType:
public QList<QPair<QString,QString> >
38 for (
int i = 0; i <
size(); ++i ) {
39 if (
at( i ).first == el )
47 const LangListType &langMap ) {
49 QFile outFile( fname );
50 if ( ! outFile.
open( QIODevice::WriteOnly ) ) {
51 qCritical() <<
QString(
"Could not write %1" )
57 outStream <<
"<?xml version='1.0'?>" << endl;
58 outStream <<
QString(
"<!DOCTYPE l:i18n SYSTEM \"%1\" [" )
59 .
arg( dtdPath ) << endl;
61 LangListType::const_iterator i = langMap.constBegin();
62 while ( i != langMap.constEnd() ) {
64 outStream <<
QString(
"<!ENTITY %1 SYSTEM \"%2\">" )
65 .
arg( (*i).first ).
arg( (*i).second ) << endl;
68 outStream <<
"]>" << endl;
70 if ( langMap.size() > 0 ) {
72 <<
"<l:i18n xmlns:l=\"http://docbook.sourceforge.net/xmlns/l10n/1.0\">"
74 i = langMap.constBegin();
75 while ( i != langMap.constEnd() ) {
77 .
arg( (*i).first ) << endl;
80 outStream <<
"</l:i18n>" << endl;
89 const LangListType &langMap ) {
91 QFile outFile( fname );
92 if ( ! outFile.
open( QIODevice::WriteOnly ) ) {
93 qCritical() <<
QString(
"Could not write %1" )
99 outStream <<
"<?xml version='1.0'?>" << endl;
100 outStream <<
QString(
"<!DOCTYPE l:i18n SYSTEM \"%1\">" )
101 .
arg( dtdPath ) << endl;
103 if ( langMap.size() > 0 ) {
105 <<
"<l:i18n xmlns:l=\"http://docbook.sourceforge.net/xmlns/l10n/1.0\">"
107 LangListType::const_iterator i = langMap.constBegin();
108 while ( i != langMap.constEnd() ) {
109 outStream <<
QString(
"<l:l10n language=\"%1\" href=\"%2\"/>" )
110 .
arg( (*i).first ).
arg( (*i).second ) << endl;
113 outStream <<
"</l:i18n>" << endl;
122 return p.
endsWith(
"/" ) ? p : p +
"/";
125 int main(
int argc,
char **argv ) {
129 if ( arguments.
count() != 4 ) {
130 qCritical() <<
"wrong argument count";
138 QFile i18nFile( l10nDir +
"common/l10n.xml" );
140 if ( ! i18nFile.
open( QIODevice::ReadOnly ) ) {
141 qCritical() << i18nFile.
fileName() <<
" not found";
145 const QString all10nFName = destDir +
"all-l10n.xml";
146 const QString customl10nFName = destDir +
"kde-custom-l10n.xml";
152 QRegExp rxEntity, rxEntity2, rxDocType, rxDocType2;
153 rxDocType.
setPattern(
"^\\s*<!DOCTYPE\\s+l:i18n\\s+SYSTEM\\s+\"l10n\\.dtd\"\\s+\\[\\s*$");
154 rxDocType2.
setPattern(
"^\\s*<!DOCTYPE\\s+l:i18n\\s+SYSTEM\\s+\"l10n\\.dtd\"\\s*>$");
155 rxEntity.
setPattern(
"^\\s*<!ENTITY\\s+([^\\s]+)\\s+SYSTEM\\s+\"([^\\s]+)\">\\s*$");
156 rxEntity2.
setPattern(
"^\\s*<l:l10n language=\"([^\\s]+)\"\\s+href=\"([^\\s]+)\"/>\\s*$");
158 int parsingState = 0;
160 LangListType allLangs, customLangs;
162 bool foundRxEntity =
false;
163 bool foundRxEntity2 =
false;
164 while ( ! inStream.
atEnd() ) {
167 switch ( parsingState ) {
169 if ( rxDocType.
indexIn( line ) != -1 ) {
172 }
else if ( rxDocType2.
indexIn( line ) != -1 ) {
179 if ( rxEntity.
indexIn( line ) != -1 && !foundRxEntity2 ) {
180 foundRxEntity =
true;
181 langCode = rxEntity.
cap( 1 );
182 langFile = l10nDir +
"common/" + rxEntity.
cap( 2 );
183 allLangs += qMakePair( langCode, langFile );
185 }
else if ( rxEntity2.
indexIn( line ) != -1 && !foundRxEntity ) {
186 foundRxEntity2 =
true;
187 langCode = rxEntity2.
cap( 1 );
188 langFile = l10nDir +
"common/" + rxEntity2.
cap( 2 );
189 allLangs += qMakePair( langCode, langFile );
199 QDir outDir( l10nCustomDir );
202 dirFileFilters <<
"*.xml";
204 QDir::Files|QDir::NoSymLinks, QDir::Name );
209 customLangFiles.
removeOne(
"all-l10n.xml" );
210 customLangFiles.
removeOne(
"kde-custom-l10n.xml" );
219 while ( i != customLangFiles.
constEnd() ) {
225 if ( ( allLangs.searchLang( langCode ) ) > 0 ) {
237 if ( foundRxEntity ) {
239 res =
writeLangFile( all10nFName, l10nDir +
"common/l10n.dtd",
QString cap(int nth) const
QString readLine(qint64 maxlen)
int writeLangFileNew(const QString &fname, const QString &dtdPath, const LangListType &langMap)
const T & at(int i) const
void setPattern(const QString &pattern)
int indexIn(const QString &str, int offset, CaretMode caretMode) const
int count(const T &value) const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
int writeLangFile(const QString &fname, const QString &dtdPath, const LangListType &langMap)
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QStringList entryList(QFlags< QDir::Filter > filters, QFlags< QDir::SortFlag > sort) const
QString left(int n) const
const QString addTrailingSlash(const QString &p)
int main(int argc, char **argv)
const_iterator constEnd() const
const_iterator constBegin() const
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
bool removeOne(const T &value)