Skip to content

Commit 1f2573b

Browse files
committed
feat(i18n): integrate i18nText for copy button accessibility labels #8
1 parent 02f3b73 commit 1f2573b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

assets/js/components/copyClipboard.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { i18nText } from './i18nText.js'
2+
13
const blocks = document.querySelectorAll('pre > code')
24

35
function addCopyButtons () {
@@ -10,14 +12,14 @@ function addCopyButtons () {
1012
button.className = 'code-copy'
1113

1214
button.setAttribute('data-tts', 'up-right')
13-
button.setAttribute('aria-label', 'Copiar')
15+
button.setAttribute('aria-label', i18nText('copy'))
1416
button.innerHTML = '<svg class="i i-copy" viewBox="0 0 24 24"><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path><rect width="13" height="13" x="9" y="9" rx="2"></rect></svg>'
1517
button.addEventListener('click', function () {
1618
clipboard.writeText(codeBlock.textContent).then(function () {
1719
button.blur()
18-
button.setAttribute('aria-label', 'Copiado!')
20+
button.setAttribute('aria-label', i18nText('copied'))
1921
setTimeout(function () {
20-
button.setAttribute('aria-label', 'Copiar')
22+
button.setAttribute('aria-label', i18nText('copy'))
2123
}, 2000)
2224
})
2325
})

0 commit comments

Comments
 (0)