feat(storefront): translatable Store description + nav home key + dynamic html lang

Three small storefront i18n improvements found during the FR
pre-launch walkthrough on FASHIONHUB:

- Store description (e.g. "Trendy clothing and accessories") was a
  single English string rendering in the footer regardless of locale.
  Added a description_translations JSON column on Store with the same
  shape used elsewhere (CMS, Platform, Subscription), exposed via
  get_translated_description(lang), and updated the footer + meta tag
  to use it. Seeded FR/DE/LB/EN for FASHIONHUB and FASHIONOUTLET so
  Fashion Group renders correctly out of the box. Other stores still
  show the single description field as fallback.

- "Home" was a hardcoded English literal in both desktop and mobile
  nav, even though the FR translation already existed at nav.home in
  static/locales/fr.json. Now uses _('nav.home').

- <html lang="en"> was hardcoded, which made <input type="date"> show
  in mm/dd/yyyy on the FR storefront. Now driven by current_language
  so the browser's locale-aware date picker matches the page locale.

Migration tenancy_005 adds the description_translations column;
nullable, no backfill needed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-16 19:46:17 +02:00
parent caf1361291
commit 06a44e55e7
4 changed files with 64 additions and 5 deletions

View File

@@ -0,0 +1,31 @@
"""add description_translations to stores
Revision ID: tenancy_005
Revises: tenancy_004
Create Date: 2026-05-16
"""
import sqlalchemy as sa
from alembic import op
revision = "tenancy_005"
down_revision = "tenancy_004"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.add_column(
"stores",
sa.Column(
"description_translations",
sa.JSON(),
nullable=True,
comment="Language-keyed description dict for multi-language support",
),
)
def downgrade() -> None:
op.drop_column("stores", "description_translations")

View File

@@ -56,6 +56,11 @@ class Store(Base, TimestampMixin, SoftDeleteMixin):
String, nullable=False
) # Non-nullable name column for the store (brand name)
description = Column(Text) # Optional text description column for the store
description_translations = Column(
JSON,
nullable=True,
comment="Language-keyed description dict for multi-language support",
)
# Letzshop URLs - multi-language support (brand-specific marketplace feeds)
letzshop_csv_url_fr = Column(String) # URL for French CSV in Letzshop
@@ -320,6 +325,16 @@ class Store(Base, TimestampMixin, SoftDeleteMixin):
"logo"
) # Return None or the logo URL if found
def get_translated_description(self, lang: str, default_lang: str = "fr") -> str | None:
"""Get description in the given language, falling back to default_lang then self.description."""
if self.description_translations:
return (
self.description_translations.get(lang)
or self.description_translations.get(default_lang)
or self.description
)
return self.description
# ========================================================================
# Domain Helper Methods
# ========================================================================

View File

@@ -1,7 +1,7 @@
{# app/templates/storefront/base.html #}
{# Base template for store shop frontend with theme support #}
<!DOCTYPE html>
<html lang="en" x-data="{% block alpine_data %}storefrontLayoutData(){% endblock %}" x-bind:class="{ 'dark': dark }">
<html lang="{{ current_language|default('en') }}" x-data="{% block alpine_data %}storefrontLayoutData(){% endblock %}" x-bind:class="{ 'dark': dark }">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -13,7 +13,7 @@
</title>
{# SEO Meta Tags #}
<meta name="description" content="{% block meta_description %}{{ store.description or 'Shop at ' + store.name }}{% endblock %}">
<meta name="description" content="{% block meta_description %}{{ store.get_translated_description(current_language) or 'Shop at ' + store.name }}{% endblock %}">
{# Favicon - store-specific or default #}
{% if theme.branding.favicon %}
@@ -89,7 +89,7 @@
{# Navigation — Home is always shown, module items are dynamic #}
<nav class="hidden md:flex space-x-8">
<a href="{{ base_url }}" class="text-gray-700 dark:text-gray-300 hover:text-primary">
Home
{{ _('nav.home') }}
</a>
{% for item in storefront_nav.get('nav', []) %}
<a href="{{ base_url }}{{ item.route }}" class="text-gray-700 dark:text-gray-300 hover:text-primary">
@@ -244,7 +244,7 @@
<nav class="max-w-7xl mx-auto px-4 py-4 space-y-1">
<a href="{{ base_url }}" @click="closeMobileMenu()"
class="block px-3 py-2 rounded-lg text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 font-medium">
Home
{{ _('nav.home') }}
</a>
{% for item in storefront_nav.get('nav', []) %}
<a href="{{ base_url }}{{ item.route }}" @click="closeMobileMenu()"
@@ -279,7 +279,7 @@
{{ store.name }}
</h3>
<p class="text-gray-600 dark:text-gray-400 mb-4">
{{ store.description }}
{{ store.get_translated_description(current_language) }}
</p>
{# Social Links from theme #}

View File

@@ -207,6 +207,12 @@ DEMO_STORES = [
"name": "Fashion Hub",
"subdomain": "fashionhub",
"description": "Trendy clothing and accessories",
"description_translations": {
"en": "Trendy clothing and accessories",
"fr": "Vêtements et accessoires tendance",
"de": "Trendige Kleidung und Accessoires",
"lb": "Trendeg Kleeder a Accessoiren",
},
"theme_preset": "vibrant",
"custom_domain": "fashionhub.store",
"custom_domain_platform": "loyalty", # Link domain to Loyalty platform
@@ -217,6 +223,12 @@ DEMO_STORES = [
"name": "Fashion Outlet",
"subdomain": "fashionoutlet",
"description": "Discounted designer fashion and seasonal clearance",
"description_translations": {
"en": "Discounted designer fashion and seasonal clearance",
"fr": "Mode de créateurs à prix réduit et soldes de saison",
"de": "Reduzierte Designermode und saisonale Restposten",
"lb": "Reduzéiert Designermode a Saisonsoldes",
},
"theme_preset": "vibrant",
"custom_domain": None,
},
@@ -932,6 +944,7 @@ def create_demo_stores(
name=store_data["name"],
subdomain=store_data["subdomain"],
description=store_data["description"],
description_translations=store_data.get("description_translations"),
is_active=True,
is_verified=True,
created_at=datetime.now(UTC),