@edx/tinymce-language-selector

中文文档
1.1.0发布于 2020/06/30AGPL-3.0-or-laterCommonJS零依赖近 30 天下载 2315

A plugin for TinyMCE 5 that allows the user to specify if text is written in a foreign language and in which language.

原始使用文档

Image

Description

This is a plugin for TinyMCE 5 that allows users to specify what language their text is written in. The plugin wraps the desired text in span tags with a lang attribute for the specified language. Unspecified text is assumed to be written in the page's language. This helps the resulting text comply with WCAG 2.0 3.1.2 Language of Parts: "The human language of each passage or phrase in the content can be programmatically determined..."

The plugin is intended for use as you are creating a new passage. It also works when you need to change the language of an existing passage, but not as well (see below Caveats section for details). For best results, don’t select any text and just change in and out of different language modes while typing.

Installation

This is published as an NPM package.

npm install @edx/tinymce-language-selector

Usage

Import the plugin to add it to TinyMCE's plugin manager:

import '@edx/tinymce-language-selector'

Make sure TinyMCE has already been imported since the plugin needs access to the global tinymce variable.

Then you can use the plugin just like one of TinyMCE's builtin plugins. When configuring TinyMCE, make sure to modify extended_valid_elements to allow span tags with the lang attribute or the id attribute and to strip empty span tags:

extended_valid_elements: 'span[lang|id] -span'

Development

We are leveraging the semantic release workflow to create new versions and release packages to npm.

Caveats

  • The repo currently doesn't contain any unit tests due to how specific TinyMCE's testing framework is to itself. It has only been tested manually so far.
  • One known limitation is that you can't select and change the language of text that goes across multiple HTML tags (besides formatting). An error will be raised to the user. You can select and change the language of anything smaller than a paragraph, provided the paragraph does not contain any language spans inside of it already.
  • There wasn’t a TinyMCE-endorsed way of changing the button text, so we directly modify the innerText of the button node. I’m not sure how well this will work with internationalization and non-default styling.

版本与发布记录

@edx/tinymce-language-selector 共发布 1 个版本,首次发布于 2020/06/30;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.0latest2020/06/306 年前

关于 @edx/tinymce-language-selector 的常见问题

@edx/tinymce-language-selector 是什么?

A plugin for TinyMCE 5 that allows the user to specify if text is written in a foreign language and in which language.

如何安装 @edx/tinymce-language-selector?

在项目目录运行 npm install @edx/tinymce-language-selector,或使用 pnpm add / yarn add / bun add。

@edx/tinymce-language-selector 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/edx__tinymce-language-selector 是否存在。

@edx/tinymce-language-selector 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@edx/tinymce-language-selector 可以商用吗?

@edx/tinymce-language-selector 使用 AGPL-3.0-or-later 许可。最严格的 Copyleft:除分发外,通过网络向用户提供基于它的服务也需要开源对应源码。闭源 SaaS 使用前务必评估。以上为概括,不构成法律意见,请以许可原文为准。

@edx/tinymce-language-selector 的下载量有多少?

根据 npm 官方下载统计,@edx/tinymce-language-selector 在 2026/10/13 – 2026/11/11 这 30 天内被下载 2,315 次,日均约 77 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@edx/tinymce-language-selector 还在维护吗?

最新版本 1.1.0 发布于 2020/06/30(6 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/06/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。