From 644e3ad91250c0cb7b291b48e3b5cef401bffd90 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Mon, 30 May 2011 13:08:47 -0400
Subject: [PATCH] - Fix setting language for spellchecker on spellcheck_before_send

---
 program/js/googiespell.js              |   10 +++++-----
 program/include/rcube_spellchecker.php |   25 ++++++++++++++++++++++++-
 program/steps/mail/sendmail.inc        |    2 +-
 program/js/app.js                      |   16 +++++++++++++++-
 4 files changed, 45 insertions(+), 8 deletions(-)

diff --git a/program/include/rcube_spellchecker.php b/program/include/rcube_spellchecker.php
index 7acb700..8282406 100644
--- a/program/include/rcube_spellchecker.php
+++ b/program/include/rcube_spellchecker.php
@@ -52,7 +52,7 @@
     {
         $this->rc = rcmail::get_instance();
         $this->engine = $this->rc->config->get('spellcheck_engine', 'googie');
-        $this->lang = $lang;
+        $this->lang = $lang ? $lang : 'en';
 
         if ($this->engine == 'pspell' && !extension_loaded('pspell')) {
             raise_error(array(
@@ -161,6 +161,29 @@
 
 
     /**
+     * Returns checking result (mispelled words with suggestions)
+     *
+     * @return array Spellchecking result. An array indexed by word.
+     */
+    function get()
+    {
+        $result = array();
+
+        foreach ($this->matches as $item) {
+            if ($this->engine == 'pspell') {
+                $word = $item[0];
+            }
+            else {
+                $word = mb_substr($this->content, $item[1], $item[2], RCMAIL_CHARSET);
+            }
+            $result[$word] = is_array($item[4]) ? implode("\t", $item[4]) : $item[4];
+        }
+
+        return $out;
+    }
+
+
+    /**
      * Returns error message
      *
      * @return string Error message
diff --git a/program/js/app.js b/program/js/app.js
index ea54b0b..5f5473a 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -890,12 +890,14 @@
         self.clearTimeout(this.save_timer);
 
         // all checks passed, send message
-        var form = this.gui_objects.messageform,
+        var lang = this.spellcheck_lang(),
+          form = this.gui_objects.messageform,
           msgid = this.set_busy(true, 'sendingmessage');
 
         form.target = 'savetarget';
         form._draft.value = '';
         form.action = this.add_url(form.action, '_unlock', msgid);
+        form.action = this.add_url(form.action, '_lang', lang);
         form.submit();
 
         // clear timeout (sending could take longer)
@@ -3004,6 +3006,18 @@
     this.enable_command('spellcheck', this.spellcheck_ready);
   };
 
+  // get selected language
+  this.spellcheck_lang = function()
+  {
+    var ed;
+    if (window.tinyMCE && (ed = tinyMCE.get(this.env.composebody)) && ed.plugins.spellchecker) {
+      return ed.plugins.spellchecker.selectedLang;
+    }
+    else if (this.env.spellcheck) {
+      return GOOGIE_CUR_LANG;
+    }
+  };
+
   this.set_draft_id = function(id)
   {
     $("input[name='_draft_saveid']").val(id);
diff --git a/program/js/googiespell.js b/program/js/googiespell.js
index 22716c4..d6aea48 100644
--- a/program/js/googiespell.js
+++ b/program/js/googiespell.js
@@ -10,8 +10,8 @@
 	    Aleksander Machniak - alec [at] alec.pl
 */
 
-var SPELL_CUR_LANG = null;
-var GOOGIE_DEFAULT_LANG = 'en';
+var GOOGIE_CUR_LANG,
+    GOOGIE_DEFAULT_LANG = 'en';
 
 function GoogieSpell(img_dir, server_url) {
     var ref = this,
@@ -260,9 +260,9 @@
         	    ref.resumeEditingState();
     	    } else {
         	    if (!ref.custom_no_spelling_error)
-		        ref.flashNoSpellingErrorState();
-        	else
-            	ref.custom_no_spelling_error(ref);
+	    	        ref.flashNoSpellingErrorState();
+            	else
+                	ref.custom_no_spelling_error(ref);
     	    }
     	    ref.removeIndicator();
 	    }
diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc
index de971a2..8054304 100644
--- a/program/steps/mail/sendmail.inc
+++ b/program/steps/mail/sendmail.inc
@@ -413,7 +413,7 @@
   if ($CONFIG['spellcheck_before_send'] && $CONFIG['enable_spellcheck']
     && empty($_SESSION['compose']['spell_checked'])
   ) {
-    $spellchecker = new rcube_spellchecker();
+    $spellchecker = new rcube_spellchecker(get_input_value('_lang', RCUBE_INPUT_GPC));
     $spell_result = $spellchecker->check($message_body, $isHtml);
 
     $_SESSION['compose']['spell_checked'] = true;

--
Gitblit v1.9.1