[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: [PATCH] KSpell2 improvement
From:       Mashrab Kuvatov <kmashrab () sat ! physik ! uni-bremen ! de>
Date:       2006-03-28 13:46:15
Message-ID: 200603281546.20113.kmashrab () sat ! physik ! uni-bremen ! de
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


Hi all,

I've updated the patch for kdelibs4. It cleanly applies to the trunk and has 
qt4 changes.

I'd appreciate, if someone could commit and compile it. Please let me know if 
there are any problems.

Cheers,
Mashrab.

PS. Please CC me, I'm not in the list.

-- 
PGP key: www.uni-bremen.de/~kmashrab/kmashrab.asc

["kspell2-localize-language-combo-kde4.patch" (text/x-diff)]

Index: broker.cpp
===================================================================
--- broker.cpp	(revision 523449)
+++ broker.cpp	(working copy)
@@ -25,6 +25,7 @@
 #include "defaultdictionary.h"
 #include "dictionary.h"
 
+#include <klocale.h>
 #include <kparts/plugin.h>
 #include <kparts/componentfactory.h>
 
@@ -168,6 +169,120 @@
     return d->languageClients.keys();
 }
 
+QStringList Broker::languagesName() const
+{
+    /* For whatever reason languages() might change. So,
+     * to be in sync with it let's do the following check.
+     */
+    if (languagesNameCache.count() == languages().count() )
+	    return languagesNameCache;
+
+    QStringList allLocalizedDictionaries;
+    QStringList allDictionaries = languages();
+    QString currentDictionary,   // e.g. en_GB-ize-wo_accents
+            lISOName,            // language ISO name
+            cISOName,            // country ISO name
+            variantName,         // dictionary variant name e.g. w_accents
+            localizedLang,       // localized language
+            localizedCountry;    // localized country
+    const char*  variantEnglish; // dictionary variant in English
+
+    int underscorePos,     // position of "_" char
+        minusPos,          // position of "-" char
+        variantCount = 0;  // used to iterate over variantList
+
+    struct variantListType
+    {
+        const char* variantShortName;
+        const char* variantEnglishName;
+    };
+    const variantListType variantList[] = {
+      { "40", I18N_NOOP2("dictionary variant", "40") }, // what does 40 mean?
+      { "60", I18N_NOOP2("dictionary variant", "60") }, // what does 60 mean?
+      { "80", I18N_NOOP2("dictionary variant", "80") }, // what does 80 mean?
+      { "ise", I18N_NOOP2("dictionary variant", "-ise suffixes") },
+      { "ize", I18N_NOOP2("dictionary variant", "-ize suffixes") },
+      { "ise-w_accents", I18N_NOOP2("dictionary variant", "-ise suffixes and with accents") },
+      { "ise-wo_accents", I18N_NOOP2("dictionary variant", "-ise suffixes and without accents") },
+      { "ize-w_accents", I18N_NOOP2("dictionary variant", "-ize suffixes and with accents") },
+      { "ize-wo_accents", I18N_NOOP2("dictionary variant", "-ize suffixes and without accents") },
+      { "lrg", I18N_NOOP2("dictionary variant", "large") },
+      { "med", I18N_NOOP2("dictionary variant", "medium") },
+      { "sml", I18N_NOOP2("dictionary variant", "small") },
+      { "variant_0", I18N_NOOP2("dictionary variant", "variant 0") },
+      { "variant_1", I18N_NOOP2("dictionary variant", "variant 1") },
+      { "variant_2", I18N_NOOP2("dictionary variant", "variant 2") },
+      { "wo_accents", I18N_NOOP2("dictionary variant", "without accents") },
+      { "w_accents", I18N_NOOP2("dictionary variant", "with accents") },
+      { "ye", I18N_NOOP2("dictionary variant", "with ye") },
+      { "yeyo", I18N_NOOP2("dictionary variant", "with yeyo") }, 
+      { "yo", I18N_NOOP2("dictionary variant", "with yo") },
+      { "extended", I18N_NOOP2("dictionary variant", "extended") },
+      { 0, 0 }
+    };
+
+    for ( QStringList::Iterator it = allDictionaries.begin(); it != allDictionaries.end(); ++it ) {
+        currentDictionary = *it;
+        minusPos = currentDictionary.find( "-" );
+      	underscorePos = currentDictionary.find( "_" );
+	if ( underscorePos != -1 && underscorePos <= 3 ) {
+           cISOName = currentDictionary.mid( underscorePos + 1, 2 );
+           lISOName = currentDictionary.left( underscorePos );
+           if ( minusPos != -1 )
+              variantName = currentDictionary.right( currentDictionary.length() - minusPos - 1 );
+	}  else {
+              if ( minusPos != -1 ) {
+                  variantName = currentDictionary.right( currentDictionary.length() - minusPos - 1 );
+                  lISOName = currentDictionary.left( minusPos );
+              }
+              else
+                 lISOName = currentDictionary;
+              }
+        localizedLang = KGlobal::locale()->twoAlphaToLanguageName( lISOName );
+        if ( localizedLang.isEmpty() )
+           localizedLang = lISOName;
+	if ( !cISOName.isEmpty() )
+           if ( !KGlobal::locale()->twoAlphaToCountryName( cISOName ).isEmpty() )
+              localizedCountry = KGlobal::locale()->twoAlphaToCountryName( cISOName );
+           else
+              localizedCountry = cISOName;
+	if ( !variantName.isEmpty() ) {
+	   while ( variantList[ variantCount ].variantShortName != 0 )
+		  if ( variantList[ variantCount ].variantShortName == variantName )
+			 break;
+	          else
+			 variantCount++;
+	   if ( variantList[ variantCount ].variantShortName != 0 )
+           	variantEnglish = variantList[ variantCount ].variantEnglishName;
+	   else
+           	variantEnglish = variantName.latin1();
+	}
+	if ( !cISOName.isEmpty() && !variantName.isEmpty() )
+             allLocalizedDictionaries.append( i18n(
+				    "dictionary name. %1-language, %2-country and %3 variant name",
+				    "%1 (%2) [%3]" ).arg( localizedLang, localizedCountry,
+				                    i18n( "dictionary variant", variantEnglish ) ) );
+	else
+	     if ( !cISOName.isEmpty() )
+                  allLocalizedDictionaries.append( i18n(
+					 "dictionary name. %1-language and %2-country name",
+					 "%1 (%2)" ).arg( localizedLang, localizedCountry ) );
+             else
+	        if ( !variantName.isEmpty() )
+            	     allLocalizedDictionaries.append( i18n(
+					    "dictionary name. %1-language and %2-variant name",
+					    "%1 [%2]" ).arg( localizedLang,
+						    i18n( "dictionary variant", variantEnglish ) ) );
+		else
+                  allLocalizedDictionaries.append( localizedLang );
+	lISOName = cISOName = variantName = "";
+	variantCount = 0;
+    }
+    // cache the list
+    languagesNameCache = allLocalizedDictionaries;
+    return allLocalizedDictionaries;
+}
+
 Settings* Broker::settings() const
 {
     return d->settings;
Index: broker.h
===================================================================
--- broker.h	(revision 523449)
+++ broker.h	(working copy)
@@ -106,6 +106,11 @@
         QStringList languages() const;
 
         /**
+         * Returns a localized list of names of supported languages.
+         */
+        QStringList languagesName() const;
+
+        /**
          * Returns the Settings object used by the broker.
          */
         Settings *settings() const;
@@ -123,6 +128,7 @@
         Broker( KSharedConfig *config );
         void loadPlugins();
         void loadPlugin( const QString& );
+        mutable QStringList languagesNameCache;
     private:
         class Private;
         Private* const d;
Index: ui/dialog.cpp
===================================================================
--- ui/dialog.cpp	(revision 523449)
+++ ui/dialog.cpp	(working copy)
@@ -117,14 +117,9 @@
     d->ui = new KSpell2UI( this );
     d->ui->m_suggestions->setSorting( NONSORTINGCOLUMN );
     d->ui->m_language->clear();
-    d->ui->m_language->insertItems( d->ui->m_language->count(), d->checker->broker()->languages() );
-    for ( int i = 0; !d->ui->m_language->itemText( i ).isNull(); ++i ) {
-        QString ct = d->ui->m_language->itemText( i );
-        if ( ct == d->checker->broker()->settings()->defaultLanguage() ) {
-            d->ui->m_language->setCurrentIndex( i );
-            break;
-        }
-    }
+    d->ui->m_language->insertItems( 0, d->checker->broker()->languagesName() );
+    d->ui->m_language->setCurrentIndex( d->checker->broker()->languages().findIndex(
+                                 d->checker->broker()->settings()->defaultLanguage() ) );
 }
 
 void Dialog::activeAutoCorrect( bool _active )
