From 0565c019c77e4c67876dec5bd099a9de4564da30 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Thu, 10 Feb 2022 16:58:45 +0100 Subject: fix(prism): translate toolbar buttons on single article pages The translation was not always loaded the first time. So I decided to put the prism attributes manually instead. --- src/utils/helpers/prism.ts | 49 ---------------------------------------------- 1 file changed, 49 deletions(-) (limited to 'src/utils') diff --git a/src/utils/helpers/prism.ts b/src/utils/helpers/prism.ts index 1004a84..bc84c91 100644 --- a/src/utils/helpers/prism.ts +++ b/src/utils/helpers/prism.ts @@ -1,5 +1,3 @@ -import { IntlShape } from 'react-intl'; - /** * Check if the current block has a defined language. * @param classList - A list of class. @@ -35,50 +33,3 @@ export const addPrismClasses = () => { } }); }; - -/** - * Translate the PrismJS Copy to clipboard button. - */ -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', copyText); - article.setAttribute('data-prismjs-copy-success', copiedText); - article.setAttribute('data-prismjs-copy-error', errorText); - }); -}; - -/** - * Translate the PrismJS color-scheme button. - */ -export const translateToggleButton = (locale: string, intl: IntlShape) => { - const articles = document.getElementsByTagName('article'); - const darkTheme = intl.formatMessage({ - defaultMessage: 'Toggle Dark Theme', - description: 'Prism: toggle dark theme button text', - }); - const lightTheme = intl.formatMessage({ - defaultMessage: 'Toggle Light Theme', - description: 'Prism: toggle light theme button text', - }); - - Array.from(articles).forEach((article) => { - article.setAttribute('lang', locale); - article.setAttribute('data-prismjs-color-scheme-dark', darkTheme); - article.setAttribute('data-prismjs-color-scheme-light', lightTheme); - }); -}; -- cgit v1.2.3