diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | bd9e6617827818fd043452c08c606f07b78014a0 (patch) | |
tree | 425bb4c3168f9c02f10150f235d2cb998dcc6108 /kbabel/datatools/length | |
download | tdesdk-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/datatools/length')
-rw-r--r-- | kbabel/datatools/length/Makefile.am | 19 | ||||
-rw-r--r-- | kbabel/datatools/length/kbabel_lengthtool.desktop | 98 | ||||
-rw-r--r-- | kbabel/datatools/length/main.cc | 142 | ||||
-rw-r--r-- | kbabel/datatools/length/main.h | 54 | ||||
-rw-r--r-- | kbabel/datatools/length/test.po | 46 |
5 files changed, 359 insertions, 0 deletions
diff --git a/kbabel/datatools/length/Makefile.am b/kbabel/datatools/length/Makefile.am new file mode 100644 index 00000000..62231402 --- /dev/null +++ b/kbabel/datatools/length/Makefile.am @@ -0,0 +1,19 @@ + +INCLUDES = -I$(srcdir)/../../common -I../../common $(all_includes) +kbabel_lengthtool_la_LIBADD = $(LIB_KIO) ../../common/libkbabelcommon.la + +####### Files + +kde_module_LTLIBRARIES = kbabel_lengthtool.la + +kbabel_lengthtool_la_SOURCES = main.cc + +kbabel_lengthtool_la_LDFLAGS = $(all_libraries) -avoid-version -module -no-undefined + +noinst_HEADERS = main.h + +kbabel_lengthtool_la_METASOURCES = AUTO + +service_DATA = kbabel_lengthtool.desktop +servicedir = $(kde_servicesdir) + diff --git a/kbabel/datatools/length/kbabel_lengthtool.desktop b/kbabel/datatools/length/kbabel_lengthtool.desktop new file mode 100644 index 00000000..2171f44e --- /dev/null +++ b/kbabel/datatools/length/kbabel_lengthtool.desktop @@ -0,0 +1,98 @@ +[Desktop Entry] +Name=Translated Message Length Validator for KBabel +Name[bg]=Валидност на дължината на преведените съобщения - KBabel +Name[bs]=Provjera dužine prevedenih poruka za KBabel +Name[ca]=Un validador per a KBabel de la llargària dels missatges traduïts +Name[cs]=Validátor délky přeložených zpráv +Name[cy]=Dilysydd Hyd Neges wedi'i Gyfieithu ar gyfer KBabel +Name[da]=Oversat beskedlængde godkender for KBabel +Name[de]=Überprüfung der übersetzten Nachrichtenlänge für KBabel +Name[el]=Ελεγκτής εγκυρότητας μήκους μεταφρασμένων μηνυμάτων για το KBabel +Name[eo]=Longeckontrolilo por tradukitaj mesaĝoj +Name[es]=Validador de longitud de mensajes traducidos para KBabel +Name[et]=KBabeli tõlgitud teadete pikkuse kontrollija +Name[eu]=Itzulitako mezu luzera balidatzailea KBabel-entzat +Name[fa]=اعتبارسنج طول پیام ترجمهشده برای KBabel +Name[fi]=Käännetyn viestin pituuden tarkistus KBabelissa +Name[fr]=Un validateur de longueur de message pour KBabel +Name[gl]=Validador do tamaño da mensaxe traducida para KBabel +Name[hu]=Üzenethossz-ellenőrző a KBabelhez +Name[is]=Staðfestir á lengd þýddra skeyta fyrir KBabel +Name[it]=Convalidatore di KBabel per la lunghezza dei messaggi tradotti +Name[ja]=KBabel 翻訳メッセージの長さを検証 +Name[ka]=ნათარგმნი შეტყობინებების სიგრძის დამოწმება KBabel-სთვის +Name[kk]=KBabel-дың аударылған жазулардың ұзындығын тексеруі +Name[lt]=KBabel išverstų pranešimų ilgio patikros įrankis +Name[nb]=Sjekk av lengden på oversatte strenger i KBabel +Name[nds]=Textlängde-Prööv för KBabel +Name[ne]=केब्याबलका लागि अनुबाद गरिएको सन्देश लम्बाइ प्रमाणितकर्ता +Name[nl]=Vertaalde-tekstlengte-validatie voor KBabel +Name[nn]=Sjekk av lengda på omsette strengar i KBabel +Name[pl]=Sprawdzenie długości przetłumaczonego komunikatu w KBabel +Name[pt]=Validador do Tamanho da Mensagem Traduzida para o KBabel +Name[pt_BR]=Um Validador de Tamanho de Mensagem Traduzida para o KBabel +Name[ru]=Проверка длины переведённых сообщений для KBabel +Name[sk]=Kontrola dĺžky preložených textov pre KBabel +Name[sl]=Potrjevalnik dolžin prevedenih sporočil za KBabel +Name[sr]=Оверивач дужине преведених порука за KBabel +Name[sr@Latn]=Overivač dužine prevedenih poruka za KBabel +Name[sv]=Validering av meddelandelängd för översättningar i Kbabel +Name[ta]= Kபாபேலுக்கான மொழிபெயர்ப்பு செய்தி அளவு மதிப்பீட்டாளர் +Name[tg]=Утилитаи тафтиши дарозии ахборҳои тарҷумакунанда барои KBabel +Name[tr]=KBabel için Çevrilen Mesaj Uzunluk Kontrolü +Name[uk]=Перевірка довжини перекладених фраз для KBabel +Name[zh_CN]=KBabel 已翻译消息的长度检查器 +Name[zh_TW]=KBabel 的已翻譯訊息長度檢查器 +ValidationString=length checking +X-KDE-Library=kbabel_lengthtool +Type=Service +Commands=validate +Comment=Check Translated Message Length +Comment[bg]=Проверка дължината на преведените съобщения +Comment[bs]=Provjeri dužinu prevedenih poruka +Comment[ca]=Comprova la llargària del missatge traduït +Comment[cs]=Zkontrolovat délku přeložené zprávy +Comment[cy]=Gwirio hyd neges wedi'i gyfieithu +Comment[da]=Tjek oversat beskedlængde +Comment[de]=Prüfung der übersetzten Nachrichtenlänge +Comment[el]=Έλεγχος μήκους μεταφρασμένων μηνυμάτων +Comment[eo]=Kontrolu longecon de tradukita mesaĝo +Comment[es]=Comprobar longitud de los mensajes traducidos +Comment[et]=Tõlgitud teate pikkuse kontroll +Comment[eu]=Egiaztatu itzulitako mezuen luzera +Comment[fa]=بررسی طول پیام ترجمهشده +Comment[fi]=Tarkista käännetyn viestin pituus +Comment[fr]=Vérifie la longueur des messages traduits +Comment[gl]=Verificación do tamaño da mensaxe traducida +Comment[hi]=अनूदित संदेश लंबाई जाँचें +Comment[hu]=A lefordított üzenetek hosszának ellenőrzése +Comment[is]=Athuga lengd þýddra skeyta +Comment[it]=Controlla la lunghezza dei messaggi tradotti +Comment[ja]=翻訳メッセージの長さを検証 +Comment[ka]=ნათარგმნი შეტყობინებების სიგრძის შემოწმება +Comment[kk]=Аударылған жазулардың ұзындығын тексеру +Comment[lt]=Tikrinti išverstų pranešimų ilgį +Comment[nb]=Sjekk lengden på oversatte strenger +Comment[nds]=Översett Textlängde pröven +Comment[ne]=अनुबाद गरिएको सन्देश लम्बाइ जाँच गर्नुहोस् +Comment[nl]=Lengte van vertaalde tekst controleren +Comment[nn]=Sjekk lengda på omsette strengar +Comment[pl]=Sprawdzenie długości przetłumaczonego komunikatu +Comment[pt]=Verificação do Tamanho da Mensagem Traduzida +Comment[pt_BR]=Verifica o Comprimento da Mensagem Traduzida +Comment[ru]=Проверить длину переведённых сообщений +Comment[sk]=Kontrola dĺžky preložených textov +Comment[sl]=Preveri dolžino prevedenih sporočil +Comment[sr]=Провери дужину преведених порука +Comment[sr@Latn]=Proveri dužinu prevedenih poruka +Comment[sv]=Kontrollera meddelandelängd för översättningar +Comment[ta]= மொழிபெயர் செய்தி நீளம் சரிபார்ப்பு +Comment[tg]=Тафтиш кардани дарозии хабарҳои тарҷумашуда +Comment[tr]=Çevrilen Mesaj Uzunluğunu 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/length/main.cc b/kbabel/datatools/length/main.cc new file mode 100644 index 00000000..ee595dc9 --- /dev/null +++ b/kbabel/datatools/length/main.cc @@ -0,0 +1,142 @@ +/* This file is part of KBabel + based Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> + 2002 Stanislav Visnovsky <visnovsky@kde.org> + 2003 Dwayne Bailey <dwayne@translate.org.za> + + 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. + + 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 <resources.h> +#include "catalog.h" +#include "catalogitem.h" +#include "catalogsettings.h" +#include "main.h" +#include <math.h> + +#include <kconfig.h> +#include <kdebug.h> +#include <kgenericfactory.h> +#include <klibloader.h> +#include <klocale.h> +#include <kmessagebox.h> + +/*************************************************** + * + * Factory + * + ***************************************************/ + +K_EXPORT_COMPONENT_FACTORY( kbabel_lengthtool, KGenericFactory<LengthTool> ( "kbabeldatatool" ) ) + +using namespace KBabel; + +LengthTool::LengthTool( QObject* parent, const char* name, const QStringList & ) + : KDataTool( parent, name ), _cache_origin( 0 ) +{ + i18n("which check found errors","translation has inconsistent length"); +} + +bool LengthTool::run( const QString& command, void* data, const QString& datatype, const QString& mimetype ) +{ + + if ( command != "validate" ) + { + kdDebug(KBABEL) << "Length Tool 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) << "Length Tool only accept the CatalogItem datatype" << endl; + return false; + } + + if ( mimetype != "application/x-kbabel-catalogitem" ) + { + kdDebug(KBABEL) << "Length Tool only accept the 'application/x-kbabel-catalogitem' mimetype" << endl; + return false; + } + + if( command == "validate" ) + { + + CatalogItem* item = (CatalogItem*)(data); + bool hasError = false; + QStringList str, id; + + if(!item->isUntranslated()) { + + if( _cache_origin != item->project() ) + { + _context = item->project()->miscSettings().contextInfo; + _plurals = item->project()->miscSettings().singularPlural; + _cache_origin = item->project(); + } + + //Ensure KDE plural forms are in a StringList + if( item->pluralForm() == KDESpecific ) { + str = QStringList::split( "\\n", item->msgstr().first(), true ); + id = QStringList::split( "\\n", + item->msgid().first().replace( QRegExp(_plurals), ""), true ); + } else { + str = item->msgstr(); + id = item->msgid(); + } + + //Check for translations that are too short or too long + //This may not be totally correct but we check both + //the singular and plural forms against each translated plural. + //FIXME: replace 10% check with configurable setting or a statistical + //based expected length relationship + int idlen, strlen; + for( QStringList::Iterator i = id.begin() ; i != id.end() ; i++ ) { + QString iditem = (*i); + idlen = iditem.replace( QRegExp(_context),"").length(); + for( QStringList::Iterator j = str.begin() ; j != str.end() ; j++ ) { + QString stritem = (*j); + strlen = stritem.length(); + hasError = hasError || (strlen < (0.1 * idlen)) + || (strlen > (10 * idlen)); + } + } + + } + + if(hasError) + item->appendError( "translation has inconsistant length" ); + else + item->removeError( "translation has inconsistant length" ); + + return !hasError; + } + return false; +} + +#include "main.moc" diff --git a/kbabel/datatools/length/main.h b/kbabel/datatools/length/main.h new file mode 100644 index 00000000..225c91ad --- /dev/null +++ b/kbabel/datatools/length/main.h @@ -0,0 +1,54 @@ +/* This file is part of KBabel + based on Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> + 2002 Stanislav Visnovsky <visnovsky@kde.org> + 2003 Dwayne Bailey <dwayne@translate.org.za> + + 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. + + 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 __main_h__ +#define __main_h__ + +#include "kbproject.h" + +#include <kdatatool.h> + +class LengthTool : public KDataTool +{ + Q_OBJECT + +public: + LengthTool( QObject* parent, const char* name, const QStringList & ); + virtual bool run( const QString& command, void* data, const QString& datatype, const QString& mimetype); +private: + KBabel::Project::Ptr _cache_origin; + QRegExp _context; + QRegExp _plurals; +}; + +#endif diff --git a/kbabel/datatools/length/test.po b/kbabel/datatools/length/test.po new file mode 100644 index 00000000..d1bb209d --- /dev/null +++ b/kbabel/datatools/length/test.po @@ -0,0 +1,46 @@ +# Test file to validate the length checking tool +# Dwayne Bailey <dwayne@translate.org.za>, 2003 +# +msgid "" +msgstr "" +"Project-Id-Version: test\n" +"Last-Translator: Dwayne Bailey <dwayne@translate.org.za>\n" +"PO-Revision-Date: 2003-01-09 09:35+0200\n" +"Language-Team: <english@translate.org.za>\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: KBabel 1.2\n" + +# msgstr < 10% of msgid +# Expected Result = error +msgid "Some translation string" +msgstr "aa" + +# msgstr > 10 * length of msgid +# Expected Result = error +msgid "Short" +msgstr "Very long translation of a very short string. " +"This should be picked up. Not really sure what a more" +" correct approach might be." + +# Shortness test with KDE plural forms +# Expected Result = error +msgid "" +"_n: Some translation string\n" +"Second form %n" +msgstr "" +"aa\n" +"Second form %n transaltion" + +# SHortness test with GNU plural forms +# Expected Result = error +msgid "Some translation string" +msgid_plural "The second form %n" +msgstr[0] "aa" +msgstr[1] "Second for %n" + +# Shortness test with KDE context info +# Expected Result = error +msgid "_: Translation comment\n" +"Some translation string" +msgstr "aa" |