diff --git a/package.json b/package.json index 5c6713a..9ff4cf9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pezkuwi-telegram-miniapp", - "version": "1.0.218", + "version": "1.0.220", "type": "module", "description": "Pezkuwichain Telegram Mini App - Forum, Announcements, Rewards", "author": "Pezkuwichain Team", diff --git a/src/components/ErrorBoundary.tsx b/src/components/ErrorBoundary.tsx index d54dfc2..4d8d7ab 100644 --- a/src/components/ErrorBoundary.tsx +++ b/src/components/ErrorBoundary.tsx @@ -12,8 +12,8 @@ import type { Translations, LanguageCode } from '@/i18n/types'; const translations: Record = { krd, en, tr, ckb, fa, ar }; function detectLang(): LanguageCode { - const seg = window.location.pathname.split('/').filter(Boolean)[0]; - if (seg && seg in translations) return seg as LanguageCode; + const stored = localStorage.getItem('app_language'); + if (stored && stored in translations) return stored as LanguageCode; return 'krd'; } diff --git a/src/i18n/index.tsx b/src/i18n/index.tsx index 479e957..aa8266d 100644 --- a/src/i18n/index.tsx +++ b/src/i18n/index.tsx @@ -68,14 +68,15 @@ const TG_LANG_MAP: Record = { }; /** - * Detect language: URL path first, then Telegram user language, then default. + * Detect language: localStorage first, then Telegram user language, then default. + * CRITICAL: Never use URL path for language in Telegram MiniApps! + * Telegram WebView caches URL and strips #tgWebAppData hash on next open. */ function detectLanguage(): LanguageCode { - // 1. Check URL path - const path = window.location.pathname; - const firstSegment = path.split('/').filter(Boolean)[0]; - if (firstSegment && VALID_LANGS.includes(firstSegment as LanguageCode)) { - return firstSegment as LanguageCode; + // 1. Check localStorage (persisted user preference) + const stored = localStorage.getItem('app_language'); + if (stored && VALID_LANGS.includes(stored as LanguageCode)) { + return stored as LanguageCode; } // 2. Check Telegram WebApp user language @@ -134,34 +135,16 @@ export function LanguageProvider({ children }: LanguageProviderProps) { currentLanguage = lang; }, [lang]); - // Update document direction, lang attribute, and URL when language changes + // Update document direction, lang attribute, and persist to localStorage useEffect(() => { document.documentElement.lang = lang === 'krd' ? 'ku' : lang; document.documentElement.dir = isRTL ? 'rtl' : 'ltr'; - - // Ensure URL has language prefix (preserve query params and special paths) - const pathSegments = window.location.pathname.split('/').filter(Boolean); - const firstSegment = pathSegments[0]; - // Don't rewrite URL for standalone pages like /citizens - const STANDALONE_PATHS = ['citizens', 'explorer']; - if (firstSegment && STANDALONE_PATHS.includes(firstSegment)) { - // Keep standalone path as-is - } else if (!firstSegment || !VALID_LANGS.includes(firstSegment as LanguageCode)) { - window.history.replaceState(null, '', `/${lang}${window.location.search}`); - } + localStorage.setItem('app_language', lang); }, [lang, isRTL]); const setLang = useCallback((newLang: LanguageCode) => { setLangState(newLang); - // Update URL without reload - const currentPath = window.location.pathname; - const segments = currentPath.split('/').filter(Boolean); - // Remove old lang prefix if present - if (segments.length > 0 && VALID_LANGS.includes(segments[0] as LanguageCode)) { - segments.shift(); - } - const newPath = `/${newLang}${segments.length > 0 ? '/' + segments.join('/') : ''}`; - window.history.replaceState(null, '', `${newPath}${window.location.search}`); + localStorage.setItem('app_language', newLang); }, []); const t = useCallback( diff --git a/src/version.json b/src/version.json index b68f9b7..a320f69 100644 --- a/src/version.json +++ b/src/version.json @@ -1,5 +1,5 @@ { - "version": "1.0.218", - "buildTime": "2026-02-21T15:35:05.624Z", - "buildNumber": 1771688105624 + "version": "1.0.220", + "buildTime": "2026-02-22T18:04:29.930Z", + "buildNumber": 1771783469930 }