From c66d63eccf820b6e3e66ab956ba44a0b0919404a Mon Sep 17 00:00:00 2001 From: Robert Reinhard Date: Wed, 28 Feb 2024 17:43:31 -0800 Subject: [PATCH 1/3] Yarn install side effect --- yarn.lock | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/yarn.lock b/yarn.lock index 87df602..25e8bc1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4805,11 +4805,6 @@ find-up@^4.0.0, find-up@^4.1.0: locate-path "^5.0.0" path-exists "^4.0.0" -flag-icons@^6.2.0: - version "6.4.2" - resolved "https://registry.yarnpkg.com/flag-icons/-/flag-icons-6.4.2.tgz#c608770f55cecf0904ffd17230ca1ec44fa65d53" - integrity sha512-1zlIYDVcn5jQpF5aYWEAeO4WXuLHj4i6lQIZNjn8Kl6rcZperkUj79uHC9OUi2s+IEl9AYskW8JCx83/6KcmLw== - flat@^5.0.0: version "5.0.2" resolved "https://registry.yarnpkg.com/flat/-/flat-5.0.2.tgz#8ca6fe332069ffa9d324c327198c598259ceb241" @@ -10852,7 +10847,7 @@ webpack-dev-middleware@^4.2.0: range-parser "^1.2.1" schema-utils "^3.0.0" -"webpack-graphql-loader@github:gpoitch/graphql-loader#gp/refresh": +webpack-graphql-loader@gpoitch/graphql-loader#gp/refresh: version "1.0.2" resolved "https://codeload.github.com/gpoitch/graphql-loader/tar.gz/42f0f990a6132ccd5e284d0e6cfeade12728dba2" dependencies: From 019d78fb32a1f5bb3d2d4eb6666fda3ad57e00ea Mon Sep 17 00:00:00 2001 From: Robert Reinhard Date: Wed, 28 Feb 2024 17:43:49 -0800 Subject: [PATCH 2/3] Load generated JSON for fetch-translations --- plugins/fetch-translations.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plugins/fetch-translations.js b/plugins/fetch-translations.js index f6de1d1..473d679 100644 --- a/plugins/fetch-translations.js +++ b/plugins/fetch-translations.js @@ -7,6 +7,19 @@ export default async function({ i18n, $craft, $config }, localeCode) { // Get the iso for the selected locale const locale = i18n.locales.find(locale => locale.code == localeCode) + // If JSON files are generated, use them if they exist + if ($config.cloak.i18n.generateJson) { + try { + const response = await fetch(`/i18n/${localeCode}.json`); + if (!response.ok) throw 'Static JSON not found' + return await response.json() + + // If not found, fallback to the CMS + } catch (e) { + console.error(e) + } + } + // Lookup translations given the CMS if ($craft) return await fetchCraftTranslations({ $craft, From 421945d25f60f28cd4011a2ffa7a1f2b12f31ecc Mon Sep 17 00:00:00 2001 From: Robert Reinhard Date: Wed, 28 Feb 2024 19:44:21 -0800 Subject: [PATCH 3/3] Only try and load static JSON on client --- plugins/fetch-translations.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/fetch-translations.js b/plugins/fetch-translations.js index 473d679..685df33 100644 --- a/plugins/fetch-translations.js +++ b/plugins/fetch-translations.js @@ -7,16 +7,18 @@ export default async function({ i18n, $craft, $config }, localeCode) { // Get the iso for the selected locale const locale = i18n.locales.find(locale => locale.code == localeCode) - // If JSON files are generated, use them if they exist - if ($config.cloak.i18n.generateJson) { + // If JSON files are generated and this is being invoked on the client, use + // those JSON files. + if ($config.cloak.i18n.generateJson && process.client) { try { - const response = await fetch(`/i18n/${localeCode}.json`); - if (!response.ok) throw 'Static JSON not found' - return await response.json() + const generateDir = $config._app.basePath || "/"; + const response = await fetch(`${generateDir}i18n/${localeCode}.json`); + if (!response.ok) throw "Static JSON not found"; + return await response.json(); - // If not found, fallback to the CMS + // If not found, fallback to the CMS } catch (e) { - console.error(e) + console.error(e); } }