summaryrefslogtreecommitdiffstats
path: root/kbabel/filters/linguist
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitbd9e6617827818fd043452c08c606f07b78014a0 (patch)
tree425bb4c3168f9c02f10150f235d2cb998dcc6108 /kbabel/filters/linguist
downloadtdesdk-bd9e6617827818fd043452c08c606f07b78014a0.tar.gz
tdesdk-bd9e6617827818fd043452c08c606f07b78014a0.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdesdk@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kbabel/filters/linguist')
-rw-r--r--kbabel/filters/linguist/Makefile.am18
-rw-r--r--kbabel/filters/linguist/kbabel_linguist_export.desktop53
-rw-r--r--kbabel/filters/linguist/kbabel_linguist_import.desktop53
-rw-r--r--kbabel/filters/linguist/linguistexport.cpp214
-rw-r--r--kbabel/filters/linguist/linguistexport.h68
-rw-r--r--kbabel/filters/linguist/linguistimport.cpp193
-rw-r--r--kbabel/filters/linguist/linguistimport.h68
7 files changed, 667 insertions, 0 deletions
diff --git a/kbabel/filters/linguist/Makefile.am b/kbabel/filters/linguist/Makefile.am
new file mode 100644
index 00000000..479c8052
--- /dev/null
+++ b/kbabel/filters/linguist/Makefile.am
@@ -0,0 +1,18 @@
+####### General stuff
+
+INCLUDES = -I../../common -I$(srcdir)/../../common $(all_includes)
+
+kde_module_LTLIBRARIES = kbabel_linguistexport.la kbabel_linguistimport.la
+
+kbabel_linguistexport_la_SOURCES = linguistexport.cpp
+kbabel_linguistexport_la_LIBADD = ../../common/libkbabelcommon.la
+kbabel_linguistexport_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
+
+kbabel_linguistimport_la_SOURCES = linguistimport.cpp
+kbabel_linguistimport_la_LIBADD = ../../common/libkbabelcommon.la
+kbabel_linguistimport_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries)
+
+METASOURCES = AUTO
+
+service_DATA = kbabel_linguist_export.desktop kbabel_linguist_import.desktop
+servicedir = $(kde_servicesdir)
diff --git a/kbabel/filters/linguist/kbabel_linguist_export.desktop b/kbabel/filters/linguist/kbabel_linguist_export.desktop
new file mode 100644
index 00000000..400abd26
--- /dev/null
+++ b/kbabel/filters/linguist/kbabel_linguist_export.desktop
@@ -0,0 +1,53 @@
+[Desktop Entry]
+Type=Service
+Name=KBabel Linguist Export Filter
+Name[bg]=Лингвистичен филтър за експортиране - KBabel
+Name[br]=Sil ezporzh Linguist evit KBabel
+Name[bs]=KBabel Linguist filter za izvoz
+Name[ca]=Filtre KBabel per exportar Linguist
+Name[cs]=Exportní filtr do formátu Linguist pro KBabel
+Name[cy]=Hidl Allforio Ieithydd KBabel
+Name[da]=KBabel Linguist eksportfilter
+Name[de]=Linguist Export-Filter für KBabel
+Name[el]=Φίλτρο εξαγωγής Linguist του KBabel
+Name[es]=Filtro de exportación lingüístico de KBabel
+Name[et]=KBabeli Linguisti ekspordifilter
+Name[eu]=KBabel Linguist esportazio iragazkia
+Name[fa]=پالایۀ صادرات زبان‌شناس KBabel
+Name[fi]=KBabel Linguist -vientisuodatin
+Name[fr]=Filtre d'exportation Linguist pour KBabel
+Name[ga]=Scagaire Easpórtála Linguist le haghaidh KBabel
+Name[gl]=Filtro de exportación a Linguist para KBabel
+Name[hi]=के-बेबल लिंग्विस्ट निर्यात फ़िल्टर
+Name[hu]=KBabel Linguist exportszűrő
+Name[is]=KBabel Linguist útflutningssía
+Name[it]=Filtro di esportazione di Linguist per KBabel
+Name[ja]=KBabel Linguist エクスポートフィルタ
+Name[ka]=KBabel Linguist ექსპორტის ფილტრი
+Name[kk]=KBabel лингвистік экспорттау сүзгісі
+Name[lt]=KBabel Linguist eksportavimo filtras
+Name[ms]=Penapis Eksport KBabel Linguist
+Name[nb]=Linguist-eksportfilter for KBabel
+Name[nds]=KBabel-Exportfilter för Linguist
+Name[ne]=केब्याबल बहुभाषी निर्यात फिल्टर
+Name[nl]=KBabel Linguïst Exportfilter
+Name[nn]=Linguist-eksportfilter for KBabel
+Name[pa]=ਕੇਬਬੇਲ ਬੋਲੀ ਨਿਰਯਾਤ ਫਿਲਟਰ
+Name[pl]=Filtr KBabel do eksportu do formatu Linguist
+Name[pt]=Filtro de Exportação para Linguist para o KBabel
+Name[pt_BR]=Filtro de Exportação Linguist do KBabel
+Name[ru]=Фильтр экспорта лингвистических сообщений
+Name[sk]=Exportný filter Qt Linguist pre KBabel
+Name[sl]=Izvozni filter Linguist za KBabel
+Name[sr]=KBabel-ов филтер за извоз у Linguist
+Name[sr@Latn]=KBabel-ov filter za izvoz u Linguist
+Name[sv]=Kbabel exportfilter för Linguist
+Name[ta]=Kபாபேல் மொழியியல் ஏற்றுமதி வடிகட்டி
+Name[tg]=Филтри содироти хабарҳои лингвистӣ
+Name[tr]=KBabel Linguist Dışa Aktarma Süzgeci
+Name[uk]=Фільтр експорту Linguist для KBabel
+Name[zh_CN]=KBabel Linguist 导出过滤器
+Name[zh_TW]=KBabel 語言匯出過濾器
+X-KDE-Library=kbabel_linguistexport
+X-KDE-Export=application/x-linguist
+ServiceTypes=KBabelFilter
diff --git a/kbabel/filters/linguist/kbabel_linguist_import.desktop b/kbabel/filters/linguist/kbabel_linguist_import.desktop
new file mode 100644
index 00000000..ae8bd364
--- /dev/null
+++ b/kbabel/filters/linguist/kbabel_linguist_import.desktop
@@ -0,0 +1,53 @@
+[Desktop Entry]
+Type=Service
+Name=KBabel Linguist Import Filter
+Name[bg]=Лингвистичен филтър за импортиране - KBabel
+Name[br]=Sil enporzh Linguist evit KBabel
+Name[bs]=KBabel Linguist filter za izvoz
+Name[ca]=Filtre KBabel per importar Linguist
+Name[cs]=Importní filtr Linguist pro KBabel
+Name[cy]=Hidl Mewnforio Ieithydd KBabel
+Name[da]=KBabel Linguist importfilter
+Name[de]=Linguist Import-Filter für KBabel
+Name[el]=Φίλτρο εισαγωγής Linguist του KBabel
+Name[es]=Filtro de importación de lengua KBabel
+Name[et]=KBabeli Linguisti impordifilter
+Name[eu]=KBabel Linguist esportazio iragazkia
+Name[fa]=پالایۀ واردات زبان‌شناس KBabel
+Name[fi]=KBabel Linguist -tuontisuodatin
+Name[fr]=Filtre d'importation Linguist pour KBabel
+Name[ga]=Scagaire Iompórtála Linguist le haghaidh KBabel
+Name[gl]=Filtro de importación de Linguist para KBabel
+Name[hi]=के-बेबल लिंग्विस्ट आयात फ़िल्टर
+Name[hu]=KBabel Linguist importszűrő
+Name[is]=KBabel Linguist innflutningssía
+Name[it]=Filtro di importazione di Linguist per KBabel
+Name[ja]=KBabel Linguist インポートフィルタ
+Name[ka]=KBabel Linguist იმპორის ფილტრი
+Name[kk]=KBabel лингвистік импорттау сүзгісі
+Name[lt]=KBabel Linguist importavimo filtras
+Name[ms]=Penapis Import KBabel Linguist
+Name[nb]=Linguist-importfilter for KBabel
+Name[nds]=KBabel-Importfilter för Linguist
+Name[ne]=केब्याबल बहुभाषी आयात फिल्टर
+Name[nl]=KBabel Linguïst importfilter
+Name[nn]=Linguist-importfilter for KBabel
+Name[pa]=ਕੇਬਬੇਲ ਬੋਲੀ ਅਯਾਤ ਫਿਲਟਰ
+Name[pl]=Filtr KBabel do importu z formatu Linguist
+Name[pt]=Filtro de Importação de Linguist para o KBabel
+Name[pt_BR]=Filtro de Importação Linguist para o KBabel
+Name[ru]=Фильтр импорта лингвистических сообщений
+Name[sk]=Importný filter Qt Linguist pre KBabel
+Name[sl]=Uvozni filter Linguist za KBabel
+Name[sr]=KBabel-ов филтер за увоз из Linguist-а
+Name[sr@Latn]=KBabel-ov filter za uvoz iz Linguist-a
+Name[sv]=Kbabel importfilter för Linguist
+Name[ta]=Kபாபேல் மொழியியல் இறக்குமதி வடிகட்டி
+Name[tg]=Филтри воридоти хабарҳои лингвистӣ
+Name[tr]=KBabel Linguist İçe Aktarma Süzgeci
+Name[uk]=Фільтр імпорту Linguist для KBabel
+Name[zh_CN]=KBabel Linguist 导入过滤器
+Name[zh_TW]=KBabel 語言匯入過濾器
+X-KDE-Library=kbabel_linguistimport
+X-KDE-Import=application/x-linguist
+ServiceTypes=KBabelFilter
diff --git a/kbabel/filters/linguist/linguistexport.cpp b/kbabel/filters/linguist/linguistexport.cpp
new file mode 100644
index 00000000..3b69e20a
--- /dev/null
+++ b/kbabel/filters/linguist/linguistexport.cpp
@@ -0,0 +1,214 @@
+/* ****************************************************************************
+ This file is part of KBabel
+
+ Copyright (C) 1999-2000 by Matthias Kiefer
+ <matthias.kiefer@gmx.de>
+ 2001-2002 by Stanislav Visnovsky
+ <visnovsky@kde.org>
+ 2002-2003 by Marco Wegner
+ <mail@marcowegner.de>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+
+**************************************************************************** */
+
+
+#include <qfile.h>
+#include "qregexp.h"
+#include <qstring.h>
+#include <qstringlist.h>
+#include <qtextstream.h>
+
+#include <kgenericfactory.h>
+
+#include "catalog.h"
+#include "catalogitem.h"
+#include "catalogsettings.h"
+#include "linguistexport.h"
+
+K_EXPORT_COMPONENT_FACTORY( kbabel_linguistexport, KGenericFactory<LinguistExportPlugin> ( "kbabellinguistexportfilter" ) )
+
+using namespace KBabel;
+
+LinguistExportPlugin::LinguistExportPlugin( QObject * parent, const char * name, const QStringList& )
+ : CatalogExportPlugin( parent, name )
+{
+}
+
+ConversionStatus LinguistExportPlugin::save( const QString& filename, const QString&, const Catalog * catalog )
+{
+ // Check whether we know how to handle the extra data.
+ if ( catalog->importPluginID( ) != "Qt translation source" )
+ return UNSUPPORTED_TYPE;
+
+ QFile file( filename );
+ if ( !file.open( IO_WriteOnly ) )
+ return OS_ERROR;
+
+ SaveSettings settings = catalog->saveSettings( );
+
+ // New DOM document.
+ QDomDocument doc( "TS" );
+ // Create the root element.
+ doc.appendChild( doc.createElement( "TS" ) );
+
+ // Create a default context just in case none is given in the messages.
+ context = "Default"; // ### FIXME: Qt's default seems named "@default"
+
+ bool fuzzy;
+
+ // Regular messages.
+ for ( uint i = 0; i < catalog->numberOfEntries( ); i++ ) {
+ QString comment( extractComment( doc, catalog->comment( i ), fuzzy ) );
+ createMessage( doc, catalog->msgid( i ).join( "" ), catalog->msgstr( i ).join( "" ),
+ comment, false, fuzzy );
+ }
+
+ // Obsolete messages.
+ if ( settings.saveObsolete ) {
+ QValueList<CatalogItem> obsMessages = catalog->obsoleteEntries( );
+ QValueList<CatalogItem>::Iterator it;
+ for ( it = obsMessages.begin( ); it != obsMessages.end( ); ++it ) {
+ QString comment( extractComment( doc, (*it).comment( ), fuzzy ) );
+ createMessage( doc, (*it).msgid( true ).join( "" ), (*it).msgstr( true ).join( "" ),
+ comment, true, fuzzy );
+ }
+ }
+
+ QTextStream stream( &file );
+ doc.save( stream, 2 );
+ file.close( );
+
+ return OK;
+}
+
+const QString LinguistExportPlugin::extractComment( QDomDocument& doc, const QString& s, bool& fuzzy )
+{
+ fuzzy = false;
+ QString comment( s );
+ if ( !comment.isEmpty( ) ) {
+ // Extract the context and the actual comment.
+ comment.remove( QRegExp( "^Context:[\\s]*" ) );
+ /*
+ * HACK
+ *
+ * KBabel has not any flag to tell "this entry is fuzzy!"
+ * but it uses the corresponding Gettext comment instead.
+ *
+ * Therefore we have little choice, but to use "#, fuzzy" in the comment,
+ * even if it is very Linguist-unlike. So the "#, fuzzy" must be removed before
+ * writing the comment for Linguist
+ */
+
+ int pos = comment.find("#, fuzzy");
+ if ( pos >= 0) {
+ fuzzy = true;
+ comment.remove("#, fuzzy");
+ }
+
+ QString newContext;
+ pos = comment.find( '\n' );
+ if ( pos >= 0 ) {
+ newContext = comment.left( pos );
+ comment.replace( 0, pos + 1, "" ); // ### TODO: use QString::remove
+ } else {
+ newContext = comment;
+ comment = ""; // ### TODO: use QString() instead of ""
+ }
+ setContext( doc, newContext );
+ }
+ return comment;
+}
+
+void LinguistExportPlugin::createMessage( QDomDocument& doc, const QString& msgid,
+ const QString& msgstr, const QString& comment,
+ const bool obsolete, const bool fuzzy )
+{
+ QDomElement elem;
+ QDomText text;
+
+ QDomElement messageElement = doc.createElement( "message" );
+
+ elem = doc.createElement( "source" );
+ text = doc.createTextNode( msgid );
+ elem.appendChild( text );
+ messageElement.appendChild( elem );
+
+ if ( !comment.isEmpty( ) ) {
+ elem = doc.createElement( "comment" );
+ text = doc.createTextNode( comment );
+ elem.appendChild( text );
+ messageElement.appendChild( elem );
+ }
+
+ elem = doc.createElement( "translation" );
+ if ( obsolete )
+ elem.setAttribute( "type", "obsolete" );
+ else if ( msgstr.isEmpty( ) || fuzzy ) {
+ elem.setAttribute( "type", "unfinished" );
+ }
+ if ( !msgstr.isEmpty())
+ {
+ text = doc.createTextNode( msgstr );
+ elem.appendChild( text );
+ }
+ messageElement.appendChild( elem );
+ contextElement.appendChild( messageElement );
+}
+
+void LinguistExportPlugin::setContext( QDomDocument& doc, QString newContext )
+{
+ // Nothing to do here.
+ if ( newContext == context )
+ return;
+
+ // Find out whether there is already such a context in the QDomDocument.
+ QDomNode node = doc.documentElement( ).firstChild( );
+ while ( !node.isNull( ) ) {
+ if ( node.isElement( ) ) {
+ QDomElement elem = node.firstChild( ).toElement( );
+ if ( elem.isElement( ) && elem.tagName( ) == "name" && elem.text( ) == newContext ) {
+ // We found the context.
+ context = newContext;
+ contextElement = node.toElement( );
+ // Nothing more to do.
+ return;
+ }
+ }
+ node = node.nextSibling( );
+ }
+
+ // Create new context element.
+ contextElement = doc.createElement( "context" );
+ doc.documentElement( ).appendChild( contextElement );
+ // Appropriate name element.
+ QDomElement nameElement = doc.createElement( "name" );
+ QDomText text = doc.createTextNode( newContext );
+ nameElement.appendChild( text );
+ contextElement.appendChild( nameElement );
+ // Store new context.
+ context = newContext;
+}
diff --git a/kbabel/filters/linguist/linguistexport.h b/kbabel/filters/linguist/linguistexport.h
new file mode 100644
index 00000000..3201f95f
--- /dev/null
+++ b/kbabel/filters/linguist/linguistexport.h
@@ -0,0 +1,68 @@
+/* ****************************************************************************
+ This file is part of KBabel
+
+ Copyright (C) 2002 by Stanislav Visnovsky
+ <visnovsky@kde.org>
+ 2002-2003 by Marco Wegner
+ <mail@marcowegner.de>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+
+**************************************************************************** */
+
+
+#ifndef LINGUISTEXPORT_H
+#define LINGUISTEXPORT_H
+
+#include <qdom.h>
+
+#include "catalogfileplugin.h"
+
+class QString;
+class QStringList;
+
+namespace KBabel {
+class Catalog;
+}
+
+class LinguistExportPlugin : public KBabel::CatalogExportPlugin
+{
+ public:
+ LinguistExportPlugin( QObject * parent, const char * name, const QStringList& );
+ virtual KBabel::ConversionStatus save( const QString& filename, const QString& mimetype, const KBabel::Catalog * catalog );
+
+ private:
+ const QString extractComment( QDomDocument& doc, const QString& s, bool& fuzzy );
+ void createMessage( QDomDocument& doc, const QString& msgid, const QString& msgstr,
+ const QString& comment, const bool obsolete, const bool fuzzy );
+ void setContext( QDomDocument& doc, QString newContext );
+
+ private:
+ QString context;
+ QDomElement contextElement;
+};
+
+#endif // LINGUISTEXPORT_H
diff --git a/kbabel/filters/linguist/linguistimport.cpp b/kbabel/filters/linguist/linguistimport.cpp
new file mode 100644
index 00000000..220c0634
--- /dev/null
+++ b/kbabel/filters/linguist/linguistimport.cpp
@@ -0,0 +1,193 @@
+// kate: space-indent on; indent-width 2; replace-tabs on;
+
+/* ****************************************************************************
+ This file is part of KBabel
+
+ Copyright (C) 1999-2000 by Matthias Kiefer
+ <matthias.kiefer@gmx.de>
+ 2001-2002 by Stanislav Visnovsky
+ <visnovsky@kde.org>
+ 2002-2003 by Marco Wegner
+ <mail@marcowegner.de>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+
+**************************************************************************** */
+
+// Qt include files
+#include <qfile.h>
+#include <qfileinfo.h>
+#include <qobject.h>
+#include <qregexp.h>
+#include <qstring.h>
+#include <qstringlist.h>
+// KDE include files
+#include <kdebug.h>
+#include <kgenericfactory.h>
+// Project specific include files
+#include "catalogitem.h"
+#include "linguistimport.h"
+
+K_EXPORT_COMPONENT_FACTORY( kbabel_linguistimport, KGenericFactory<LinguistImportPlugin> ( "kbabellinguistimportfilter" ) )
+
+using namespace KBabel;
+
+LinguistImportPlugin::LinguistImportPlugin( QObject * parent, const char * name, const QStringList& )
+ : CatalogImportPlugin( parent, name )
+{
+}
+
+ConversionStatus LinguistImportPlugin::load( const QString& filename, const QString& )
+{
+ if ( filename.isEmpty( ) ) {
+ kdDebug( ) << "fatal error: empty filename to open" << endl;
+ return NO_FILE;
+ }
+
+ QFileInfo info( filename );
+
+ if ( !info.exists( ) || info.isDir( ) )
+ return NO_FILE;
+
+ if ( !info.isReadable( ) )
+ return NO_PERMISSIONS;
+
+ QFile file( filename );
+ if ( !file.open( IO_ReadOnly ) )
+ return NO_PERMISSIONS;
+
+ QString errorMsg;
+ int errorLine, errorColumn;
+
+ QDomDocument doc;
+ if ( !doc.setContent( &file, &errorMsg, &errorLine, &errorColumn ) ) {
+ file.close( );
+ kdError() << "Parsing error at line " << errorLine << ", column " << errorColumn << ", error " << errorMsg << endl;
+ return PARSE_ERROR;
+ }
+ file.close( );
+
+ const QDomElement documentElement( doc.documentElement() );
+ // Count the number of messages in this file. This is needed for updating
+ // the progress bar correctly.
+ msgcnt = documentElement.elementsByTagName( "message" ).count();
+
+ if ( documentElement.tagName() != "TS" )
+ return UNSUPPORTED_TYPE;
+
+ cnt = 0;
+ emit signalClearProgressBar( );
+ kdDebug( ) << "start parsing..." << endl;
+
+ parse( documentElement );
+ //setCatalogExtraData( obsMessages );
+
+ emit signalProgress( 100 );
+ kdDebug( ) << "finished parsing..." << endl;
+
+ setMimeTypes( "application/x-linguist" );
+
+ return OK;
+}
+
+void LinguistImportPlugin::parse( const QDomElement& parentElement )
+{
+ QDomNode node = parentElement.firstChild( );
+
+ while ( !node.isNull( ) ) {
+ if ( node.isElement( ) ) {
+ QDomElement elem = node.toElement( );
+
+ if ( elem.tagName( ) == "context" ) {
+ // nothing to do here
+ } else if ( elem.tagName( ) == "name" ) {
+ context = elem.text( );
+ } else if ( elem.tagName( ) == "message" ) {
+ CatalogItem item;
+ QString comment;
+ bool isObsolete = false;
+ bool isFuzzy = false;
+
+ QDomNode childNode = node.firstChild();
+ for ( ; ! childNode.isNull() ; childNode = childNode.nextSibling() )
+ {
+ const QDomElement elem = childNode.toElement();
+
+ if ( elem.isNull() )
+ continue;
+
+ if ( elem.tagName( ) == "source" ) {
+ item.setMsgid( elem.text( ) );
+ } else if ( elem.tagName( ) == "translation" ) {
+ item.setMsgstr( elem.text( ) );
+ if ( elem.attribute( "type" ) == "unfinished" ) {
+ // Only mark as fuzzy if there is a translation
+ isFuzzy = !elem.text().isEmpty();
+ } else if ( elem.attribute( "type" ) == "obsolete" ) {
+ isObsolete = true;
+ }
+ } else if ( elem.tagName( ) == "comment" ) {
+ if ( !elem.text( ).isEmpty( ) )
+ comment = elem.text( );
+ }
+ }
+
+ QString fullComment = "Context: " + context;
+ if ( isFuzzy )
+ {
+ /*
+ * HACK
+ *
+ * KBabel has not any flag to tell "this entry is fuzzy!"
+ * but it uses the corresponding Gettext comment instead.
+ *
+ * Therefore we have little choice, but to add "#, fuzzy" to the comment,
+ * even if it is very Linguist-unlike
+ */
+ fullComment += "\n";
+ fullComment += "#, fuzzy";
+ }
+ if ( !comment.isEmpty() )
+ {
+ fullComment += "\n";
+ fullComment += comment;
+ }
+ item.setComment( fullComment );
+
+ appendCatalogItem( item, isObsolete );
+
+ // Update the progress bar.
+ cnt++;
+ uint prog = 100*cnt/msgcnt;
+ emit signalProgress( prog );
+ }
+ // ### TODO: avoid recursing
+ // recursive parsing
+ parse( elem );
+ }
+ node = node.nextSibling( );
+ }
+}
diff --git a/kbabel/filters/linguist/linguistimport.h b/kbabel/filters/linguist/linguistimport.h
new file mode 100644
index 00000000..3cdbd7e3
--- /dev/null
+++ b/kbabel/filters/linguist/linguistimport.h
@@ -0,0 +1,68 @@
+/* ****************************************************************************
+ This file is part of KBabel
+
+ Copyright (C) 2002 by Stanislav Visnovsky
+ <visnovsky@kde.org>
+ 2002-2003 by Marco Wegner
+ <mail@marcowegner.de>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+
+**************************************************************************** */
+
+
+#ifndef LINGUISTIMPORT_H
+#define LINGUISTIMPORT_H
+
+#include <qdom.h>
+
+#include "catalogfileplugin.h"
+
+class QString;
+class QStringList;
+
+/**
+ * The class for importing Qt's translation source files.
+ */
+class LinguistImportPlugin : public KBabel::CatalogImportPlugin
+{
+ public:
+ LinguistImportPlugin( QObject * parent, const char * name, const QStringList& );
+
+ virtual KBabel::ConversionStatus load( const QString& filename, const QString& mimetype );
+ virtual const QString id( ) { return "Qt translation source"; }
+
+ private:
+ void parse( const QDomElement& parentElement );
+
+ private:
+ uint msgcnt;
+ uint cnt;
+ QString context;
+ //QStringList obsMessages;
+};
+
+#endif // LINGUISTIMPORT_H