Bug 746148 - Respect the LANG environment variable when trying to select a spell checking dictionary; r=ehsan a=mfinkle
authorjhorak <jhorak@redhat.com>
Thu, 19 Apr 2012 13:45:50 -0400
changeset 95294 6294c13ee51e040d96b0b0fcc1d6335f28261758
parent 95293 d8a90842487049896570f621ebb18bf2afe4edd5
child 95295 3e24a0ebd104a5d11712ab9a7879003db8601773
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, mfinkle
bugs746148
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 746148 - Respect the LANG environment variable when trying to select a spell checking dictionary; r=ehsan a=mfinkle
editor/composer/src/nsEditorSpellCheck.cpp
--- a/editor/composer/src/nsEditorSpellCheck.cpp
+++ b/editor/composer/src/nsEditorSpellCheck.cpp
@@ -736,28 +736,41 @@ nsEditorSpellCheck::UpdateCurrentDiction
               break;
           }
         }
       }
     }
   }
 
   // If we have not set dictionary, and the editable element doesn't have a
-  // lang attribute, we try to get a dictionary. First try, en-US. If it does
-  // not work, pick the first one.
+  // lang attribute, we try to get a dictionary. First try LANG environment variable,
+  // then en-US. If it does not work, pick the first one.
   if (mPreferredLang.IsEmpty()) {
     nsAutoString currentDictionary;
     rv = GetCurrentDictionary(currentDictionary);
     if (NS_FAILED(rv) || currentDictionary.IsEmpty()) {
-      rv = SetCurrentDictionary(NS_LITERAL_STRING("en-US"));
+      // Try to get current dictionary from environment variable LANG
+      char* env_lang = getenv("LANG");
+      if (env_lang != nsnull) {
+        nsString lang = NS_ConvertUTF8toUTF16(env_lang);
+        // Strip trailing charset if there is any
+        PRInt32 dot_pos = lang.FindChar('.');
+        if (dot_pos != -1) {
+          lang = Substring(lang, 0, dot_pos - 1);
+        }
+        rv = SetCurrentDictionary(lang);
+      }
       if (NS_FAILED(rv)) {
-        nsTArray<nsString> dictList;
-        rv = mSpellChecker->GetDictionaryList(&dictList);
-        if (NS_SUCCEEDED(rv) && dictList.Length() > 0) {
-          SetCurrentDictionary(dictList[0]);
+        rv = SetCurrentDictionary(NS_LITERAL_STRING("en-US"));
+        if (NS_FAILED(rv)) {
+          nsTArray<nsString> dictList;
+          rv = mSpellChecker->GetDictionaryList(&dictList);
+          if (NS_SUCCEEDED(rv) && dictList.Length() > 0) {
+            SetCurrentDictionary(dictList[0]);
+          }
         }
       }
     }
   }
 
   // If an error was thrown while setting the dictionary, just
   // fail silently so that the spellchecker dialog is allowed to come
   // up. The user can manually reset the language to their choice on