@openremote/or-translate 1.3.0-snapshot.20250117163129 → 1.3.0-snapshot.20250117163435

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.
@@ -0,0 +1,88 @@
1
+ import { getWcStorybookHelpers } from "wc-storybook-helpers";
2
+ import {i18next, OrTranslate} from "@openremote/or-translate";
3
+ import "@openremote/or-translate";
4
+ import i18nextBackend from "i18next-http-backend";
5
+ import { html } from 'lit';
6
+
7
+ const { events, args, argTypes, template } = getWcStorybookHelpers("or-translate");
8
+
9
+ /** @type { import('@storybook/web-components').Meta } */
10
+ const meta = {
11
+ title: "Playground/or-translate",
12
+ component: "or-translate",
13
+ args,
14
+ argTypes,
15
+ parameters: {
16
+ actions: {
17
+ handles: events
18
+ }
19
+ }
20
+ };
21
+
22
+ /** @type { import('@storybook/web-components').Story } */
23
+ export const Primary = {
24
+ args: {
25
+ value: "monday"
26
+ },
27
+ loaders: [
28
+ async (args) => ({
29
+ orTranslate: await loadOrTranslate(args)
30
+ })
31
+ ],
32
+ parameters: {
33
+ docs: {
34
+ source: {
35
+ code: getExampleCode()
36
+ },
37
+ story: {
38
+ height: '60px'
39
+ }
40
+ }
41
+ },
42
+ render: (args) => html`
43
+ ${template(args)}
44
+ ${template({value: "tuesday"})}
45
+ ${template({value: "wednesday"})}
46
+ ${template({value: "thursday"})}
47
+ ${template({value: "friday"})}
48
+ ${template({value: "saturday"})}
49
+ ${template({value: "sunday"})}
50
+ `
51
+ };
52
+
53
+ /* ------------------------------------------------------- */
54
+ /* UTILITY FUNCTIONS */
55
+ /* ------------------------------------------------------- */
56
+
57
+ function getExampleCode() {
58
+
59
+ //language=javascript
60
+ return `
61
+ import i18nextBackend from "i18next-http-backend"; // optional
62
+ import "@openremote/or-translate";
63
+
64
+ // (OPTIONAL) If not i18next is not initialized yet;
65
+ i18next.use(i18nextBackend).init({lng: 'en', backend: {loadPath: () => "/shared/locales/{{lng}}/{{ns}}.json"}});
66
+
67
+ // in your HTML code use this;
68
+ <or-translate value="monday"></or-translate>
69
+ `
70
+ }
71
+
72
+ /**
73
+ * Initialises {@link OrTranslate}, awaits initialization, and returns the HTML object.
74
+ */
75
+ async function loadOrTranslate(args) {
76
+ console.debug("Loading OrTranslate...");
77
+ const orTranslate = Object.assign(new OrTranslate(), args);
78
+ console.debug("Waiting for i18next initialization...");
79
+ if(window.location.href.includes("localhost")) {
80
+ await i18next.use(i18nextBackend).init({lng: 'en', backend: {loadPath: () => "http://localhost:8080/shared/locales/{{lng}}/or.json"}});
81
+ } else {
82
+ await i18next.use(i18nextBackend).init({lng: 'en', backend: {loadPath: () => "/shared/locales/{{lng}}/or.json"}});
83
+ }
84
+ console.debug("OrTranslate loaded");
85
+ return orTranslate;
86
+ }
87
+
88
+ export default meta;
package/lib/index.d.ts CHANGED
@@ -14,6 +14,20 @@ declare const OrTranslate_base: {
14
14
  readonly isConnected: boolean;
15
15
  };
16
16
  } & typeof LitElement;
17
+ /**
18
+ * # Translate
19
+ * ### `<or-translate>` - `OrTranslate`
20
+ *
21
+ * Utility component that dynamically translates the value attribute using the [i18next](https://www.i18next.com) library. <br />
22
+ * Useful throughout web apps, as it automatically responds to language changes.
23
+ *
24
+ * Based on the selected language in cache, it will look up the `/locales` folder with the `or.json` file, and translate by key. <br />
25
+ * Location of the translation folder;
26
+ * - **OR Manager:** `/manager/src/web/shared/locales/<lang>/app.json`
27
+ * - **Custom projects:** `/ui/app/<your app>/locales/<lang>/app.json`
28
+ *
29
+ * The HTML content is a simple text, with no <span> or similar wrapper.
30
+ */
17
31
  export declare class OrTranslate extends OrTranslate_base {
18
32
  static styles: import("lit").CSSResult;
19
33
  value?: string;
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAC5C,OAAO,OAAiC,MAAM,SAAS,CAAC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AC;AAEjB,OAAO,EAAC,SAAS,EAAC,CAAC;AAEnB;;;;;;;;;;;;;GAaG;AAEI,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,SAAS,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC;IAkBjD,MAAM;QACZ,OAAO,IAAI,CAAA;cACL,IAAI,CAAC,mBAAmB,EAAE;SAC/B,CAAC;IACN,CAAC;IAES,mBAAmB;QACzB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IACtG,CAAC;;AAxBa,kBAAM,GAAG,GAAG,CAAA;;;;;;;;KAQzB,AARmB,CAQlB;AAGK;IADN,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;0CACH;AAGf;IADN,QAAQ,CAAC,EAAC,IAAI,EAAE,MAAM,EAAC,CAAC;4CACc;AAhB9B,WAAW;IADvB,aAAa,CAAC,cAAc,CAAC;GACjB,WAAW,CA2BvB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openremote/or-translate",
3
- "version": "1.3.0-snapshot.20250117163129",
3
+ "version": "1.3.0-snapshot.20250117163435",
4
4
  "description": "Provides a web component for translations using i18next",
5
5
  "main": "dist/umd/index.bundle.js",
6
6
  "module": "lib/index.js",
@@ -20,7 +20,7 @@
20
20
  "lit": "^2.0.2"
21
21
  },
22
22
  "devDependencies": {
23
- "@openremote/util": "1.3.0-snapshot.20250117163129"
23
+ "@openremote/util": "1.3.0-snapshot.20250117163435"
24
24
  },
25
25
  "publishConfig": {
26
26
  "access": "public"