@tilde-nlp/website-translator 8.3.0-beta → 8.5.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -0
- package/dist/widget.js +1 -1
- package/dist/widget.js.LICENSE.txt +1 -1
- package/package.json +1 -1
- package/src/js/interfaces/IPluginOptions.ts +14 -0
package/README.md
CHANGED
|
@@ -94,6 +94,40 @@ Set `dynamicContentDiscoveryDelayMs` before initialization to accommodate the we
|
|
|
94
94
|
|
|
95
95
|
The same setting applies when `mode` is `"word-count"`. Set it to `0` to complete discovery immediately after the initial pass. Invalid or negative values use the 5000 ms default.
|
|
96
96
|
|
|
97
|
+
## Configure language URL persistence
|
|
98
|
+
|
|
99
|
+
By default, language changes preserve the existing behaviour: the widget stores the selected language in the `lang` query parameter and creates a browser history entry.
|
|
100
|
+
|
|
101
|
+
The `lang` parameter also gives each translated language a distinct URL that search engines can discover. The widget uses these URLs when localizing links and generating canonical and `hreflang` metadata. Use `"push"` or `"replace"` when translated variants should remain discoverable through `?lang=...` URLs.
|
|
102
|
+
|
|
103
|
+
SPAs can update the parameter without adding history entries, or leave routing entirely to the host application:
|
|
104
|
+
|
|
105
|
+
```HTML
|
|
106
|
+
<script>
|
|
107
|
+
// Use "replace" to keep ?lang=lv without creating a history entry.
|
|
108
|
+
WebsiteTranslator.Options.translation.languageUrlMode = "replace";
|
|
109
|
+
|
|
110
|
+
// Use "none" to prevent the widget from reading or writing ?lang and from adding it to links.
|
|
111
|
+
WebsiteTranslator.Options.translation.languageUrlMode = "none";
|
|
112
|
+
</script>
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Use `"none"` only when the host application owns language routing or translated pages should not be indexed separately. When using `"none"` for indexable translated pages, the host application must provide stable localized URLs and the corresponding canonical and `hreflang` metadata. Otherwise, search engines may not discover or correctly associate translated variants.
|
|
116
|
+
|
|
117
|
+
## SPA route translation lifecycle
|
|
118
|
+
|
|
119
|
+
The widget applies the same route lifecycle to `history.pushState`, `history.replaceState`, browser back/forward navigation, and hash-based navigation:
|
|
120
|
+
|
|
121
|
+
1. Invalidate queued, delayed, and in-flight work from the previous route.
|
|
122
|
+
2. Restore translated DOM that remains connected and remove detached translation state.
|
|
123
|
+
3. Reset route-specific discovery and processing state.
|
|
124
|
+
4. Prepare the current DOM for translation and restart dynamic content observation.
|
|
125
|
+
5. Translate content rendered immediately or discovered later by the SPA.
|
|
126
|
+
|
|
127
|
+
Route navigation uses a **restore and reprocess** policy. The widget does not preserve translated markup on elements that survive navigation because the host framework may reuse or mutate those elements as part of rendering the new route. Restoring source markup first gives the framework and the next discovery pass a consistent DOM.
|
|
128
|
+
|
|
129
|
+
Translation strings are cached by source content, item type, attribute, and target language. Route changes retain this cache, so unchanged content can be reapplied without another translation API request. Explicit language changes start a fresh translation execution and clear the cache. Source-language and third-party-language routes only invalidate and restore widget state; they do not start widget translation observation.
|
|
130
|
+
|
|
97
131
|
# Browser support
|
|
98
132
|
|
|
99
133
|
<!--
|