Extensions/Authoring/noTranslate

Extensions add specific functionality to Learnosity APIs. They rely on modules within LT being available.

--

Adds the ability for authors to add translate="no" around content. This is useful for content that should not be translated by Google translate or other translation services such as Learnosity Author Aide.

To remove an inline attribute, highlight the text and use the clear formatting button in the toolbar.

Right now there's no way to remove a block attribute, because they add surrounding <div> elements. The only way is to use the Source window in the rich-text editor.

Adding a custom button is a capability in Author API. Below is a code snippet of an Author API configuration object. Note the custom button is added under rich_text_editor.

You MUST use the object as defined below. Also, note the toolbar_settings which is required to place the custom button(s) where you want in the toolbar.

{
    "config": {
        "dependencies": {
            "question_editor_api": {
                "init_options": {
                    "rich_text_editor": {
                        "customButtons": [
                            {
                                "func": "LT.extensions.noTranslate.addLanguageAttribute",
                                "icon": "https://raw.githubusercontent.com/michaelsharman/LT/refs/heads/main/src/authoring/extensions/ui/noTranslate/assets/icon_no_translate.svg",
                                "label": "Set no translate",
                                "name": "setNoTranslate"
                            }
                        ],
                        "toolbar_settings": {
                            "ltr_toolbar": [
                                {
                                    "items": ["Bold","Italic","Underline","-","TextColor","-", "LrnUnderlinedIndicator","-","RemoveFormat","FontSize"],
                                    "name": "basicstyles"
                                },
                                {
                                    "items": ["NumberedList","BulletedList","-","Indent","Outdent"],
                                    "name": "list"
                                },
                                {
                                    "items": ["JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock"],
                                    "name": "justify"
                                },
                                {
                                    "items": ["Link","Unlink"],
                                    "name": "link"
                                },
                                {
                                    "items": ["Image","LrnMath","Table","Blockquote","SpecialChar"],
                                    "name": "insert"
                                },
                                {
                                    "items": ["LrnSimpleFeature"],
                                    "name": "simplefeature"
                                },
                                {
                                    "items": ["LrnResource"],
                                    "name": "resource"
                                },
                                {
                                    "items": ["LrnEditAriaLabel","LrnPopupContent"],
                                    "name": "editAriaLabel"
                                },
                                {
                                    "name": "custombuttons"
                                },
                                {
                                    "items": ["Undo","Redo"],
                                    "name": "clipboard"
                                },
                                {
                                    "items": ["Styles"],
                                    "name": "style"
                                },
                                {
                                    "items": ["Sourcedialog"],
                                    "name": "mode"
                                },
                                {
                                    "items": ["lrn_datatable"],
                                    "name": "data"
                                }
                            ]
                        }
                    }
                }
            }
        }
    }
}

Methods

addNoTranslate(attribute, callback)

Called via a custom button in the rich text toolbar. Renders a modal asking the author to set inline or block. Then inserts a <span> element for inline or a <div> or <p> element for block with a translate attribute.

Since
2.19.0
Parameters:
Name Type Description
attribute *
callback *

run()

Extension constructor.

Since
2.19.0
Example
import { LT } from '@caspingus/lt/src/authoring/index';

LT.init(authorApp); // Set up LT with the Author API application instance variable
LT.extensions.noTranslate.run();

getLinebreakType(text)

Returns whether the selected text is a single line or multiple lines. From there, we can determine whether to wrap the content in a or

element.

Parameters:
Name Type Description
text string
Returns