diff --git a/dist/index.js b/dist/index.js index 3bf0d3b..7e29965 100644 --- a/dist/index.js +++ b/dist/index.js @@ -299,6 +299,16 @@ class LiveTranslatorManager { badge.addEventListener('mouseleave', () => this.hideBox()); badges.push(badge); cacheKeyParts.push(meta.path); + if (attribute.name === 'href') { + node.onclick = (ev) => { + ev.stopPropagation(); + ev.preventDefault(); + const clone = node.cloneNode(); + const href = ZeroWidthEncoder.cleanString(clone.getAttribute('href')); + clone.setAttribute('href', href); + clone.click(); + }; + } } } if (badges.length) { diff --git a/package-lock.json b/package-lock.json index 2ef2bd7..065e6c5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vue-i18n-live-translator-plugin", - "version": "1.1.1", + "version": "1.1.10", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "vue-i18n-live-translator-plugin", - "version": "1.1.1", + "version": "1.1.10", "license": "MIT", "devDependencies": { "@babel/types": "^7.23.6", diff --git a/src/demo/App.vue b/src/demo/App.vue index 5696ede..7e2323b 100644 --- a/src/demo/App.vue +++ b/src/demo/App.vue @@ -45,8 +45,10 @@
{{ t('LTPlugin.ListItemN', [i]) }}

Attribute

- +

HREF attribute

+ {{ t('LTPlugin.Link.Title') }}

Absolute position

@@ -142,7 +144,6 @@ function dragEnd() { } .image { - width: 80%; border-radius: 8px; } diff --git a/src/demo/lang/en.json b/src/demo/lang/en.json index 4034613..bbc26e2 100644 --- a/src/demo/lang/en.json +++ b/src/demo/lang/en.json @@ -13,6 +13,10 @@ "ListItemN": "Item {0}", "MultipleTitle": "Multiple strings inside one tag", "Draggable": "Drag me around to cover elements", - "PositionAbsolute": "Position is absolute" + "PositionAbsolute": "Position is absolute", + "Link": { + "Href": "https://en.wikipedia.org/", + "Title": "Link to Wikipedia" + } } } diff --git a/src/demo/lang/hu.json b/src/demo/lang/hu.json index e1d5305..96f22ec 100644 --- a/src/demo/lang/hu.json +++ b/src/demo/lang/hu.json @@ -13,6 +13,10 @@ "ListItemN": "Elem {0}", "MultipleTitle": "Több string egy tagen belül", "Draggable": "Mozgass egy elem fölé, hogy eltakard azt", - "PositionAbsolute": "'absolute' pozíció" + "PositionAbsolute": "'absolute' pozíció", + "Link": { + "Href": "https://hu.wikipedia.org/", + "Title": "Link a Wikipediára" + } } } diff --git a/src/index.ts b/src/index.ts index 8301d49..6e99baa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -355,6 +355,17 @@ class LiveTranslatorManager { badge.addEventListener('mouseleave', () => this.hideBox()) badges.push(badge) cacheKeyParts.push(meta.path) + + if (attribute.name === 'href') { + node.onclick = (ev) => { + ev.stopPropagation() + ev.preventDefault() + const clone = node.cloneNode() as HTMLElement + const href = ZeroWidthEncoder.cleanString(clone.getAttribute('href')) + clone.setAttribute('href', href) + clone.click() + } + } } }