@@ -238,7 +233,9 @@
 
 void Dialog::slotChangeLanguage( const QString& lang )
 {
-    d->checker->changeLanguage( lang );
+    d->checker->changeLanguage(
+        d->checker->broker()->languages()[
+            d->checker->broker()->languagesName().findIndex( lang ) ] );
     slotSuggest();
 }
 
Index: ui/configwidget.cpp
===================================================================
--- ui/configwidget.cpp	(revision 523449)
+++ ui/configwidget.cpp	(working copy)
@@ -58,10 +58,9 @@
     QVBoxLayout *layout = new QVBoxLayout( this, 0, 0, "KSpell2ConfigUILayout");
     d->ui = new KSpell2ConfigUI( this );
 
-    QStringList langs = d->broker->languages();
     //QStringList clients = d->broker->clients();
-    d->ui->m_langCombo->insertItems(d->ui->m_langCombo->count(), langs );
-    setCorrectLanguage( langs );
+    d->ui->m_langCombo->insertItems( 0, d->broker->languagesName() );
+    setCorrectLanguage( d->broker->languages() );
     //d->ui->m_clientCombo->insertStringList( clients );
     d->ui->m_skipUpperCB->setChecked( !d->broker->settings()->checkUppercase() );
     d->ui->m_skipRunTogetherCB->setChecked( d->broker->settings()->skipRunTogether() );
@@ -84,7 +83,9 @@
 void ConfigWidget::setFromGUI()
 {
     d->broker->settings()->setDefaultLanguage(
-        d->ui->m_langCombo->currentText() );
+        d->broker->languages()[
+            d->broker->languagesName().findIndex( 
+                d->ui->m_langCombo->currentText() ) ] );
     d->broker->settings()->setCheckUppercase(
         !d->ui->m_skipUpperCB->isChecked() );
     d->broker->settings()->setSkipRunTogether(

[Attachment #6 (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic