mirror of
https://github.com/ParisNeo/lollms-webui.git
synced 2024-12-24 06:36:37 +00:00
Upgraded localizer
This commit is contained in:
parent
538d22d750
commit
082b81e27d
@ -36,9 +36,15 @@ const localizer = new WebAppLocalizer(translations, localStoragePrefix, language
|
||||
```
|
||||
|
||||
## HTML Usage
|
||||
If your translation is plain text, then use:
|
||||
```html
|
||||
<element data-translate="key"></element>
|
||||
```
|
||||
If your translation contains html, then add data-translate-html entry:
|
||||
```html
|
||||
<element data-translate="key" data-translate-html></element>
|
||||
```
|
||||
|
||||
|
||||
Apply translations: `localizer.apply();`
|
||||
Get the translation of a prompt with options:
|
||||
|
@ -63,6 +63,15 @@ Apply translations to all elements with the `data-translate` attribute.
|
||||
|
||||
### HTML Usage
|
||||
Add the `data-translate` attribute to elements you want to localize:
|
||||
If your translation is plain text, then use:
|
||||
```html
|
||||
<element data-translate="key"></element>
|
||||
```
|
||||
If your translation contains html, then add data-translate-html entry:
|
||||
```html
|
||||
<element data-translate="key" data-translate-html></element>
|
||||
```
|
||||
|
||||
|
||||
```html
|
||||
<h1 data-translate="welcome-message"></h1>
|
||||
|
@ -56,7 +56,13 @@ class WebAppLocalizer {
|
||||
const elements = document.querySelectorAll('[data-translate]');
|
||||
elements.forEach(element => {
|
||||
const key = element.getAttribute('data-translate');
|
||||
const useHTML = element.hasAttribute('data-translate-html');
|
||||
|
||||
if (useHTML) {
|
||||
element.innerHTML = this.translate(key);
|
||||
} else {
|
||||
element.textContent = this.translate(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user