feat: implement i18n for product and category, add 5 new locales
This commit is contained in:
1 parent
96d874233d
commit
2977df0a9d
8 files changed
+25
-25
No files matched your search
@@ -121,9 +121,9 @@ export default function CategoryPage() {
|
||||
) : (
|
||||
<div className="relative h-64 md:h-80 overflow-hidden">
|
||||
<img
|
||||
src={getCategoryImage(category?.name ?? '')}
|
||||
src={getCategoryImage(typeof category?.name === 'string' ? category.name : (category?.name as any)?.en || '')}
|
||||
className="absolute inset-0 w-full h-full object-cover brightness-30 scale-105"
|
||||
alt={category?.name}
|
||||
alt={typeof category?.name === 'string' ? category.name : (category?.name as any)?.[i18n.language] || (category?.name as any)?.en || ''}
|
||||
onError={(e) => { (e.target as HTMLImageElement).style.display = 'none' }}
|
||||
/>
|
||||
<div className="absolute inset-0 bg-night-900/40" />
|
||||
@@ -136,13 +136,13 @@ export default function CategoryPage() {
|
||||
<span>/</span>
|
||||
<Link to="/shop" className="hover:text-white transition-colors">Shop</Link>
|
||||
<span>/</span>
|
||||
<span className="text-white">{category?.name ?? '...'}</span>
|
||||
<span className="text-white">{typeof category?.name === 'string' ? category.name : (category?.name as any)?.[localStorage.getItem('homaroma_lang') || 'en'] || (category?.name as any)?.en || '...'}</span>
|
||||
</div>
|
||||
<h1 className="text-4xl md:text-5xl font-bold text-white">
|
||||
{loading ? (
|
||||
<div className="h-10 w-48 bg-white/20 animate-pulse rounded-lg" />
|
||||
) : (
|
||||
category?.name
|
||||
typeof category?.name === 'string' ? category.name : (category?.name as any)?.[i18n.language] || (category?.name as any)?.en || ''
|
||||
)}
|
||||
</h1>
|
||||
{!loading && category?._count && (
|
||||
@@ -169,7 +169,7 @@ export default function CategoryPage() {
|
||||
: 'bg-white text-spa-stone border-spa-stone/20 hover:border-spa-forest hover:text-spa-forest shadow-sm'
|
||||
}`}
|
||||
>
|
||||
{cat.name}
|
||||
{typeof cat.name === 'string' ? cat.name : (cat.name as any)?.[localStorage.getItem('homaroma_lang') || 'en'] || (cat.name as any)?.en || ''}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -133,7 +133,7 @@ export default function ProductDetailPage() {
|
||||
price: currentVariant.price || product.price || 0,
|
||||
productName: displayName,
|
||||
variantSize: currentVariant.size,
|
||||
productImage: product.images?.[0]?.url || getCategoryImage(product.category.name)
|
||||
productImage: product.images?.[0]?.url || getCategoryImage(typeof product.category.name === 'string' ? product.category.name : (product.category.name as any)?.en || '')
|
||||
})
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ export default function ProductDetailPage() {
|
||||
<Link to="/shop" className="hover:text-spa-forest transition-colors">{t('common.shop')}</Link>
|
||||
<span>/</span>
|
||||
<Link to={`/category/${product.category.id}`} className="hover:text-spa-forest transition-colors">
|
||||
{product.category.name}
|
||||
{typeof product.category.name === 'string' ? product.category.name : (product.category.name as any)?.[i18n.language] || (product.category.name as any)?.en || ''}
|
||||
</Link>
|
||||
<span>/</span>
|
||||
<span className="text-spa-forest">{displayName}</span>
|
||||
@@ -172,9 +172,9 @@ export default function ProductDetailPage() {
|
||||
<div className="w-full">
|
||||
<ProductImageGallery
|
||||
images={product.images || []}
|
||||
fallback={getCategoryImage(product.category.name)}
|
||||
fallback={getCategoryImage(typeof product.category.name === 'string' ? product.category.name : (product.category.name as any)?.en || '')}
|
||||
alt={product.scent.name}
|
||||
badgeText={product.category.name}
|
||||
badgeText={typeof product.category.name === 'string' ? product.category.name : (product.category.name as any)?.[i18n.language] || (product.category.name as any)?.en || ''}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -182,7 +182,7 @@ export default function ProductDetailPage() {
|
||||
<div className="space-y-8">
|
||||
<div className="space-y-2">
|
||||
<p className="text-spa-forest uppercase tracking-[0.3em] text-xs font-bold opacity-80">
|
||||
{product.category.name}
|
||||
{typeof product.category.name === 'string' ? product.category.name : (product.category.name as any)?.[i18n.language] || (product.category.name as any)?.en || ''}
|
||||
</p>
|
||||
<h1 className="text-5xl font-bold leading-tight text-pop-black">
|
||||
{displayName}
|
||||
@@ -258,7 +258,7 @@ export default function ProductDetailPage() {
|
||||
to={`/category/${product.category.id}`}
|
||||
className="text-pop-black font-bold hover:text-spa-forest transition-colors"
|
||||
>
|
||||
{product.category.name}
|
||||
{typeof product.category.name === 'string' ? product.category.name : (product.category.name as any)?.[i18n.language] || (product.category.name as any)?.en || ''}
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -126,10 +126,10 @@ export default function SearchPage() {
|
||||
{categories.map((cat) => (
|
||||
<Link
|
||||
key={cat.id}
|
||||
to={`/search?q=${encodeURIComponent(cat.name)}`}
|
||||
to={`/search?q=${encodeURIComponent(typeof cat.name === 'string' ? cat.name : (cat.name as any)?.[i18n.language] || (cat.name as any)?.en || '')}`}
|
||||
className="bg-white border border-spa-stone/20 px-4 py-1.5 rounded-full text-xs font-medium text-spa-stone hover:border-spa-forest hover:text-spa-forest shadow-sm transition-all duration-300"
|
||||
>
|
||||
{cat.name}
|
||||
{typeof cat.name === 'string' ? cat.name : (cat.name as any)?.[i18n.language] || (cat.name as any)?.en || ''}
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -211,7 +211,7 @@ export default function ShopPage() {
|
||||
: 'bg-white text-spa-stone border-spa-stone/20 hover:border-spa-forest hover:text-spa-forest shadow-sm'
|
||||
}`}
|
||||
>
|
||||
{cat.name}
|
||||
{typeof cat.name === 'string' ? cat.name : (cat.name as any)?.[i18n.language] || (cat.name as any)?.en || ''}
|
||||
{cat._count && (
|
||||
<span className={`ml-2 ${activeCategory === cat.id ? 'opacity-80' : 'opacity-60'}`}>({cat._count.products})</span>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user