@openremote/or-translate 1.11.0-snapshot.20251030160722 → 1.11.0-snapshot.20251031111902

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openremote/or-translate",
3
- "version": "1.11.0-snapshot.20251030160722",
3
+ "version": "1.11.0-snapshot.20251031111902",
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",
@@ -17,6 +17,7 @@
17
17
  "prepack": "npx rspack"
18
18
  },
19
19
  "author": "OpenRemote",
20
+ "repository": "https://github.com/openremote/openremote",
20
21
  "license": "AGPL-3.0-or-later",
21
22
  "dependencies": {
22
23
  "i18next": "^21.5.3",
@@ -0,0 +1,85 @@
1
+ /*
2
+ * Copyright 2025, OpenRemote Inc.
3
+ *
4
+ * See the CONTRIBUTORS.txt file in the distribution for a
5
+ * full listing of individual contributors.
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU Affero General Public License as
9
+ * published by the Free Software Foundation, either version 3 of the
10
+ * License, or (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU Affero General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Affero General Public License
18
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+ import {setCustomElementsManifest, type Meta, type StoryObj } from "@storybook/web-components";
21
+ import {getStorybookHelpers} from "@wc-toolkit/storybook-helpers";
22
+ import customElements from "../custom-elements.json" with { type: "json" };
23
+ import packageJson from "../package.json" with { type: "json" };
24
+ import i18nextBackend from "i18next-http-backend";
25
+ import {i18next, OrTranslate} from "../src";
26
+ import "../src/index";
27
+
28
+ const tagName = "or-translate";
29
+ type Story = StoryObj;
30
+ setCustomElementsManifest(customElements);
31
+
32
+ const { events, args, argTypes, template } = getStorybookHelpers(tagName);
33
+
34
+ const meta: Meta = {
35
+ title: "Playground/or-translate",
36
+ component: tagName,
37
+ args: args,
38
+ argTypes: argTypes,
39
+ render: storyArgs => template(storyArgs),
40
+ excludeStories: /^[a-z].*/,
41
+ parameters: {
42
+ actions: {
43
+ handles: events
44
+ },
45
+ docs: {
46
+ subtitle: `<${tagName}>`,
47
+ description: "Useful elements for automatically translating text for in UI apps"
48
+ }
49
+ }
50
+ };
51
+
52
+ export const Primary: Story = {
53
+ args: {
54
+ value: "monday"
55
+ },
56
+ loaders: [
57
+ async storyArgs => ({
58
+ orTranslate: await loadOrTranslate(storyArgs.allArgs)
59
+ })
60
+ ]
61
+ };
62
+
63
+ export {customElements, packageJson};
64
+
65
+ /* ------------------------------------------------------- */
66
+ /* UTILITY FUNCTIONS */
67
+ /* ------------------------------------------------------- */
68
+
69
+ /**
70
+ * Initialises {@link OrTranslate}, awaits initialization, and returns the HTML object.
71
+ */
72
+ async function loadOrTranslate(storyArgs: any) {
73
+ console.debug("Loading OrTranslate...");
74
+ const orTranslate = Object.assign(new OrTranslate(), storyArgs);
75
+ console.debug("Waiting for i18next initialization...");
76
+ if(window.location.href.includes("localhost")) {
77
+ await i18next.use(i18nextBackend).init({lng: "en", backend: {loadPath: () => "http://localhost:8080/shared/locales/{{lng}}/or.json"}});
78
+ } else {
79
+ await i18next.use(i18nextBackend).init({lng: "en", backend: {loadPath: () => "/shared/locales/{{lng}}/or.json"}});
80
+ }
81
+ console.debug("OrTranslate loaded");
82
+ return orTranslate;
83
+ }
84
+
85
+ export default meta;