diff options
Diffstat (limited to 'src/utils/helpers/prism.ts')
| -rw-r--r-- | src/utils/helpers/prism.ts | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/utils/helpers/prism.ts b/src/utils/helpers/prism.ts index 86c8f7d..7f10dc9 100644 --- a/src/utils/helpers/prism.ts +++ b/src/utils/helpers/prism.ts @@ -1,4 +1,4 @@ -import { t } from '@lingui/macro'; +import { IntlShape } from 'react-intl'; /** * Check if the current block has a defined language. @@ -39,13 +39,25 @@ export const addPrismClasses = () => { /** * Translate the PrismJS Copy to clipboard button. */ -export const translateCopyButton = (locale: string) => { +export const translateCopyButton = (locale: string, intl: IntlShape) => { const articles = document.getElementsByTagName('article'); + const copyText = intl.formatMessage({ + defaultMessage: 'Copy', + description: 'Prism: copy button text (no clicked)', + }); + const copiedText = intl.formatMessage({ + defaultMessage: 'Copied!', + description: 'Prism: copy button text (clicked)', + }); + const errorText = intl.formatMessage({ + defaultMessage: 'Use Ctrl+c to copy', + description: 'Prism: error text', + }); Array.from(articles).forEach((article) => { article.setAttribute('lang', locale); - article.setAttribute('data-prismjs-copy', t`Copy`); - article.setAttribute('data-prismjs-copy-success', t`Copied!`); - article.setAttribute('data-prismjs-copy-error', t`Use Ctrl+c to copy`); + article.setAttribute('data-prismjs-copy', copyText); + article.setAttribute('data-prismjs-copy-success', copiedText); + article.setAttribute('data-prismjs-copy-error', errorText); }); }; |
