@schukai/monster 3.9.1 → 3.10.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schukai/monster",
3
- "version": "3.9.1",
3
+ "version": "3.10.0",
4
4
  "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
5
5
  "keywords": [
6
6
  "framework",
@@ -11,7 +11,7 @@ import { Pathfinder } from "../data/pathfinder.mjs";
11
11
 
12
12
  import { parseDataURL } from "../types/dataurl.mjs";
13
13
  import { getGlobalObject } from "../types/global.mjs";
14
- import { isArray, isFunction, isObject, isString } from "../types/is.mjs";
14
+ import {isArray, isFunction, isIterable, isObject, isString} from "../types/is.mjs";
15
15
  import { Observer } from "../types/observer.mjs";
16
16
  import { ProxyObserver } from "../types/proxyobserver.mjs";
17
17
  import { validateFunction, validateInstance, validateObject, validateString } from "../types/validate.mjs";
@@ -27,6 +27,7 @@ import {
27
27
  import { findDocumentTemplate, Template } from "./template.mjs";
28
28
  import { addObjectWithUpdaterToElement } from "./updater.mjs";
29
29
  import { instanceSymbol } from "../constants.mjs";
30
+ import {getDocumentTranslations, Translations} from "../i18n/translations.mjs";
30
31
 
31
32
  export {
32
33
  CustomElement,
@@ -281,6 +282,39 @@ class CustomElement extends HTMLElement {
281
282
  };
282
283
  }
283
284
 
285
+
286
+ /**
287
+ * This method updates the labels of the element.
288
+ * The labels are defined in the options object.
289
+ * The key of the label is used to retrieve the translation from the document.
290
+ * If the translation is different from the label, the label is updated.
291
+ *
292
+ * Before you can use this method, you must have loaded the translations.
293
+ *
294
+ * @returns {Monster.DOM.CustomElement}
295
+ */
296
+ updateI18n() {
297
+
298
+ const translations = getDocumentTranslations();
299
+ if (!translations) {
300
+ return this;
301
+ }
302
+
303
+ const labels = this.getOption("labels");
304
+ if(!isIterable(labels)){
305
+ return this;
306
+ }
307
+
308
+ for (const key in labels) {
309
+ const text = translations.getText(key, labels[key]);
310
+ if (text !== labels[key]) {
311
+ this.setOption("labels." + key, text);
312
+ }
313
+
314
+ }
315
+ return this;
316
+ }
317
+
284
318
  /**
285
319
  * There is no check on the name by this class. the developer is responsible for assigning an appropriate tag.
286
320
  * if the name is not valid, registerCustomElement() will issue an error
@@ -293,6 +327,7 @@ class CustomElement extends HTMLElement {
293
327
  static getTag() {
294
328
  throw new Error("the method getTag must be overwritten by the derived class.");
295
329
  }
330
+
296
331
 
297
332
  /**
298
333
  * At this point a `CSSStyleSheet` object can be returned. If the environment does not
@@ -142,7 +142,7 @@ function getMonsterVersion() {
142
142
  }
143
143
 
144
144
  /** don't touch, replaced by make with package.json version */
145
- monsterVersion = new Version("3.9.1");
145
+ monsterVersion = new Version("3.10.0");
146
146
 
147
147
  return monsterVersion;
148
148
  }
@@ -7,7 +7,7 @@ describe('Monster', function () {
7
7
  let monsterVersion
8
8
 
9
9
  /** don´t touch, replaced by make with package.json version */
10
- monsterVersion = new Version("3.9.1")
10
+ monsterVersion = new Version("3.10.0")
11
11
 
12
12
  let m = getMonsterVersion();
13
13