@schukai/monster 3.9.1 → 3.10.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
|
@@ -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 {
|
|
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
|
package/source/types/version.mjs
CHANGED
package/test/cases/monster.mjs
CHANGED