Blob Blame History Raw
diff -up comm-esr31/mozilla/editor/composer/src/nsEditorSpellCheck.cpp.dict-fix comm-esr31/mozilla/editor/composer/src/nsEditorSpellCheck.cpp
--- comm-esr31/mozilla/editor/composer/src/nsEditorSpellCheck.cpp.dict-fix	2014-11-27 23:16:41.000000000 +0100
+++ comm-esr31/mozilla/editor/composer/src/nsEditorSpellCheck.cpp	2014-12-11 13:06:02.679106492 +0100
@@ -102,6 +102,23 @@ GetLoadContext(nsIEditor* aEditor)
 }
 
 /**
+ * Helper function for converting underscore to dash in dictionary name,
+ * ie. en_CA to en-CA. This is required for some Linux distributions which
+ * use underscore as separator in system-wide installed dictionaries.
+ * We use it for nsStyleUtil::DashMatchCompare.
+ */
+static nsString
+GetDictNameWithDash(const nsAString& aDictName)
+{
+  nsString dictNameWithDash(aDictName);
+  int32_t underScore = dictNameWithDash.FindChar('_');
+  if (underScore != -1) {
+    dictNameWithDash.Replace(underScore, 1, '-');
+  }
+  return dictNameWithDash;
+}
+
+/**
  * Fetches the dictionary stored in content prefs and maintains state during the
  * fetch, which is asynchronous.
  */
@@ -603,8 +620,8 @@ nsEditorSpellCheck::SetCurrentDictionary
     } else {
       langCode.Assign(aDictionary);
     }
-
-    if (mPreferredLang.IsEmpty() || !nsStyleUtil::DashMatchCompare(mPreferredLang, langCode, comparator)) {
+    if (mPreferredLang.IsEmpty() ||
+        !nsStyleUtil::DashMatchCompare(GetDictNameWithDash(mPreferredLang), langCode, comparator)) {
       // When user sets dictionary manually, we store this value associated
       // with editor url.
       StoreCurrentDictionary(mEditor, aDictionary);
@@ -790,8 +807,8 @@ nsEditorSpellCheck::DictionaryFetched(Di
 
       // try dictionary.spellchecker preference if it starts with langCode (and
       // if we haven't tried it already)
-      if (!preferedDict.IsEmpty() && !dictName.Equals(preferedDict) && 
-          nsStyleUtil::DashMatchCompare(preferedDict, langCode, comparator)) {
+      if (!preferedDict.IsEmpty() && !dictName.Equals(preferedDict) &&
+          nsStyleUtil::DashMatchCompare(GetDictNameWithDash(preferedDict), langCode, comparator)) {
         rv = SetCurrentDictionary(preferedDict);
       }
 
@@ -819,8 +836,7 @@ nsEditorSpellCheck::DictionaryFetched(Di
             // We have already tried it
             continue;
           }
-
-          if (nsStyleUtil::DashMatchCompare(dictStr, langCode, comparator) &&
+          if (nsStyleUtil::DashMatchCompare(GetDictNameWithDash(dictStr), langCode, comparator) &&
               NS_SUCCEEDED(SetCurrentDictionary(dictStr))) {
               break;
           }