Description
A page translation plugin powered by a large translation model that provides webpage translation. With the JSSDK, you can add multilingual support to your website in one click.
How it works

Integrate the JSSDK
Current version
Item | Value |
|---|---|
Version |
|
CDN root path |
|
3.0.1. When you upgrade, replace the version number in the CDN links accordingly.
The SDK provides two translation modes:
- Page translation (
pageTranslate): directly replaces the source text on the page with the translation, ideal for monolingual display. - Side-by-side paragraph translation (
paragraphTranslate): inserts the translation after the source text, ideal for reading the source text and translation side by side.
- Lazy-load translation (only translates the visible area)
- Dynamic content translation (automatically translates after DOM changes)
- Glossaries and translation memory
- Fine-grained hooks (insert custom logic before and after translation)
Installation
Load the SDK from the CDN with a script tag. Two methods are supported:
Method 1: Full bundle (recommended for getting started)
Include index.js once (it contains the core and all plugins) to use both page translation and side-by-side translation:
File | Description | URL |
|---|---|---|
| Full bundle (core + plugins) | https://g.alicdn.com/code/npm/@alife/translate-js-sdk/3.0.1/index.js |
Method 2: On-demand imports
Load core.js first, then load the plugin scripts you need:
File | Description | URL |
|---|---|---|
| Core SDK | https://g.alicdn.com/code/npm/@alife/translate-js-sdk/3.0.1/core.js |
| Page translation plugin | https://g.alicdn.com/code/npm/@alife/translate-js-sdk/3.0.1/page.js |
| Side-by-side translation plugin | https://g.alicdn.com/code/npm/@alife/translate-js-sdk/3.0.1/paragraph.js |
- The full bundle requires only one file. With on-demand imports, load
core.jsfirst, then the plugins. - The global object is
window.AliTranslate, with the aliaswindow.__AliTranslate(both refer to the same instance).
Quick start
Page translation (Pure Page)
Side-by-side paragraph translation (Paragraph Compare)
SDK configuration parameters (SDKConfig)
The following SDK-level parameters are shared by AliTranslate.pageTranslate / AliTranslate.paragraphTranslate:
Parameter | Type | Required | Description |
|---|---|---|---|
|
| Yes | Authentication signing function that returns a signed request ready to call the translation service |
|
| No | Glossary that improves the consistency of domain terms |
|
| No | Translation memory |
|
| No | Business domain (passed through to the translation request) |
|
| No | Chunk size threshold (affects request batching and throughput) |
|
| No | Maximum number of retries after a translation failure |
|
| No | Callback invoked when translation is complete |
PageTranslateConfig parameters
Parameter | Type | Required | Description |
|---|---|---|---|
|
| Yes | Target language |
|
| No | Source language. If not specified, the language is automatically detected. |
|
| No | Translation root node. The default value is |
|
| No | Excluded nodes (once matched, the entire subtree is not translated) |
|
| No | Element attributes that support translation |
|
| No | Whether to enable lazy-load translation |
|
| No | Viewport offset for lazy loading (px) |
|
| No | Lazy translation selectors (reserved field in the current version; prefer |
|
| No | Whether to watch for DOM changes and translate automatically |
|
| No | Initialization wait / dynamic translation throttle delay (ms) |
|
| No | Page translation rules (applied to the source text container) |
|
| No | Callback invoked before the translation is inserted |
|
| No | Callback invoked when translation of a node starts |
|
| No | Callback invoked when translation of a node ends |
ParagraphTranslateConfig parameters
Parameter | Type | Required | Description |
|---|---|---|---|
|
| Yes | Target language |
|
| No | Source language. If not specified, the language is automatically detected. |
|
| No | Translation root node. The default value is |
|
| No | Excluded nodes (once matched, not included in paragraph extraction) |
|
| No | Element attributes that support translation |
|
| No | Whether to enable lazy-load translation |
|
| No | Viewport offset for lazy loading (px) |
|
| No | Lazy translation selectors (reserved field in the current version; prefer |
|
| No | Whether to watch for DOM changes and translate automatically |
|
| No | Initialization wait / dynamic translation throttle delay (ms) |
|
| No | Forces translations to be inserted as blocks (on their own line) |
|
| No | Forces translations to be inserted inline (on the same line) |
|
| No | Style rules for side-by-side translation |
|
| No | Callback invoked before |
|
| No | Callback invoked when translation of a paragraph starts |
|
| No | Callback invoked when translation of a paragraph ends |
TransStyleRule
Hooks and rollback-safe DOM changes
The SDK provides a mutator (a reversible change operator) for safe DOM operations in hooks. Changes made through it are automatically rolled back when removeTranslations() is called.
mutator capabilities:
setStyle(el, prop, value, priority?)addClass(el, className)removeClass(el, className)appendNode(parent, node)removeNode(node)
Languages and enum values
Common language values:
auto(automatic detection)zh,en,ja,ko,fr,de,es,ru,ar,th,vi
LANGUAGE type definition in the SDK.
Common APIs
Full example (side-by-side translation + rules + hooks)
To support both page translation and side-by-side paragraph translation, we recommend using the full
index.js bundle and clearly separating the switching and cleanup flows of the two modes in your business UI.
Implement a token service
Sign requests using the V3 request body & signature mechanism of the Alibaba Cloud SDK.
Best practices for production
- Required
getToken: complete authentication signing on your backend before sending translation requests. - Choose one import method: the full
index.jsbundle is sufficient. With on-demand imports, page translation requirespage.js, and side-by-side translation requiresparagraph.js. - Clean up before re-translating: before switching parameters or languages multiple times, call
removeTranslations()first to prevent stale state from interfering with the new configuration. - Keep target and exclude selectors narrow: scope
targetSelectorsto your business containers, and useexcludeSelectorsto exclude navigation, code blocks, editing areas, and similar regions. - Avoid translating sensitive areas, such as input fields, editors, business script nodes, and template containers.
- Avoid heavy logic in hooks:
onTranslatingStart/Endfire frequently. Avoid expensive operations that block the main thread. - Recommended for dynamic content: enable
dynamicto support lazily rendered and streaming pages.
FAQ
Translation has no effect
- Check that the scripts are loaded correctly (the full
index.js, orcore.jsplus the required plugin). - Check that
targetSelectorsmatch elements on the page. - Check that
excludeSelectorsdo not accidentally exclude the target area. - Check that the signing API returns a valid request structure.
rules / hooks do not take effect
- Make sure the parameters are passed at the same level as
pageTranslate/paragraphTranslate. - Call
removeTranslations()before translating again. - Check that
selectormatches the paragraphcommonAncestoror one of its ancestors.
The loading indicator is not visible
- When translation is fast, the indicator disappears instantly. Set a minimum visible duration (for example, 300-500 ms) on your side.
- Use
data-source-hashas a unique identifier to prevent concurrent paragraphs from overwriting each other.
Where do I get the AK/SK?
- Obtain them from the AccessKey module of the Alibaba Cloud platform.
Where do I get the workspaceId for the token service?
- Log in to the Alibaba Cloud account that the AK/SK belongs to, and find the workspace details in the lower-left corner of the Model Studio console.
- The workspace ID in the pop-up window is the required workspaceId. Click the copy icon to the right of the field to copy it directly.
API permission error
- Tongyi Multimodal Translation is not activated: use the Alibaba Cloud primary account that owns the AK to activate the service in Model Studio.
Change log
March 2026
Version | Release date | Description |
3.0.1 | August 6, 2026 | Support for translating page element attribute content (configuration parameter) |
3.0.0 | July 16, 2026 | Major version upgrade: added on-demand imports, glossary/corpus/domain configuration, style overrides, and more configuration parameters |
2.0.6 | March 5, 2026 | Added the |