r17886 by jghali - Better language detection for spell dictionary (backport from 1.5.0svn)

scribus-commit scribus-commit at lists.scribus.net
Tue Nov 20 00:18:13 UTC 2012


Author: jghali
Date: Tue Nov 20 00:18:13 2012
New Revision: 17886

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17886
Log:
Better language detection for spell dictionary (backport from 1.5.0svn)

Modified:
    branches/Version14x/Scribus/scribus/langmgr.cpp
    branches/Version14x/Scribus/scribus/langmgr.h

Modified: branches/Version14x/Scribus/scribus/langmgr.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17886&path=/branches/Version14x/Scribus/scribus/langmgr.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/langmgr.cpp (original)
+++ branches/Version14x/Scribus/scribus/langmgr.cpp Tue Nov 20 00:18:13 2012
@@ -272,6 +272,40 @@
 	return "";
 }
 
+const QString LanguageManager::getShortAbbrevFromAbbrev(QString langAbbrev)
+{
+	if (langList.contains(langAbbrev))
+		return langAbbrev;
+
+	QString joiner("_");
+	QStringList langParts = langAbbrev.split(QChar('_'));
+	if (langParts.count() > 2)
+		langParts.removeLast();
+
+	while (langParts.count() > 2)
+	{
+		QString abbrev = langParts.join(joiner);
+		if (langList.contains(abbrev))
+			return abbrev;
+		langParts.removeLast();
+	}
+
+	if (langParts.count() == 2)
+	{
+		QString abbrev = langParts.join(joiner);
+		if (langList.contains(abbrev))
+			return abbrev;
+		if (langParts.at(0) == langParts.at(1).toLower())
+		{
+			if (langList.contains(langParts.at(0)))
+				return langParts.at(0);
+		}
+		langParts.removeLast();
+	}
+
+	return "";
+}
+
 void LanguageManager::fillInstalledStringList(QStringList *stringListToFill, bool addDefaults) 
 {
 	if (stringListToFill)
@@ -366,11 +400,23 @@
 		foreach(dictName, dictList)
 		{
 			if (!QFile::exists(dictionaryPaths.at(i)+dictName+".aff"))
+			{
 				dictList.removeAll(dictName);
+			}
 			else
 			{
 				if (!dictionaryMap.contains(dictName))
-					dictionaryMap.insert(dictName, dictionaryPaths.at(i)+dictName);
+				{
+					if (dictName.length() <= 5 && langList.contains(dictName))
+					{
+						dictionaryMap.insert(dictName, dictionaryPaths.at(i)+dictName);
+						continue;
+					}
+					QString shortAbbrev(LanguageManager::getShortAbbrevFromAbbrev(dictName));
+					if (shortAbbrev.isEmpty())
+						shortAbbrev = dictName;
+					dictionaryMap.insert(shortAbbrev, dictionaryPaths.at(i)+dictName);
+				}
 			}
 		}
 //		qDebug()<<"Number of dictionaries/AFFs found in"<<dictionaryPaths.at(i)<<":"<<dictList.count();

Modified: branches/Version14x/Scribus/scribus/langmgr.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17886&path=/branches/Version14x/Scribus/scribus/langmgr.h
==============================================================================
--- branches/Version14x/Scribus/scribus/langmgr.h (original)
+++ branches/Version14x/Scribus/scribus/langmgr.h Tue Nov 20 00:18:13 2012
@@ -47,6 +47,7 @@
 	const QString getAbbrevFromLang(QString lang, bool getFromTranslated=true, bool useInstalled=true, int abbrevNo=1);
 	const QString getLangFromTransLang(QString lang);
 	const QString getTransLangFromLang(QString lang);
+	const QString getShortAbbrevFromAbbrev(QString langAbbrev);
 	void fillInstalledStringList(QStringList *stringListToFill, bool addDefaults);
 	void printInstalledList();
 	QString numericSequence(QString seq);




More information about the scribus-commit mailing list