From 5597ff486dba9d0ea9fb4a0acfdb73c690859147 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 8 Feb 2022 15:12:34 +0100 Subject: chore(prism): translate color scheme toggle button --- src/utils/helpers/prism.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/utils/helpers/prism.ts') diff --git a/src/utils/helpers/prism.ts b/src/utils/helpers/prism.ts index 7f10dc9..1004a84 100644 --- a/src/utils/helpers/prism.ts +++ b/src/utils/helpers/prism.ts @@ -61,3 +61,24 @@ export const translateCopyButton = (locale: string, intl: IntlShape) => { 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