@schukai/monster 3.27.0 → 3.28.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  import {Embed} from '@schukai/monster/source/i18n/providers/embed.mjs';
2
2
 
3
- // read from scritp tag with id i18n
3
+ // read from script tag with id i18n
4
4
  const translation = new Embed('i18n');
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schukai/monster",
3
- "version": "3.27.0",
3
+ "version": "3.28.0",
4
4
  "description": "Monster is a simple library for creating fast, robust and lightweight websites.",
5
5
  "keywords": [
6
6
  "framework",
@@ -295,25 +295,45 @@ class CustomElement extends HTMLElement {
295
295
  * Before you can use this method, you must have loaded the translations.
296
296
  *
297
297
  * @returns {Monster.DOM.CustomElement}
298
+ * @throws {Error} Cannot find element with translations. Add a translations object to the document.
298
299
  */
299
300
  updateI18n() {
300
-
301
301
  const translations = getDocumentTranslations();
302
302
  if (!translations) {
303
303
  return this;
304
304
  }
305
305
 
306
- const labels = this.getOption("labels");
307
- if (!isIterable(labels)) {
306
+ let labels = this.getOption("labels");
307
+ if (!(isObject(labels) || isIterable(labels))) {
308
308
  return this;
309
309
  }
310
310
 
311
311
  for (const key in labels) {
312
- const text = translations.getText(key, labels[key]);
313
- if (text !== labels[key]) {
314
- this.setOption("labels." + key, text);
312
+ const def = labels[key];
313
+
314
+ if (isString(def)) {
315
+ const text = translations.getText(key, def);
316
+ if (text !== def) {
317
+ this.setOption("labels." + key, text);
318
+ }
319
+ continue;
320
+ } else if (isObject(def)) {
321
+ for (const k in def) {
322
+ const d = def[k];
323
+
324
+ const text = translations.getPluralRuleText(key, k, d);
325
+ if (!isString(text)) {
326
+ throw new Error("Invalid labels definition");
327
+ }
328
+ if (text !== d) {
329
+ this.setOption("labels." + key + "." + k, text);
330
+ }
331
+ }
332
+ continue;
315
333
  }
316
334
 
335
+ throw new Error("Invalid labels definition");
336
+
317
337
  }
318
338
  return this;
319
339
  }
@@ -973,10 +993,10 @@ function registerCustomElement(element) {
973
993
  if (customElements === undefined) {
974
994
  throw new Error("customElements is not supported.");
975
995
  }
976
-
996
+
977
997
  if (customElements.get(element.getTag()) !== undefined) {
978
998
  return;
979
999
  }
980
-
1000
+
981
1001
  customElements.define(element.getTag(), element);
982
1002
  }
@@ -104,7 +104,7 @@ class Translations extends Base {
104
104
  } else {
105
105
  count = validateInteger(count);
106
106
  if (count === 0) {
107
- // special handlig for zero count
107
+ // special handling for zero count
108
108
  if (r.hasOwnProperty("zero")) {
109
109
  return validateString(r["zero"]);
110
110
  }
@@ -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.27.0");
145
+ monsterVersion = new Version("3.28.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.27.0")
10
+ monsterVersion = new Version("3.28.0")
11
11
 
12
12
  let m = getMonsterVersion();
13
13