aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-02-08 15:12:34 +0100
committerArmand Philippot <git@armandphilippot.com>2022-02-08 15:13:41 +0100
commit5597ff486dba9d0ea9fb4a0acfdb73c690859147 (patch)
tree0f1774a7be5616363790a0dba9246cb55c1d98f1 /src/utils
parent5d79523eba4ec0a89668b904dc7896c843ab8dd6 (diff)
chore(prism): translate color scheme toggle button
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/helpers/prism.ts21
1 files changed, 21 insertions, 0 deletions
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);
+ });
+};