fix(i18n): translate pricing tiers, features, and content pages
Some checks failed
Some checks failed
Add name_translations JSON column to SubscriptionTier for multi-language tier names. Pre-resolve tier names and build dynamic feature lists from module providers in route handlers. Fix Jinja2 macro scoping by importing pricing partial with context. Backfill content_translations for all 43 content pages across 4 platforms (en/fr/de/lb). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -28,9 +28,12 @@ ROUTE_CONFIG = {
|
||||
}
|
||||
|
||||
|
||||
def _get_tiers_data(db: Session, platform_id: int | None = None) -> list[dict]:
|
||||
def _get_tiers_data(
|
||||
db: Session, platform_id: int | None = None, lang: str = "fr",
|
||||
) -> list[dict]:
|
||||
"""Build tier data for display in templates from database."""
|
||||
from app.modules.billing.models import SubscriptionTier, TierCode
|
||||
from app.modules.billing.services.feature_aggregator import feature_aggregator
|
||||
|
||||
filters = [
|
||||
SubscriptionTier.is_active.is_(True),
|
||||
@@ -49,12 +52,26 @@ def _get_tiers_data(db: Session, platform_id: int | None = None) -> list[dict]:
|
||||
tiers = []
|
||||
for tier in tiers_db:
|
||||
feature_codes = sorted(tier.get_feature_codes())
|
||||
|
||||
# Build features list from declarations for template rendering
|
||||
features = []
|
||||
for code in feature_codes:
|
||||
decl = feature_aggregator.get_declaration(code)
|
||||
if decl:
|
||||
features.append({
|
||||
"code": code,
|
||||
"name_key": decl.name_key,
|
||||
"limit": tier.get_limit_for_feature(code),
|
||||
"is_quantitative": decl.feature_type.value == "quantitative",
|
||||
})
|
||||
|
||||
tiers.append({
|
||||
"code": tier.code,
|
||||
"name": tier.name,
|
||||
"name": tier.get_translated_name(lang),
|
||||
"price_monthly": tier.price_monthly_cents / 100,
|
||||
"price_annual": (tier.price_annual_cents / 100) if tier.price_annual_cents else None,
|
||||
"feature_codes": feature_codes,
|
||||
"features": features,
|
||||
"products_limit": tier.get_limit_for_feature("products_limit"),
|
||||
"orders_per_month": tier.get_limit_for_feature("orders_per_month"),
|
||||
"team_members": tier.get_limit_for_feature("team_members"),
|
||||
@@ -156,11 +173,13 @@ async def homepage(
|
||||
db, platform_id=platform_id, slug="home", include_unpublished=False
|
||||
)
|
||||
|
||||
language = getattr(request.state, "language", "fr") or "fr"
|
||||
|
||||
if cms_homepage:
|
||||
# Use CMS-based homepage with template selection
|
||||
context = get_platform_context(request, db)
|
||||
context["page"] = cms_homepage
|
||||
context["tiers"] = _get_tiers_data(db, platform_id=platform_id)
|
||||
context["tiers"] = _get_tiers_data(db, platform_id=platform_id, lang=language)
|
||||
|
||||
template_name = cms_homepage.template or "default"
|
||||
template_path = f"cms/platform/homepage-{template_name}.html"
|
||||
@@ -171,7 +190,7 @@ async def homepage(
|
||||
# Fallback: Default homepage template with placeholder content
|
||||
logger.info("[HOMEPAGE] No CMS homepage found, using default template with placeholders")
|
||||
context = get_platform_context(request, db)
|
||||
context["tiers"] = _get_tiers_data(db, platform_id=platform_id)
|
||||
context["tiers"] = _get_tiers_data(db, platform_id=platform_id, lang=language)
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"cms/platform/homepage-default.html",
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
{% from 'cms/platform/sections/_hero.html' import render_hero %}
|
||||
{% from 'cms/platform/sections/_products.html' import render_products %}
|
||||
{% from 'cms/platform/sections/_features.html' import render_features %}
|
||||
{% from 'cms/platform/sections/_pricing.html' import render_pricing %}
|
||||
{% from 'cms/platform/sections/_pricing.html' import render_pricing with context %}
|
||||
{% from 'cms/platform/sections/_cta.html' import render_cta %}
|
||||
|
||||
{% block title %}
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
{# Pricing section partial with multi-language support #}
|
||||
{#
|
||||
Parameters:
|
||||
- pricing: PricingSection object (or dict)
|
||||
- pricing: PricingSection object (or dict) from CMS sections JSON
|
||||
- lang: Current language code
|
||||
- default_lang: Fallback language
|
||||
- tiers: List of subscription tiers from DB (passed via context)
|
||||
|
||||
Requires: import with context (for _() locale function)
|
||||
#}
|
||||
|
||||
{# Helper macro: resolve a TranslatableText field with fallback #}
|
||||
@@ -80,9 +82,6 @@
|
||||
<h3 class="text-xl font-bold text-gray-900 dark:text-white mb-2">
|
||||
{{ tier.name }}
|
||||
</h3>
|
||||
<p class="text-gray-500 dark:text-gray-400 text-sm mb-4">
|
||||
{{ tier.description or '' }}
|
||||
</p>
|
||||
|
||||
{# Price #}
|
||||
<div class="mb-6">
|
||||
@@ -102,15 +101,23 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
{# Features list #}
|
||||
{# Features list (dynamic from module providers) #}
|
||||
{% if tier.features %}
|
||||
<ul class="mt-8 space-y-3">
|
||||
{% for feature in tier.features %}
|
||||
{% for feat in tier.features %}
|
||||
<li class="flex items-start">
|
||||
<svg class="w-5 h-5 text-green-500 mr-3 mt-0.5 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
|
||||
</svg>
|
||||
<span class="text-gray-600 dark:text-gray-400 text-sm">{{ feature }}</span>
|
||||
<span class="text-gray-600 dark:text-gray-400 text-sm">
|
||||
{% if feat.is_quantitative and feat.limit %}
|
||||
{{ feat.limit }} {{ _(feat.name_key) }}
|
||||
{% elif feat.is_quantitative %}
|
||||
{{ _(feat.name_key) }}
|
||||
{% else %}
|
||||
{{ _(feat.name_key) }}
|
||||
{% endif %}
|
||||
</span>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user