diff --git a/application/source/i18n/translations.mjs b/application/source/i18n/translations.mjs index 05227d9741bdf8ac0259e5aafadc7e5f99794eee..f72bc8e1b31b7b19627d705007f5376b5626bdfc 100644 --- a/application/source/i18n/translations.mjs +++ b/application/source/i18n/translations.mjs @@ -190,10 +190,12 @@ class Translations extends Base { /** * Returns the translations for the current document. * - * @param element - * @returns {*} - * @throws {Error} Element is not an HTMLElement - * @throws {Error} Missing translations + * @param {HTMLElement|undefined} [element] - Element to search for translations. Default: element with objectlink @schukai/monster/i18n/translations@@link. + * @returns {Translations} + * @throws {Error} Element is not an HTMLElement. + * @throws {Error} Cannot find element with translations. Add a translations object to the document. + * @throws {Error} This element has no translations. + * @throws {Error} Missing translations. */ function getDocumentTranslations(element) { @@ -201,14 +203,17 @@ function getDocumentTranslations(element) { if (!(element instanceof HTMLElement)) { element = d.querySelector('['+ATTRIBUTE_OBJECTLINK+'~="' + translationsLinkSymbol.toString() + '"]'); + if (element === null) { + throw new Error("Cannot find element with translations. Add a translations object to the document."); + } } if (!(element instanceof HTMLElement)) { - throw new Error("Element is not an HTMLElement"); + throw new Error("Element is not an HTMLElement."); } if (!hasObjectLink(element, translationsLinkSymbol)) { - throw new Error("Missing translations"); + throw new Error("This element has no translations."); } let obj = getLinkedObjects(element, translationsLinkSymbol); @@ -219,7 +224,7 @@ function getDocumentTranslations(element) { } } - throw new Error("Missing translations"); + throw new Error("Missing translations."); }