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" )
52 .arg( outFile.fileName() );
56 QTextStream outStream( &outFile );
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" )
94 .arg( outFile.fileName() );
98 QTextStream outStream( &outFile );
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 ) {
126 QCoreApplication app( argc, 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*$");
157 QTextStream inStream( &i18nFile );
158 int parsingState = 0;
160 LangListType allLangs, customLangs;
162 bool foundRxEntity =
false;
163 bool foundRxEntity2 =
false;
164 while ( ! inStream.atEnd() ) {
165 QString line = inStream.readLine();
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";
203 QStringList customLangFiles = outDir.entryList( dirFileFilters,
204 QDir::Files|QDir::NoSymLinks, QDir::Name );
209 customLangFiles.removeOne(
"all-l10n.xml" );
210 customLangFiles.removeOne(
"kde-custom-l10n.xml" );
218 QStringList::const_iterator i = customLangFiles.constBegin();
219 while ( i != customLangFiles.constEnd() ) {
222 QString langCode = langFile.left( langFile.length() - 4 );
225 if ( ( allLangs.searchLang( langCode ) ) > 0 ) {
237 if ( foundRxEntity ) {
239 res =
writeLangFile( all10nFName, l10nDir +
"common/l10n.dtd",
int writeLangFileNew(const QString &fname, const QString &dtdPath, const LangListType &langMap)
int writeLangFile(const QString &fname, const QString &dtdPath, const LangListType &langMap)
const QString addTrailingSlash(const QString &p)
int main(int argc, char **argv)