x
This commit is contained in:
1 parent
cfd642dee0
commit
ae3799d8ce
21 files changed
+172
-30
No files matched your search
@@ -7,13 +7,14 @@ import i18n from '../lib/i18n';
|
||||
import { useCartStore } from '../store/cartStore';
|
||||
import { useWishlistStore } from '../store/wishlistStore';
|
||||
import { useAuthStore } from '../store/authStore';
|
||||
import { DEFAULT_LOCALE, SUPPORTED_LOCALES } from '../lib/locales';
|
||||
|
||||
export default function ClientProviders({ children }: { children: ReactNode }) {
|
||||
useEffect(() => {
|
||||
// With Locale Routing, the URL is the source of truth for language.
|
||||
// Sync i18n to match the current URL if needed.
|
||||
const pathLang = window.location.pathname.split('/')[1];
|
||||
const targetLang = pathLang && ['th', 'en', 'ja', 'zh', 'vi', 'ko'].includes(pathLang) ? pathLang : 'th';
|
||||
const targetLang = pathLang && (SUPPORTED_LOCALES as readonly string[]).includes(pathLang) ? pathLang : DEFAULT_LOCALE;
|
||||
|
||||
if (targetLang !== i18n.language) {
|
||||
void i18n.changeLanguage(targetLang);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import Image from 'next/image'
|
||||
import Link from './LocalizedLink'
|
||||
import { getPathWithoutLocale, getPathWithLocale } from '../lib/locales'
|
||||
import { getPathWithoutLocale, getPathWithLocale, type Locale } from '../lib/locales'
|
||||
import { useRouter, usePathname } from 'next/navigation'
|
||||
import { useState, useEffect, useMemo, useRef } from 'react'
|
||||
import type { Category } from '@homaroma/types'
|
||||
@@ -31,7 +31,9 @@ const LANGUAGES = [
|
||||
{ code: 'zh', label: '简体中文', short: 'ZH' },
|
||||
{ code: 'vi', label: 'Tiếng Việt', short: 'VN' },
|
||||
{ code: 'ko', label: '한국어', short: 'KO' },
|
||||
]
|
||||
{ code: 'lo', label: 'ລາວ', short: 'LO' },
|
||||
{ code: 'it', label: 'Italiano', short: 'IT' },
|
||||
] satisfies Array<{ code: Locale; label: string; short: string }>
|
||||
|
||||
function setLanguageCookie(code: string) {
|
||||
if (typeof document !== 'undefined') {
|
||||
|
||||
Reference in new issue
Block a user