r17803 by craig - Add in a workaround for different language abbreviations for 1.4.x

scribus-commit scribus-commit at lists.scribus.net
Sat Oct 13 20:53:16 UTC 2012


Author: craig
Date: Sat Oct 13 20:53:16 2012
New Revision: 17803

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17803
Log:
Add in a workaround for different language abbreviations for 1.4.x

Modified:
    branches/Version14x/Scribus/scribus/langmgr.cpp
    branches/Version14x/Scribus/scribus/langmgr.h
    branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp

Modified: branches/Version14x/Scribus/scribus/langmgr.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17803&path=/branches/Version14x/Scribus/scribus/langmgr.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/langmgr.cpp (original)
+++ branches/Version14x/Scribus/scribus/langmgr.cpp Sat Oct 13 20:53:16 2012
@@ -178,11 +178,12 @@
 		return "";	
 }
 
-const QString LanguageManager::getAbbrevFromLang(QString lang, bool getFromTranslated, bool useInstalled)
+const QString LanguageManager::getAbbrevFromLang(QString lang, bool getFromTranslated, bool useInstalled, int abbrevNo)
 {
 	QMap<QString, langPair>::Iterator it;
 	if (lang == "English" || lang == QObject::tr( "English"))
 		useInstalled = false;
+	int count=1;
 	if (useInstalled)
 	{
 		for (it=langList.begin();it!=langList.end();++it)
@@ -190,9 +191,23 @@
 			if (installedLangList.find(it.key()) != installedLangList.end())
 			{
 				if (getFromTranslated && it.value().second==lang)
-					return it.key();
+				{
+					if (abbrevNo==1)
+						return it.key();
+					if (abbrevNo!=1 && count==abbrevNo)
+						return it.key();
+					++count;
+					continue;			
+				}
 				if (!getFromTranslated && it.value().first==lang)
-					return it.key();
+				{
+					if (abbrevNo==1)
+						return it.key();
+					if (abbrevNo!=1 && count==abbrevNo)
+						return it.key();
+					++count;
+					continue;		
+				}
 			}
 		}
 	}
@@ -200,13 +215,25 @@
 	{
 		for (it=langList.begin();it!=langList.end();++it)
 		{
-// 			if (installedLangList.find(it.key()) != installedLangList.end())
-// 			{
 			if (getFromTranslated && it.value().second==lang)
-				return it.key();
+			{
+				if (abbrevNo==1)
+					return it.key();
+				if (abbrevNo!=1 && count==abbrevNo)
+					return it.key();
+				++count;
+				continue;
+					
+			}
 			if (!getFromTranslated && it.value().first==lang)
-				return it.key();
-// 			}
+			{
+				if (abbrevNo==1)
+					return it.key();
+				if (abbrevNo!=1 && count==abbrevNo)
+					return it.key();
+				++count;
+				continue;
+			}
 		}
 	}
 	return "";

Modified: branches/Version14x/Scribus/scribus/langmgr.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17803&path=/branches/Version14x/Scribus/scribus/langmgr.h
==============================================================================
--- branches/Version14x/Scribus/scribus/langmgr.h (original)
+++ branches/Version14x/Scribus/scribus/langmgr.h Sat Oct 13 20:53:16 2012
@@ -43,8 +43,8 @@
 public:
 	static LanguageManager* instance();
 	
-	const QString getLangFromAbbrev(QString, bool getTranslated=true);
-	const QString getAbbrevFromLang(QString, bool getFromTranslated=true, bool useInstalled=true);
+	const QString getLangFromAbbrev(QString langAbbrev, bool getTranslated=true);
+	const QString getAbbrevFromLang(QString lang, bool getFromTranslated=true, bool useInstalled=true, int abbrevNo=1);
 	const QString getLangFromTransLang(QString lang);
 	const QString getTransLangFromLang(QString lang);
 	void fillInstalledStringList(QStringList *stringListToFill, bool addDefaults);

Modified: branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17803&path=/branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp (original)
+++ branches/Version14x/Scribus/scribus/plugins/tools/hunspellcheck/hunspellpluginimpl.cpp Sat Oct 13 20:53:16 2012
@@ -122,27 +122,36 @@
 		currPos=wordStart;
 		QString word=iText->text(wordStart,wordEnd-wordStart);
 		QString wordLang=iText->charStyle(wordStart).language();
-		wordLang=LanguageManager::instance()->getAbbrevFromLang(wordLang, true, false);
+		//qDebug()<<wordLang<<LanguageManager::instance()->getAbbrevFromLang(wordLang, true, false, 1)<<LanguageManager::instance()->getAbbrevFromLang(wordLang, true, false, 2);
+		QString langAbbrev=LanguageManager::instance()->getAbbrevFromLang(wordLang, true, false, 1);
 		//A little hack as for some reason our en dictionary from the aspell plugin was not called en_GB or en_US but en, content was en_GB though. Meh.
-		if (wordLang=="en")
-			wordLang="en_GB";
+		if (langAbbrev=="en")
+			langAbbrev="en_GB";
 		int spellerIndex=0;
-		if (!dictionaryMap.contains(wordLang))
-			qDebug()<<"Spelling language to match style language not installed ("<<wordLang<<")";
+		if (!dictionaryMap.contains(langAbbrev))
+		{
+			//qDebug()<<"Spelling language to match style language not installed ("<<langAbbrev<<")";
+			QString langAbbrev2=LanguageManager::instance()->getAbbrevFromLang(wordLang, true, false, 2);
+			if (!langAbbrev2.isEmpty() && dictionaryMap.contains(langAbbrev2))
+			{
+				//qDebug()<<"Spelling language swapped to :"<<langAbbrev2;
+				langAbbrev=langAbbrev2;
+			}
+		}
 		else
 		{
 			int i=0;
 			QMap<QString, QString>::iterator it = dictionaryMap.begin();
 			while (it != dictionaryMap.end())
 			{
-				if (it.key()==wordLang)
+				if (it.key()==langAbbrev)
 					break;
 				++i;
 				++it;
 			}
 			spellerIndex=i;
 		}
-		if (hspellerMap.contains(wordLang) && hspellerMap[wordLang]->spell(word.toUtf8().constData())==0)
+		if (hspellerMap.contains(langAbbrev) && hspellerMap[langAbbrev]->spell(word.toUtf8().constData())==0)
 		{
 			struct WordsFound wf;
 			wf.start=currPos;
@@ -151,13 +160,13 @@
 			wf.changed=false;
 			wf.ignore=false;
 			wf.changeOffset=0;
-			wf.lang=wordLang;
+			wf.lang=langAbbrev;
 			wf.replacements.clear();
 			char **sugglist = NULL;
-			int suggCount=hspellerMap[wordLang]->suggest(&sugglist, word.toUtf8().constData());
+			int suggCount=hspellerMap[langAbbrev]->suggest(&sugglist, word.toUtf8().constData());
 			for (int j=0; j < suggCount; ++j)
 				wf.replacements << QString::fromUtf8(sugglist[j]);
-			hspellerMap[wordLang]->free_list(&sugglist, suggCount);
+			hspellerMap[langAbbrev]->free_list(&sugglist, suggCount);
 			wordsToCorrect.append(wf);
 		}
 	}




More information about the scribus-commit mailing list