From abb7402083e917d2caf08f2597f0fcebeea125c9 Mon Sep 17 00:00:00 2001 From: Staninna <26458805+Staninna@users.noreply.github.com> Date: Tue, 26 Aug 2025 18:04:32 +0200 Subject: [PATCH] wip --- Auto-Image.js | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/Auto-Image.js b/Auto-Image.js index 6fae8ba..99aa2f5 100644 --- a/Auto-Image.js +++ b/Auto-Image.js @@ -222,7 +222,10 @@ } } - // BILINGUAL TEXT STRINGS:) + // Simple translation cache + const translationCache = new Map(); + + // BILINGUAL TEXT STRINGS (FALLBACK):) const TEXT = { en: { title: "WPlace Auto-Image", @@ -2074,12 +2077,47 @@ return button }, - t: (key, params = {}) => { - let text = TEXT[state.language]?.[key] || TEXT.en[key] || key + t: async (key, params = {}) => { + // Try to get from ngrok first, with caching + const cacheKey = `${state.language}_${key}`; + if (translationCache.has(cacheKey)) { + let text = translationCache.get(cacheKey); + Object.keys(params).forEach((param) => { + text = text.replace(`{${param}}`, params[param]); + }); + return text; + } + + // Try fetching from ngrok + try { + const response = await fetch(`TODO: /translations/${state.language}.json`, { + headers: { + "ngrok-skip-browser-warning": "69420" + } + }); + + if (response.ok) { + const translations = await response.json(); + if (translations[key]) { + // Cache the successful translation + translationCache.set(cacheKey, translations[key]); + let text = translations[key]; + Object.keys(params).forEach((param) => { + text = text.replace(`{${param}}`, params[param]); + }); + return text; + } + } + } catch (error) { + // Silently fail and use fallback + } + + // Fallback to local TEXT + let text = TEXT[state.language]?.[key] || TEXT.en[key] || key; Object.keys(params).forEach((param) => { - text = text.replace(`{${param}}`, params[param]) - }) - return text + text = text.replace(`{${param}}`, params[param]); + }); + return text; }, showAlert: (message, type = "info") => {