简体   繁体   English

TinyMCE Spellchecker Rails 不工作

[英]TinyMCE Spellchecker Rails not working

I am currently using the tinymce-rails gem found here https://github.com/spohlenz/tinymce-rails and I am having trouble getting the spellchecker to initialize.我目前正在使用https://github.com/spohlenz/tinymce-rails 中的 tinymce-rails gem,但在初始化拼写检查器时遇到了问题。 The TinyMCE editor works fine otherwise.否则 TinyMCE 编辑器工作正常。

Javascript: Javascript:

tinyMCE.init({
  mode: "specific_textareas",
  editor_selector: "tinymce",
  theme: "advanced",
  theme_advanced_toolbar_location: "top",
  theme_advanced_toolbar_align: "left",
  theme_advanced_statusbar_location: "bottom",
  theme_advanced_buttons1: "bold,italic,underline,bullist,numlist",
  theme_advanced_buttons3: "tablecontrols,fullscreen,spellchecker",
  plugins: "table,autoresize,fullscreen,spellchecker",
  width: "100%",
  height: 400,
  autoresize_min_height: 400,
  autoresize_max_height: 800,
  language:"en",
  spellchecker_languages: "+English=en"
});

The erb <%= f.text_area :completed, :class => "tinymce", :size => 500 %> generates the following: erb <%= f.text_area :completed, :class => "tinymce", :size => 500 %>生成以下内容:

<body id="tinymce" class="mceContentBody " contenteditable="true" onload="window.parent.tinyMCE.get('report_completed').onLoad.dispatch();" spellcheck="false" style="overflow-y: hidden; padding-bottom: 50px;" dir="ltr">

I note that the spellcheck field is false, but I'm not sure why, or if that is actually related to what the problem is.我注意到拼写检查字段是错误的,但我不确定为什么,或者这是否与问题有关。

This post , and this post suggest that it's a bit more involved than just adding it to the list of plugins & setting the language. 这篇文章这篇文章表明它比将它添加到插件列表和设置语言要复杂一些。

Both posts suggest using aspell to check spellings, adding the line :spellchecker_rpc_url => "/users/spellchecker", to the TinyMCE configuration, and writing some custom Controller code.aspell文章都建议使用aspell来检查拼写,将:spellchecker_rpc_url => "/users/spellchecker",到 TinyMCE 配置中,并编写一些自定义控制器代码。

I hope those links help you out.我希望这些链接可以帮助您。

Possible duplicate: TinyMCE 4.0.5 spell check not working可能重复: TinyMCE 4.0.5 拼写检查不起作用

According to what I've found elsewhere, the spellchecker plugin was powered by Google service - which has been retired.根据我在其他地方找到的内容,拼写检查器插件由 Google 服务提供支持 - 该服务已停用。 So at this time there does not appear to be an integrated TinyMCE spellchecker solution.所以此时似乎没有集成的 TinyMCE 拼写检查器解决方案。

However, you CAN enable the browser's built-in spellchecker by doing the following:但是,您可以通过执行以下操作来启用浏览器的内置拼写检查器:

tinymce.init({
    browser_spellcheck : true,
});

Be sure to remove spellchecker from your toolbar and your plugins list.请务必从工具栏和插件列表中删除拼写检查器。

I've managed to easily get as-you-type-check working, just by adding this to my config/tinymce.yml我已经设法轻松地让 as-you-type-check 工作,只需将它添加到我的config/tinymce.yml

browser_spellcheck:
  - true

I ended up using the suggestions in one of @James Chevalier's links and following the TinyMCE v4 docs to write this:我最终使用了@James Chevalier 链接之一中的建议,并按照TinyMCE v4 文档编写了以下内容:

# config/routes.rb

post 'tinymce/spellcheck'
# app/controllers/tinymce_controller.rb

class TinymceController < ApplicationController
  skip_forgery_protection

  respond_to :json

  def spellcheck
    suggestions = check_spelling_new(
      spellcheck_params[:text],
      spellcheck_params[:lang]
    )

    render json: {words: suggestions}
  end

  private

  def spellcheck_params
    params.permit(:method, :lang, :text)
  end

  def check_spelling_new(text, lang)
    suggestions = {}

    spell_check_response = `echo "#{text}" | aspell -a -l #{lang}`

    if spell_check_response.present?
      spelling_errors = spell_check_response.split(' ').slice(1..-1)

      spelling_errors.length.times do |i|
        spelling_errors[i].strip!

        if spelling_errors[i].to_s.start_with?('&')
          match_data = spelling_errors[i + 1]
          suggestion_count = spelling_errors[i + 2].to_i

          suggestions[match_data] ||= []

          suggestion_count.times do |k|
            suggestions[match_data] << spelling_errors[i + k + 4].gsub(',', '')
          end
        end
      end
    end

    suggestions
  end
end

// tinymce.js

tinymce.init({
  ...,
  spellchecker_rpc_url: '.../tinymce/spellcheck'
});

You must have aspell and the required dictionaries installed, of course.当然,您必须安装aspell和所需的词典。

I don't recommend doing it for new projects, do what @wloescher and @Ruby Racer said.我不建议为新项目这样做,按照@wloescher 和@Ruby Racer 所说的去做。 I've only done this for a legacy project that must support it.我只为一个必须支持它的遗留项目完成了这项工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM