@openremote/or-translate 1.8.0-snapshot.20250725070921 → 1.8.0-snapshot.20250725120000
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 +66 -66
- package/dist/umd/index.bundle.js +10 -10
- package/dist/umd/index.bundle.js.map +1 -1
- package/dist/umd/index.js +10 -10
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/index.orbundle.js +10 -10
- package/dist/umd/index.orbundle.js.map +1 -1
- package/lib/index.js +42 -11
- package/lib/translate-mixin.js +47 -1
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -1,11 +1,42 @@
|
|
|
1
|
-
var __decorate=this&&this.__decorate
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { translate } from "./translate-mixin";
|
|
8
|
+
import i18next from "i18next";
|
|
9
|
+
import { LitElement, html, css } from "lit";
|
|
10
|
+
import { customElement, property } from "lit/decorators.js";
|
|
11
|
+
export { i18next };
|
|
12
|
+
export { translate };
|
|
13
|
+
let OrTranslate = class OrTranslate extends translate(i18next)(LitElement) {
|
|
14
|
+
render() {
|
|
15
|
+
return html `
|
|
16
|
+
${this._getTranslatedValue()}
|
|
17
|
+
`;
|
|
18
|
+
}
|
|
19
|
+
_getTranslatedValue() {
|
|
20
|
+
return this.value ? i18next.isInitialized ? i18next.t(this.value, this.options) : this.value : "";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
OrTranslate.styles = css `
|
|
24
|
+
:host {
|
|
25
|
+
display: inline-block;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
:host([hidden]) {
|
|
29
|
+
display: none;
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
__decorate([
|
|
33
|
+
property({ type: String })
|
|
34
|
+
], OrTranslate.prototype, "value", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
property({ type: Object })
|
|
37
|
+
], OrTranslate.prototype, "options", void 0);
|
|
38
|
+
OrTranslate = __decorate([
|
|
39
|
+
customElement("or-translate")
|
|
40
|
+
], OrTranslate);
|
|
41
|
+
export { OrTranslate };
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
package/lib/translate-mixin.js
CHANGED
|
@@ -1 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
// TODO: Can't currently export declaration files with explicit LitElement type (see https://github.com/Microsoft/TypeScript/issues/17293)
|
|
2
|
+
export const translate = (i18next) => (base) => class extends base {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this._i18nextJustInitialized = false;
|
|
6
|
+
this.initCallback = (options) => {
|
|
7
|
+
this._i18nextJustInitialized = true;
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
if (this.requestUpdate) {
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
this.requestUpdate();
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
this.langChangedCallback = () => {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
if (this.requestUpdate) {
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
this.requestUpdate();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
connectedCallback() {
|
|
23
|
+
if (!i18next.language) {
|
|
24
|
+
i18next.on("initialized", this.initCallback);
|
|
25
|
+
}
|
|
26
|
+
i18next.on("languageChanged", this.langChangedCallback);
|
|
27
|
+
if (super.connectedCallback) {
|
|
28
|
+
super.connectedCallback();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
disconnectedCallback() {
|
|
32
|
+
i18next.off("initialized", this.initCallback);
|
|
33
|
+
i18next.off("languageChanged", this.langChangedCallback);
|
|
34
|
+
if (super.disconnectedCallback) {
|
|
35
|
+
super.disconnectedCallback();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
shouldUpdate(changedProps) {
|
|
39
|
+
if (this._i18nextJustInitialized) {
|
|
40
|
+
this._i18nextJustInitialized = false;
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
return super.shouldUpdate && super.shouldUpdate(changedProps);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=translate-mixin.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openremote/or-translate",
|
|
3
|
-
"version": "1.8.0-snapshot.
|
|
3
|
+
"version": "1.8.0-snapshot.20250725120000",
|
|
4
4
|
"description": "Provides a web component for translations using i18next",
|
|
5
5
|
"customElements": "custom-elements.json",
|
|
6
6
|
"main": "dist/umd/index.bundle.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"lit": "^2.0.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@openremote/util": "1.8.0-snapshot.
|
|
25
|
+
"@openremote/util": "1.8.0-snapshot.20250725120000"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|