fix(i18n): force service worker update to clear cached translations
This commit is contained in:
parent
a8d2c709f6
commit
e95d91ac6f
2 changed files with 15 additions and 2 deletions
|
|
@ -104,7 +104,12 @@ const I18n = {
|
||||||
const pageResponse = await fetch(`/locales/${lang}/${pageName}.json`);
|
const pageResponse = await fetch(`/locales/${lang}/${pageName}.json`);
|
||||||
let pageTranslations = {};
|
let pageTranslations = {};
|
||||||
if (pageResponse.ok) {
|
if (pageResponse.ok) {
|
||||||
pageTranslations = await pageResponse.json();
|
const responseText = await pageResponse.text();
|
||||||
|
console.log(`[i18n] DEBUG: Fetched ${responseText.length} characters from ${lang}/${pageName}.json`);
|
||||||
|
console.log(`[i18n] DEBUG: Response contains "faqs":`, responseText.includes('"faqs"'));
|
||||||
|
|
||||||
|
pageTranslations = JSON.parse(responseText);
|
||||||
|
console.log(`[i18n] DEBUG: After JSON.parse, pageTranslations has faqs?`, !!pageTranslations.faqs);
|
||||||
} else if (pageName !== 'homepage') {
|
} else if (pageName !== 'homepage') {
|
||||||
// If page-specific translations don't exist, that's okay for some pages
|
// If page-specific translations don't exist, that's okay for some pages
|
||||||
console.warn(`[i18n] No translations found for ${lang}/${pageName}, using common only`);
|
console.warn(`[i18n] No translations found for ${lang}/${pageName}, using common only`);
|
||||||
|
|
@ -114,10 +119,18 @@ const I18n = {
|
||||||
|
|
||||||
// Deep merge common and page-specific translations (page-specific takes precedence)
|
// Deep merge common and page-specific translations (page-specific takes precedence)
|
||||||
// Uses deep merge to preserve nested objects like footer in common.json
|
// Uses deep merge to preserve nested objects like footer in common.json
|
||||||
|
console.log(`[i18n] DEBUG BEFORE MERGE: pageTranslations has faqs?`, !!pageTranslations.faqs, pageTranslations.faqs ? pageTranslations.faqs.length : 0);
|
||||||
|
console.log(`[i18n] DEBUG BEFORE MERGE: pageTranslations keys:`, Object.keys(pageTranslations));
|
||||||
|
|
||||||
this.translations = this.deepMerge(commonTranslations, pageTranslations);
|
this.translations = this.deepMerge(commonTranslations, pageTranslations);
|
||||||
|
|
||||||
|
console.log(`[i18n] DEBUG AFTER MERGE: this.translations has faqs?`, !!this.translations.faqs, this.translations.faqs ? this.translations.faqs.length : 0);
|
||||||
|
console.log(`[i18n] DEBUG AFTER MERGE: this.translations keys:`, Object.keys(this.translations));
|
||||||
|
|
||||||
// Expose translations globally for components like interactive-diagram
|
// Expose translations globally for components like interactive-diagram
|
||||||
window.i18nTranslations = this.translations;
|
window.i18nTranslations = this.translations;
|
||||||
console.log(`[i18n] Loaded translations: common + ${pageName}`);
|
console.log(`[i18n] Loaded translations: common + ${pageName}`);
|
||||||
|
console.log(`[i18n] DEBUG: faqs in window.i18nTranslations?`, !!window.i18nTranslations.faqs, window.i18nTranslations.faqs ? window.i18nTranslations.faqs.length : 0);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`[i18n] Error loading translations:`, error);
|
console.error(`[i18n] Error loading translations:`, error);
|
||||||
// Fallback to English if loading fails
|
// Fallback to English if loading fails
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
* - PWA functionality
|
* - PWA functionality
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const CACHE_VERSION = '0.1.1';
|
const CACHE_VERSION = '0.1.2';
|
||||||
const CACHE_NAME = `tractatus-v${CACHE_VERSION}`;
|
const CACHE_NAME = `tractatus-v${CACHE_VERSION}`;
|
||||||
const VERSION_CHECK_INTERVAL = 3600000; // 1 hour in milliseconds
|
const VERSION_CHECK_INTERVAL = 3600000; // 1 hour in milliseconds
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue