Skip to content
Snippets Groups Projects
Verified Commit 4e4450bd authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: add CustomControl.updateI18n()

parent 43635d31
No related branches found
No related tags found
No related merge requests found
...@@ -86,7 +86,7 @@ include $(MAKEFILE_IMPORT_PATH)target-help.mk ...@@ -86,7 +86,7 @@ include $(MAKEFILE_IMPORT_PATH)target-help.mk
include $(MAKEFILE_IMPORT_PATH)target-node-build.mk include $(MAKEFILE_IMPORT_PATH)target-node-build.mk
include $(MAKEFILE_IMPORT_PATH)target-node-test.mk include $(MAKEFILE_IMPORT_PATH)target-node-test.mk
include $(MAKEFILE_IMPORT_PATH)target-npm-publish.mk include $(MAKEFILE_IMPORT_PATH)target-npm-publish.mk
#include $(MAKEFILE_IMPORT_PATH)target-npm.mk include $(MAKEFILE_IMPORT_PATH)target-npm.mk
include $(MAKEFILE_IMPORT_PATH)target-git.mk include $(MAKEFILE_IMPORT_PATH)target-git.mk
#include $(MAKEFILE_IMPORT_PATH)target-init-standard.mk #include $(MAKEFILE_IMPORT_PATH)target-init-standard.mk
#include $(MAKEFILE_IMPORT_PATH)target-init-webcomponent.mk #include $(MAKEFILE_IMPORT_PATH)target-init-webcomponent.mk
......
...@@ -11,7 +11,7 @@ import { Pathfinder } from "../data/pathfinder.mjs"; ...@@ -11,7 +11,7 @@ import { Pathfinder } from "../data/pathfinder.mjs";
import { parseDataURL } from "../types/dataurl.mjs"; import { parseDataURL } from "../types/dataurl.mjs";
import { getGlobalObject } from "../types/global.mjs"; import { getGlobalObject } from "../types/global.mjs";
import { isArray, isFunction, isObject, isString } from "../types/is.mjs"; import {isArray, isFunction, isIterable, isObject, isString} from "../types/is.mjs";
import { Observer } from "../types/observer.mjs"; import { Observer } from "../types/observer.mjs";
import { ProxyObserver } from "../types/proxyobserver.mjs"; import { ProxyObserver } from "../types/proxyobserver.mjs";
import { validateFunction, validateInstance, validateObject, validateString } from "../types/validate.mjs"; import { validateFunction, validateInstance, validateObject, validateString } from "../types/validate.mjs";
...@@ -27,6 +27,7 @@ import { ...@@ -27,6 +27,7 @@ import {
import { findDocumentTemplate, Template } from "./template.mjs"; import { findDocumentTemplate, Template } from "./template.mjs";
import { addObjectWithUpdaterToElement } from "./updater.mjs"; import { addObjectWithUpdaterToElement } from "./updater.mjs";
import { instanceSymbol } from "../constants.mjs"; import { instanceSymbol } from "../constants.mjs";
import {getDocumentTranslations, Translations} from "../i18n/translations.mjs";
export { export {
CustomElement, CustomElement,
...@@ -281,6 +282,39 @@ class CustomElement extends HTMLElement { ...@@ -281,6 +282,39 @@ class CustomElement extends HTMLElement {
}; };
} }
/**
* This method updates the labels of the element.
* The labels are defined in the options object.
* The key of the label is used to retrieve the translation from the document.
* If the translation is different from the label, the label is updated.
*
* Before you can use this method, you must have loaded the translations.
*
* @returns {Monster.DOM.CustomElement}
*/
updateI18n() {
const translations = getDocumentTranslations();
if (!translations) {
return this;
}
const labels = this.getOption("labels");
if(!isIterable(labels)){
return this;
}
for (const key in labels) {
const text = translations.getText(key, labels[key]);
if (text !== labels[key]) {
this.setOption("labels." + key, text);
}
}
return this;
}
/** /**
* There is no check on the name by this class. the developer is responsible for assigning an appropriate tag. * There is no check on the name by this class. the developer is responsible for assigning an appropriate tag.
* if the name is not valid, registerCustomElement() will issue an error * if the name is not valid, registerCustomElement() will issue an error
...@@ -294,6 +328,7 @@ class CustomElement extends HTMLElement { ...@@ -294,6 +328,7 @@ class CustomElement extends HTMLElement {
throw new Error("the method getTag must be overwritten by the derived class."); throw new Error("the method getTag must be overwritten by the derived class.");
} }
/** /**
* At this point a `CSSStyleSheet` object can be returned. If the environment does not * At this point a `CSSStyleSheet` object can be returned. If the environment does not
* support a constructor, then an object can also be built using the following detour. * support a constructor, then an object can also be built using the following detour.
......
...@@ -26,4 +26,9 @@ npm-preview: ...@@ -26,4 +26,9 @@ npm-preview:
$(QUIET) $(NPM) --prefix $(NODE_ROOT_DIR) run preview $(QUIET) $(NPM) --prefix $(NODE_ROOT_DIR) run preview
.PHONY: npm-update-all
## Update Node Components
npm-update-all:
$(ECHOMARKER) "Search and Update recursive all node_modules (npm and pnpm"
$(QUIET) $(FIND) . -type f ! -path '*node_modules*' -iname pnpm-lock.yaml -exec bash -c 'cd $$(dirname {} ) ; pwd; pnpm update -Lr ; cd - ' \;
$(QUIET) $(FIND) . -type f ! -path '*node_modules*' -iname package-lock.json -exec bash -c 'cd $$(dirname {} ) ; pwd; npm install -g npm-check-updates; npx npm-check-updates; npm install ; cd -' \;
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
"clean-jsdoc-theme": "^4.2.3", "clean-jsdoc-theme": "^4.2.3",
"create-polyfill-service-url": "^2.2.6", "create-polyfill-service-url": "^2.2.6",
"crypt": "^0.0.2", "crypt": "^0.0.2",
"esbuild": "^0.17.4", "esbuild": "^0.17.5",
"flow-bin": "^0.198.1", "flow-bin": "^0.199.1",
"fs": "0.0.1-security", "fs": "0.0.1-security",
"graphviz": "^0.0.9", "graphviz": "^0.0.9",
"jsdoc": "^4.0.0", "jsdoc": "^4.0.0",
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment