@schukai/monster 3.27.0 → 3.28.0
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
|
@@ -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
|
-
|
|
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
|
|
313
|
-
|
|
314
|
-
|
|
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
|
|
107
|
+
// special handling for zero count
|
|
108
108
|
if (r.hasOwnProperty("zero")) {
|
|
109
109
|
return validateString(r["zero"]);
|
|
110
110
|
}
|
package/source/types/version.mjs
CHANGED
package/test/cases/monster.mjs
CHANGED