From bd9e6617827818fd043452c08c606f07b78014a0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: 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 --- kbabel/datatools/regexp/Makefile.am | 21 ++ kbabel/datatools/regexp/kbabel_regexptool.desktop | 92 +++++++ kbabel/datatools/regexp/main.cc | 181 +++++++++++++ kbabel/datatools/regexp/main.h | 73 ++++++ kbabel/datatools/regexp/regexplist.xml | 303 ++++++++++++++++++++++ 5 files changed, 670 insertions(+) create mode 100644 kbabel/datatools/regexp/Makefile.am create mode 100644 kbabel/datatools/regexp/kbabel_regexptool.desktop create mode 100644 kbabel/datatools/regexp/main.cc create mode 100644 kbabel/datatools/regexp/main.h create mode 100644 kbabel/datatools/regexp/regexplist.xml (limited to 'kbabel/datatools/regexp') diff --git a/kbabel/datatools/regexp/Makefile.am b/kbabel/datatools/regexp/Makefile.am new file mode 100644 index 00000000..e727ca25 --- /dev/null +++ b/kbabel/datatools/regexp/Makefile.am @@ -0,0 +1,21 @@ + +INCLUDES = -I$(srcdir)/../../common -I../../common $(all_includes) +kbabel_regexptool_la_LIBADD = $(LIB_KIO) ../../common/libkbabelcommon.la + +####### Files + +kde_module_LTLIBRARIES = kbabel_regexptool.la + +kbabel_regexptool_la_SOURCES = main.cc + +kbabel_regexptool_la_LDFLAGS = $(all_libraries) -avoid-version -module -no-undefined + +noinst_HEADERS = main.h + +kbabel_regexptool_la_METASOURCES = AUTO + +service_DATA = kbabel_regexptool.desktop +servicedir = $(kde_servicesdir) + +regexp_DATA = regexplist.xml +regexpdir = $(kde_datadir)/kbabel diff --git a/kbabel/datatools/regexp/kbabel_regexptool.desktop b/kbabel/datatools/regexp/kbabel_regexptool.desktop new file mode 100644 index 00000000..dbd84491 --- /dev/null +++ b/kbabel/datatools/regexp/kbabel_regexptool.desktop @@ -0,0 +1,92 @@ +[Desktop Entry] +Name=Catalan Grammar +Name[br]=Yezhadur gatalaneg +Name[ca]=Gramàtica catalana +Name[cs]=Katalánská gramatika +Name[da]=Katalansk grammatik +Name[de]=Katalanische Grammatik +Name[el]=Γραμματική καταλανικών +Name[eo]=Kataluna Gramatiko +Name[es]=Gramática catalana +Name[et]=Katalaani grammatika +Name[eu]=Katalanaren gramatika +Name[fa]=دستور زبان کاتالان +Name[fi]=Katalaanin kielioppi +Name[fr]=Grammaire du catalan +Name[ga]=Gramadach na Catalóinise +Name[gl]=Gramática catalá +Name[he]=תחברי קטאלני +Name[hu]=Katalán nyelvtan +Name[is]=Katalónsk málfræði +Name[it]=Grammatica catalana +Name[ja]=カタロニア文節 +Name[ka]=კატალანური გრამატიკა +Name[kk]=Каталон грамматикасы +Name[lt]=Katalonų gramatika +Name[nb]=Katalansk grammatikk +Name[nds]=Katalaansch Grammatik +Name[ne]=क्याटालान ब्याकरण +Name[nl]=Catalaanse grammatica +Name[nn]=Katalansk grammatikk +Name[pa]=ਕਾਟਾਲਾਨ ਗਰਾਮਰ +Name[pl]=Gramatyka katalońska +Name[pt]=Gramática Catalã +Name[pt_BR]=Gramática Catalã +Name[ru]=Каталонская гамматика +Name[sk]=Katalánska gramatika +Name[sl]=katalonska slovnica +Name[sr]=Каталонијска граматика +Name[sr@Latn]=Katalonijska gramatika +Name[sv]=Katalansk grammatik +Name[tr]=Katalan Dil Bilgisi +Name[uk]=Каталонська граматика +Name[zh_CN]=Catalan 语法 +Name[zh_TW]=Catalan 文法 +ValidationString=external script checking +X-KDE-Library=kbabel_regexptool +Type=Service +Commands=validate +Comment=Check Translated Messages with a set of Regular Expressions +Comment[bg]=Проверка на преведените съобщения с регулярни изрази +Comment[ca]=Comprova els missatges traduïts amb un conjunt d'expressions regulars +Comment[cs]=Zkontrolovat přeložené zprávy pomocí sady reg. výrazů +Comment[da]=Tjek oversat besked med et sæt regulære udtryk +Comment[de]=Überprüfung übersetzter Meldungen mit einem Satz regulärer Ausdrücke +Comment[el]=Έλεγχος μεταφρασμένων μηνυμάτων με ένα σύνολο κανονικών εκφράσεων +Comment[eo]=Kontroli tradukitajn mesaĝojn per aro da regulesprimoj +Comment[es]=Comprobar mensajes traducidos mediante un juego de expresiones regulares +Comment[et]=Tõlgitud teate kontroll regulaaravaldistega +Comment[eu]=Egiaztatu itzulitako mezuak espresio erregular sorta batekin +Comment[fa]=بررسی پیامهای ترجمه‌شده توسط مجموعه‌ای از عبارتهای منظم +Comment[fi]=Tarkista käännetyt viestit säännöllisten lausekkeiden avulla +Comment[fr]=Vérifie les messages traduits avec un jeu d'expressions rationnelles +Comment[gl]=Verificación das mensaxes traducidas cun conxunto de expresións regulares +Comment[hu]=A lefordított üzenetek ellenőrzése reguláris kifejezésekkel +Comment[is]=Athuga þýdd skilaboð með reglulegum segðum +Comment[it]=Controlla i messaggi tradotti con un insieme di espressioni regolari +Comment[ja]=正規表現を用いて翻訳メッセージを検証 +Comment[ka]=რეგულარული გამოსახულებების შეცველი ნათარგმნი შეტყობინებების შემოწმება +Comment[kk]=Аударылған жазуларды үлгі өрнегімен тексеру +Comment[lt]=Tikrinti išverstus pranešimus panaudojant įprastųjų išraiškų rinkinį +Comment[nb]=Sjekk oversatte strenger med et sett regulære uttrykk +Comment[nds]=Översett Mellen mit en Sett vun regulere Utdrück pröven +Comment[ne]=नियमित अभिव्यक्तिका सेट भएका अनुबाद गरिएका सन्देशको जाँच गर्नुहोस् +Comment[nl]=Vertaalde tekst controleren met behulp van reguliere expressies +Comment[nn]=Sjekk omsette strengar med eit sett regulære uttrykk +Comment[pl]=Sprawdzenie przetłumaczonych komunikatów za pomocą zestawu wyrażeń regularnych +Comment[pt]=Verificação das Mensagens Traduzidas com um Conjunto de Expressões Regulares +Comment[pt_BR]=Verificação das Mensagens Traduzidas com um Conjunto de Expressões Regulares +Comment[ru]=Проверить переведенных сообщения по регулярному выражению +Comment[sk]=Kontrola preložených textov pomocou sady regulárnych výrazov +Comment[sl]=Preveri prevedena sporočila z naborom regularnih izrazov +Comment[sr]=Провери преведене поруке скупом регуларних израза +Comment[sr@Latn]=Proveri prevedene poruke skupom regularnih izraza +Comment[sv]=Kontrollera översatta meddelanden med en uppsättning reguljära uttryck +Comment[tr]=Bir Düzgün Anlatım grubu ile birlikte çevrilen mesajları denetle +Comment[uk]=Перевірити перекладені фрази за допомогою набору формальних виразів +Comment[zh_CN]=用一组正则表达式检查已翻译消息 +Comment[zh_TW]=利用正規表示式檢查已翻譯訊息 +ServiceTypes=KDataTool,KBabelValidator +DataType=CatalogItem +DataMimeTypes=application/x-kbabel-catalogitem +ReadOnly=true diff --git a/kbabel/datatools/regexp/main.cc b/kbabel/datatools/regexp/main.cc new file mode 100644 index 00000000..4464170d --- /dev/null +++ b/kbabel/datatools/regexp/main.cc @@ -0,0 +1,181 @@ +/* Copyright (C) 2005 Albert Cervera i Areny + + Based on Copyright (C) 1998, 1999 Torben Weis + 2002 Stanislav Visnovsky + 2003 Dwayne Bailey + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#include +#include "catalog.h" +#include "catalogitem.h" +#include "catalogsettings.h" +#include "main.h" +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/*************************************************** + * + * Factory + * + ***************************************************/ + +K_EXPORT_COMPONENT_FACTORY( kbabel_regexptool, KGenericFactory ( "kbabeldatatool" ) ) + +using namespace KBabel; + +RegExpTool::RegExpTool( QObject* parent, const char* name, const QStringList & ) + : KDataTool( parent, name ) +{ + i18n("which check found errors","translation has inconsistent length"); + loadExpressions(); + if ( ! _error.isNull() ) + KMessageBox::error( (QWidget*)parent, i18n( "Error loading data (%1)" ).arg( _error ) ); +} + +bool RegExpTool::run( const QString& command, void* data, const QString& datatype, const QString& mimetype ) +{ + if ( command != "validate" ) + { + kdDebug(KBABEL) << "RegExpTool only accepts the 'validate' command" << endl; + kdDebug(KBABEL) << " The command " << command << " is not accepted" << endl; + return false; + } + // Check wether we can accept the data + if ( datatype != "CatalogItem" ) + { + kdDebug(KBABEL) << "RegExpTool only accepts the CatalogItem datatype" << endl; + return false; + } + if ( mimetype != "application/x-kbabel-catalogitem" ) + { + kdDebug(KBABEL) << "RegExpTool only accepts the 'application/x-kbabel-catalogitem' mimetype" << endl; + return false; + } + + bool hasError = false; + if( command == "validate" ) + { + CatalogItem* item = (CatalogItem*)(data); + + if(!item->isUntranslated()) { + ExpressionList::Iterator it( _list.begin() ); + ExpressionList::Iterator end( _list.end() ); + QStringList msgs = item->msgstr(); + QStringList results; + for ( ; it != end; ++it ) { + results.clear(); + results = msgs.grep( (*it).regExp() ); + if ( results.size() > 0 ) { + hasError = true; + break; + } + } + } + if(hasError) { + item->appendError( "regexp" ); + } else { + item->removeError( "regexp" ); + } + } + return !hasError; +} + + +void RegExpTool::loadExpressions() +{ + // TODO: Change file path + QFile file( QDir::homeDirPath() + "/.kde/share/apps/kbabel/regexplist.xml" ); + QDomDocument doc; + + if ( ! file.open( IO_ReadOnly ) ) { + kdDebug() << "File not found" << endl; + _error = i18n( "File not found" ); + return; + } + if ( ! doc.setContent( &file ) ) { + kdDebug() << "Could not set content of xml file" << endl; + _error = i18n( "The file is not a XML" ); + return; + } + file.close(); + + QDomElement docElem = doc.documentElement(); + QDomNode n = docElem.firstChild(); + while( !n.isNull() ) { + QDomElement e = n.toElement(); + if( !e.isNull() ) + elementToExpression( e ); + if ( ! _error.isNull() ) + break; + n = n.nextSibling(); + } +} + +void RegExpTool::elementToExpression( const QDomElement& e ) +{ + QString name; + QString exp; + bool cs = false; //Expressions are case insensitive by default + + if ( e.tagName().compare( "item" ) != 0 ) { + _error = i18n( "Expected tag 'item'" ); + return; + } + + QDomNode n = e.firstChild(); + if ( n.isNull() ) { + _error = i18n( "First child of 'item' is not a node" ); + return; + } + + QDomElement el = n.toElement(); + if ( el.isNull() || el.tagName().compare( "name" ) != 0 ) { + _error = i18n( "Expected tag 'name'" ); + return; + } + name = el.text(); + + n = n.nextSibling(); + el = n.toElement(); + if ( el.isNull() || el.tagName().compare( "exp" ) != 0 ) { + _error = i18n( "Expected tag 'exp'" ); + return; + } + exp = el.text(); + + n = n.nextSibling(); + el = n.toElement(); + if ( ! el.isNull() ) + cs = true; + + kdDebug(KBABEL) << "RegExpTool: Adding expression: " << name << endl; + _list.append( Expression( name, QRegExp( exp, cs ) ) ); +} + +#include "main.moc" diff --git a/kbabel/datatools/regexp/main.h b/kbabel/datatools/regexp/main.h new file mode 100644 index 00000000..690c5769 --- /dev/null +++ b/kbabel/datatools/regexp/main.h @@ -0,0 +1,73 @@ +/* + Copyright (C) 2005 Albert Cervera i Areny + + Based on Copyright (C) 1998, 1999 Torben Weis + 2002 Stanislav Visnovsky + 2003 Dwayne Bailey + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef __main_h__ +#define __main_h__ + +#include +#include + +class QDomElement; + +class Expression +{ +public: + Expression() {}; + Expression( const QString& name, const QRegExp& regExp ) + { + _name = name; + _regExp = regExp; + } + const QString& name() const + { + return _name; + } + const QRegExp& regExp() const + { + return _regExp; + } + +private: + QString _name; + QRegExp _regExp; +}; + +typedef QValueList ExpressionList; + +class RegExpTool : public KDataTool +{ + Q_OBJECT + +public: + RegExpTool( QObject* parent, const char* name, const QStringList & ); + virtual bool run( const QString& command, void* data, const QString& datatype, const QString& mimetype); + +private: + void loadExpressions(); + void elementToExpression( const QDomElement& e ); + + ExpressionList _list; + QString _error; +}; + +#endif diff --git a/kbabel/datatools/regexp/regexplist.xml b/kbabel/datatools/regexp/regexplist.xml new file mode 100644 index 00000000..1cd0b23d --- /dev/null +++ b/kbabel/datatools/regexp/regexplist.xml @@ -0,0 +1,303 @@ + + + + + _el_ seguit de vocal + (^| |\\t)+el +[a,e,i,o,u][a-z]+ + + + _la_ seguit de a,e,o + (^| |\\t)+la +[a,e,o][a-z]+ + + + _per el_ + (^| |\\t)+per +el( |\\t|$)+ + + + _per els_ + (^| |\\t)+per +els( |\\t|$)+ + + + _de el_ + (^| |\\t)+de +el( |\\t|$)+ + + + _de els_ + (^| |\\t)+de +els( |\\t|$)+ + + + _a el_ + (^| |\\t)+a +el( |\\t|$)+ + + + _a els_ + (^| |\\t)+a +els( |\\t|$)+ + + + _al_ seguit de vocal + (^| |\\t)+al +[a,e,i,o,u][a-z]+ + + + m'els + (^| |\\t)m'els( |\\t|$)+ + + + mels + (^| |\\t)mels( |\\t|$)+ + + + s'el + (^| |\\t)s'el( |\\t|$)+ + + + sel + (^| |\\t)sel( |\\t|$)+ + + + s'els + (^| |\\t)s'els( |\\t|$)+ + + + sels + (^| |\\t)sels( |\\t|$)+ + + + s'em + (^| |\\t)s'em( |\\t|$)+ + + + sem + (^| |\\t)sem( |\\t|$)+ + + + s'hem + (^| |\\t)s'hem( |\\t|$)+ + + + s'ens + (^| |\\t)s'ens( |\\t|$)+ + + + s'et + (^| |\\t)s'et( |\\t|$)+ + + + susa + (^| |\\t)susa( |\\t|$)+ + + + s'us + (^| |\\t)s'us( |\\t|$)+ + + + su's + (^| |\\t)su's( |\\t|$)+ + + + t'els + (^| |\\t)t'els( |\\t|$)+ + + + t'el + (^| |\\t)t'el( |\\t|$)+ + + + t'em + (^| |\\t)t'em( |\\t|$)+ + + + t'ens + (^| |\\t)t'ens( |\\t|$)+ + + + t'en + (^| |\\t)t'en( |\\t|$)+ + + + ten + (^| |\\t)ten( |\\t|$)+ + + + t'ens + (^| |\\t)t'ens( |\\t|$)+ + + + vos sense accent + (^| |\\t)vos( |\\t|$) + + + Terminal s mascul (si es tracta d'informtica): el terminal + (^| |\\t)la +terminal( |\\t|$) + + + Terminal s mascul (si es tracta d'informtica): un terminal + (^| |\\t)una +terminal( |\\t|$) + + + + (^| |\\t)a +que( |\\t|$) + + + + (^| |\\t)de +que( |\\t|$) + + + + (^| |\\t)en +que( |\\t|$) + + + + (^| |\\t)amb +que( |\\t|$) + + + + (^| |\\t)per +que( |\\t|$) + + + + + + + + + (^| |\\t)es +(sa|se|si|so|su|ce|ci) + + + + + + + + + (^| |\\t)tals +com( |\\t|$) + + + + (^| |\\t)tal +i +com( |\\t|$) + + + + (^| |\\t)teniu +que( |\\t|$) + + + + (^| |\\t)en +quant +a( |\\t|$) + + + + + + (^| |\\t)hi +han( |\\t|$) + + + + (^| |\\t)hi +havien( |\\t|$) + + + + (^| |\\t)hi +hauran( |\\t|$) + + + + + + (^| |\\t)teniu +que( |\\t|$) + + + + (^| |\\t)tenim +que( |\\t|$) + + + + (^| |\\t)tenen +que( |\\t|$) + + + + (^| |\\t)en +quant +a( |\\t|$) + + + + (^| |\\t)en +quant +a( |\\t|$) + + + + (^| |\\t)en +quant +a( |\\t|$) + + + + (^| |\\t)en +quant +a( |\\t|$) + + + + (^| |\\t)en +quant +a( |\\t|$) + + + + \ No newline at end of file -- cgit v1.2.1