From 3c131cf957246ab6c66ee1a0ed8b4492fafed453 Mon Sep 17 00:00:00 2001
From: Rob B <computerguy440+gh@gmail.com>
Date: Wed, 15 Nov 2023 15:55:48 -0500
Subject: [PATCH] chore: make cookie consent translatable, but it seems to load
 before the user's language selection (#98)

* chore: make cookie consent translatable, but it seems to load before the user's language selection

* chore: delay cookieconsent appearance until tolgee load complete
---
 cspell.json               |  2 +-
 src/routes/+layout.svelte | 38 +++++++++++++++++++++++---------------
 2 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/cspell.json b/cspell.json
index 61a19132a..7709a7d28 100644
--- a/cspell.json
+++ b/cspell.json
@@ -5,7 +5,7 @@
   // language - current active spelling language
   "language": "en",
   // words - list of words to be always considered correct
-  "words": ["cfworker", "felte", "ficsit", "pnpx", "prismjs", "urql", "webp", "wonka"],
+  "words": ["cfworker", "felte", "ficsit", "pnpx", "prismjs", "smui", "tolgee", "urql", "webp", "wonka"],
   // flagWords - list of words to be always considered incorrect
   // This is useful for offensive words and common spelling errors.
   // cSpell:disable (don't complain about the words we listed here)
diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte
index 9dc5fa196..00f75ff1a 100644
--- a/src/routes/+layout.svelte
+++ b/src/routes/+layout.svelte
@@ -69,22 +69,30 @@
 
       await import('cookieconsent/src/cookieconsent');
 
-      if ('cookieconsent' in window) {
-        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
-        // @ts-ignore
-        window.cookieconsent.initialise({
-          palette: {
-            popup: {
-              background: '#000'
+      tolgee.on('initialLoad', () => {
+        if ('cookieconsent' in window) {
+          // eslint-disable-next-line @typescript-eslint/ban-ts-comment
+          // @ts-ignore
+          // cspell:ignore initialise
+          window.cookieconsent.initialise({
+            palette: {
+              popup: {
+                background: '#000'
+              },
+              button: {
+                background: '#f1d600'
+              }
             },
-            button: {
-              background: '#f1d600'
-            }
-          },
-          theme: 'edgeless',
-          position: 'bottom-right'
-        });
-      }
+            content: {
+              message: tolgee.t('cookieconsent.message'),
+              link: tolgee.t('cookieconsent.link'),
+              dismiss: tolgee.t('cookieconsent.dismiss')
+            },
+            theme: 'edgeless',
+            position: 'bottom-right'
+          });
+        }
+      });
 
       customProtocolCheck.set(await import('$lib/thirdparty/custom_protocol'));