简体   繁体   English

如何在 Quilljs (React) 中更改拼写检查语言

[英]How to change the spellcheck language in Quilljs (React)

How do you change the language of the spellchecker in quill.js in React?你如何在 React 中更改 quill.js中拼写检查器的语言?

My app allows the user to edit content in either English or Spanish, saving results into different locations in the database.我的应用程序允许用户编辑英语或西班牙语的内容,将结果保存到数据库中的不同位置。 When loading English text, the spellcheck is great - but when loading the Spanish text the entire content is spellchecked as English.加载英文文本时,拼写检查很棒——但在加载西班牙文本时,整个内容都被拼写为英文。 There must be a way to change that on the fly...?必须有一种方法可以即时改变它......?

This Stack Overflow answer shows how to disable the spellchecker entirely, but I cannot find information regarding switching to different languages. 此堆栈溢出答案显示了如何完全禁用拼写检查器,但我找不到有关切换到不同语言的信息。

Please also provide the source link where you found the info because I've been searching and didn't see it.还请提供您找到信息的源链接,因为我一直在搜索但没有看到它。

As seen per the quilljs source it seems that the container is just a plain HTML DOM Reference and the attribute you have to set in order to disable spellcheck is from the HTML Standard, so we can infer that the spellcheck job is taken by the browser and not by quill.quilljs 源代码中可以看出,容器似乎只是一个普通的 HTML DOM 引用,为了禁用拼写检查而必须设置的属性来自 HTML 标准,因此我们可以推断拼写检查作业是由浏览器执行的,并且不是羽毛笔。

In this Stack Overflow answer's update it is stated that the spellchecking respects the lang attribute of the tags, so what you need to do is set that attribute accordingly to the language it should be using.此 Stack Overflow 答案的更新中,说明拼写检查尊重标签的lang属性,因此您需要做的是根据应使用的语言相应地设置该属性。

A code snipped for a component that I think it may work为我认为可能工作的组件剪下的代码

// For typings
import Quill from "react-quill";
import QuillEditor from "quill"

export const MultiLangQuill = ({ content, onChange, lang }) => {
  const ref = React.useRef<Quill & { editor: QuillEditor }>(null);

  React.useEffect(() => {
    ref.current?.editor.root.setAttribute("lang", lang);
  }, [lang]);

  return (
    <Quill
      // set the ref to access to quill editor
      ref={ref}
      theme="snow"
      value={content}
      onChange={onChange}
      modules={modules}
      formats={formats}
    />
  );
};

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

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