feat(frontend): PT shell i18n, html lang pt-PT, i18n docs (BIT-739)

- Set document language to full BCP-47 from domain config (e.g. pt-PT).
- Extend ui-i18n with service errors, ad labels, ARIA landmarks, category
  meta fallback, and localized search upstream message.
- Localize ArticleHeader (dates, reading time, breadcrumb); omit duplicate
  breadcrumb when institutional chrome already provides one.

Docs: add docs/i18n.md strategy sketch; domains.md and deployment.md
(BRIDGE_INTERNAL_URL) cross-links.

Paperclip-Agent: ac1be104-8818-496a-80c5-fbc590a87855
Paperclip-Issue: 182b154e-5ad4-4965-9f30-50a66ef51ce0
Paperclip-Run: 6ce7746f-bfb6-4486-a1f5-aed26fe8e149
Made-with: Cursor
This commit is contained in:
Artur Moreira committed 2026-04-02 20:06:48 +00:00
1 parent 4d60425f7d
commit b629f6c6aa
11 files changed
+106 -26

No files matched your search

+2
View File
@@ -122,6 +122,8 @@ Operação e recuperação de **«Error establishing a database connection»**:
## Service Start (PM2)
**Bridge URL on the CT:** Domain JSON often lists `bridge_endpoint` as loopback for dev. In production, set **`BRIDGE_INTERNAL_URL`** in the environment for the Astro process (e.g. in the PM2 ecosystem file or systemd unit) so SSR calls the real bridge (e.g. `http://127.0.0.1:3200` on the same host). The frontend merges this over the JSON value in `getDomainConfig()` — see `frontend/src/lib/domain.ts` and `frontend/.env.example`.
```bash
# Frontend
cd /opt/news-platform/frontend
+1 -1
View File
@@ -93,7 +93,7 @@ A full sample lives at `config/domains/fpa-example.json`.
}
```
Live file: `config/domains/andebol.net.json`. Set **`auth_links`** to show **Entrar** / **Registar** in the header and footer and to enable **`/entrar`** → `wp-login.php` and **`/registar`** → `wp-login.php?action=register`. The HTML document language uses the first segment of `locale` (e.g. `pt-PT` → `<html lang="pt">` in `Base.astro`).
Live file: `config/domains/andebol.net.json`. Set **`auth_links`** to show **Entrar** / **Registar** in the header and footer and to enable **`/entrar`** → `wp-login.php` and **`/registar`** → `wp-login.php?action=register`. The HTML document language is the full `locale` tag (e.g. `pt-PT` → `<html lang="pt-PT">` in `Base.astro`). Shell UI strings come from `frontend/src/lib/ui-i18n.ts` keyed off the same field; see `docs/i18n.md`.
**Local smoke test:** the dev server does not read a `HOST` env var for the HTTP `Host` header. Map the hostname and open the site with that host (or send the header manually):
+31
View File
@@ -0,0 +1,31 @@
# Internationalisation (i18n) — news-platform
Short sketch for **BIT-739** and follow-on work.
## Current model (minimal, non-breaking)
1. **Per-domain locale** — Each hostname loads `config/domains/<host>.json`. The `locale` field is a BCP 47 tag (e.g. `pt-PT` for andebol.net, `en-US` for localhost / English hubs).
2. **Document language** — `frontend/src/layouts/Base.astro` sets `<html lang={config.locale}>` so regional variants (e.g. `pt-PT`) are preserved for accessibility and SEO.
3. **Static UI strings** — `frontend/src/lib/ui-i18n.ts` maps the **primary language subtag** (`pt` from `pt-PT`) to a string table. English is the fallback for unknown languages. When a second Portuguese variant is needed (e.g. `pt-BR`), add an explicit branch in `getUiStrings` rather than overloading `pt`.
4. **Runtime formatting** — Dates and relative times use `Intl` via `frontend/src/lib/format.ts`, passing the same `config.locale` as the domain JSON.
5. **Auth chrome** — Login/register labels for `auth_links` use `frontend/src/lib/auth-labels.ts` (Portuguese when `locale` starts with `pt`).
6. **Editorial content** — Headlines, bodies, and categories come from WordPress / the bridge; they are not translated by the frontend. Domain config supplies **section labels** (`categories[].label`) in the target language for each site.
## Preparing for fuller multilang (not implemented yet)
Possible directions when the product requires multiple languages **on the same hostname**:
- **Path prefix** — e.g. `/en/...`, `/pt/...`, with middleware choosing `locale` and canonical/hreflang rules.
- **Subdomains** — e.g. `en.example.com` / `pt.example.com`, each with its own domain JSON or a shared base plus `locale` override.
- **Cookie / Accept-Language** — optional overlay once URLs and caching semantics are defined (CDN keys, bridge cache).
Until then, **one locale per hostname** keeps SSR caching and domain routing simple.
## Operations alignment
Production Astro SSR should reach the bridge on an internal URL. Set **`BRIDGE_INTERNAL_URL`** on the frontend process so JSON `bridge_endpoint` loopback values in repo configs are overridden at runtime — see `frontend/src/lib/domain.ts` and `docs/deployment.md`.
@@ -1,21 +1,27 @@
---
import type { Article } from '../../types/index.js';
import { formatDate, relativeTime } from '../../lib/format.js';
import { getUiStrings } from '../../lib/ui-i18n.js';
interface Props {
article: Article;
locale: string;
/** When false, parent layout already renders a localized breadcrumb (e.g. institutional theme). */
showBreadcrumb?: boolean;
}
const { article } = Astro.props;
const { article, locale, showBreadcrumb = true } = Astro.props;
const ui = getUiStrings(locale);
---
<header class="article-header">
<!-- Breadcrumb -->
<nav class="breadcrumb" aria-label="Breadcrumb">
<a href="/">Home</a>
{showBreadcrumb && (
<nav class="breadcrumb" aria-label={ui.aria_breadcrumb}>
<a href="/">{ui.breadcrumb_home}</a>
<span class="breadcrumb__sep" aria-hidden="true">/</span>
<a href={`/category/${article.category.slug}`}>{article.category.name}</a>
<span class="breadcrumb__sep" aria-hidden="true">/</span>
<span aria-current="page">{article.title}</span>
</nav>
)}
<!-- Category -->
<div class="article-header__cats">
@@ -51,12 +57,13 @@ const { article } = Astro.props;
<div>
<p class="article-header__author-name">{article.author.name}</p>
<p class="article-header__date">
<time datetime={article.published_at} title={formatDate(article.published_at)}>
{relativeTime(article.published_at)}
<time datetime={article.published_at} title={formatDate(article.published_at, locale)}>
{relativeTime(article.published_at, locale)}
</time>
{article.updated_at !== article.published_at && (
<span class="article-header__updated">
· Updated <time datetime={article.updated_at}>{relativeTime(article.updated_at)}</time>
· {ui.article_updated_prefix}{' '}
<time datetime={article.updated_at}>{relativeTime(article.updated_at, locale)}</time>
</span>
)}
</p>
@@ -67,7 +74,7 @@ const { article } = Astro.props;
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
<circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/>
</svg>
{article.reading_time} min read
{article.reading_time} {ui.min_read}
</div>
</div>
</header>
+1 -1
View File
@@ -32,7 +32,7 @@ const canonical_url =
const { Header, Footer } = getThemeComponents(config.theme);
---
<!doctype html>
<html lang={config.locale.split('-')[0]} data-theme="light">
<html lang={config.locale} data-theme="light">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
+41 -1
View File
@@ -1,6 +1,8 @@
/**
* Static UI copy keyed by domain `locale` (BCP 47).
* Extend as more locales ship; unknown locales fall back to English.
* Matching uses the primary language subtag (`pt` from `pt-PT`); add explicit
* `pt-BR` (or other) bundles in this module when a second variant is needed.
* Unknown locales fall back to English.
*/
export type UiStrings = {
skip_to_content: string;
@@ -65,6 +67,23 @@ export type UiStrings = {
related_articles_title: string;
/** Visible label above homepage hero (editorial hub rhythm) */
homepage_hero_section: string;
/** Plain-text 503 when bridge or critical upstream fails in production */
service_unavailable: string;
/** Ad slots (visible + aria when ads_enabled) */
ad_slot_aria: string;
ad_slot_text: string;
/** Landmark / navigation ARIA labels */
aria_breadcrumb: string;
aria_pagination: string;
aria_article_sidebar: string;
/** Label before tag badges on article pages */
tags_heading: string;
/** Prefix before updated timestamp in article byline */
article_updated_prefix: string;
/** Meta description when category has no WP description */
category_meta_latest: (sectionName: string) => string;
/** Search results could not be loaded from bridge */
search_upstream_error: string;
};
const en: UiStrings = {
@@ -122,6 +141,16 @@ const en: UiStrings = {
news_most_read: 'Most Read',
related_articles_title: 'Related articles',
homepage_hero_section: 'Headlines',
service_unavailable: 'Service temporarily unavailable.',
ad_slot_aria: 'Advertisement',
ad_slot_text: 'Advertisement',
aria_breadcrumb: 'Breadcrumb',
aria_pagination: 'Pagination',
aria_article_sidebar: 'Article sidebar',
tags_heading: 'Tags:',
article_updated_prefix: 'Updated',
category_meta_latest: name => `Latest ${name} news`,
search_upstream_error: 'Results could not be loaded. Please try again shortly.',
};
const pt: UiStrings = {
@@ -179,6 +208,17 @@ const pt: UiStrings = {
news_most_read: 'Mais Lidas',
related_articles_title: 'Artigos relacionados',
homepage_hero_section: 'Manchetes',
service_unavailable: 'Serviço temporariamente indisponível.',
ad_slot_aria: 'Publicidade',
ad_slot_text: 'Publicidade',
aria_breadcrumb: 'Navegação estrutural',
aria_pagination: 'Paginação',
aria_article_sidebar: 'Barra lateral do artigo',
tags_heading: 'Etiquetas:',
article_updated_prefix: 'Atualizado',
category_meta_latest: name => `Últimas notícias: ${name}`,
search_upstream_error:
'Não foi possível obter resultados. Tenta novamente dentro de momentos.',
};
export function getUiStrings(locale: string): UiStrings {
+6 -6
View File
@@ -92,7 +92,7 @@ const breadcrumb_schema = {
<div class:list={['article-page', 'container', is_institutional && 'article-page--inst']}>
{is_institutional && (
<nav class="article-breadcrumb" aria-label="Breadcrumb">
<nav class="article-breadcrumb" aria-label={ui.aria_breadcrumb}>
<a href="/">{ui.breadcrumb_home}</a>
<span class="article-breadcrumb__sep" aria-hidden="true">/</span>
<a href={`/category/${article.category.slug}`}>{article.category.name}</a>
@@ -103,7 +103,7 @@ const breadcrumb_schema = {
<div class="article-layout">
<!-- Main article column -->
<div class="article-main">
<ArticleHeader article={article} />
<ArticleHeader article={article} locale={config.locale} showBreadcrumb={!is_institutional} />
<!-- Featured image -->
{article.featured_image && (
@@ -123,7 +123,7 @@ const breadcrumb_schema = {
<!-- Ad slot: top of article -->
{config.ads_enabled && (
<div class="ad-slot ad-slot--in-article" aria-label="Advertisement">Advertisement</div>
<div class="ad-slot ad-slot--in-article" aria-label={ui.ad_slot_aria}>{ui.ad_slot_text}</div>
)}
<!-- Article body -->
@@ -132,7 +132,7 @@ const breadcrumb_schema = {
<!-- Tags -->
{article.tags.length > 0 && (
<div class="article-tags">
<span class="article-tags__label">Tags:</span>
<span class="article-tags__label">{ui.tags_heading}</span>
{article.tags.map(tag => (
<span class="badge badge--muted">{tag.name}</span>
))}
@@ -141,9 +141,9 @@ const breadcrumb_schema = {
</div>
<!-- Sidebar -->
<aside class="article-sidebar" aria-label="Article sidebar">
<aside class="article-sidebar" aria-label={ui.aria_article_sidebar}>
{config.ads_enabled && (
<div class="ad-slot ad-slot--sidebar sticky-top" aria-label="Advertisement">Advertisement</div>
<div class="ad-slot ad-slot--sidebar sticky-top" aria-label={ui.ad_slot_aria}>{ui.ad_slot_text}</div>
)}
</aside>
</div>
+3 -3
View File
@@ -89,7 +89,7 @@ const breadcrumb_schema = {
<Base
config={config}
title={`${display_name} — ${config.site_name}`}
description={category.description || `Latest ${display_name} news`}
description={category.description || ui.category_meta_latest(display_name)}
canonical={canonical}
schema={breadcrumb_schema}
>
@@ -109,7 +109,7 @@ const breadcrumb_schema = {
<div class:list={['container', is_institutional && 'cat-page-wide']}>
<!-- Breadcrumb -->
<nav class="breadcrumb" style="padding-top: 1.5rem" aria-label="Breadcrumb">
<nav class="breadcrumb" style="padding-top: 1.5rem" aria-label={ui.aria_breadcrumb}>
<a href="/">{ui.breadcrumb_home}</a>
<span class="breadcrumb__sep" aria-hidden="true">/</span>
<span aria-current="page">{display_name}</span>
@@ -229,7 +229,7 @@ const breadcrumb_schema = {
)}
{total_pages > 1 && (
<nav class:list={['pagination', is_institutional && 'pagination--hub']} aria-label="Pagination">
<nav class:list={['pagination', is_institutional && 'pagination--hub']} aria-label={ui.aria_pagination}>
{has_prev && (
<a
href={`/category/${slug}?page=${page - 1}`}
+2 -2
View File
@@ -27,7 +27,7 @@ try {
homepage = await bridge.getHomepage();
} catch {
if (import.meta.env.PROD) {
return new Response('Serviço temporariamente indisponível.', {
return new Response(ui.service_unavailable, {
status: 503,
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
});
@@ -67,7 +67,7 @@ const website_schema = {
{config.ads_enabled && (
<div class="container" style="padding-block: 1rem">
<div class="ad-slot ad-slot--leaderboard" aria-label="Advertisement">Advertisement</div>
<div class="ad-slot ad-slot--leaderboard" aria-label={ui.ad_slot_aria}>{ui.ad_slot_text}</div>
</div>
)}
+2 -2
View File
@@ -21,7 +21,7 @@ let bridge: BridgeClient;
try {
bridge = await resolveSsrBridge(config.bridge_endpoint, site_host);
} catch {
return new Response('Serviço temporariamente indisponível.', {
return new Response(ui.service_unavailable, {
status: 503,
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
});
@@ -323,7 +323,7 @@ const breadcrumb_schema = {
PAGINATION
══════════════════════════════════════════════════════════ */}
{total_pages > 1 && (
<nav class="pagination" aria-label="Pagination">
<nav class="pagination" aria-label={ui.aria_pagination}>
{has_prev && (
<a
href={paginationHref(page - 1)}
+2 -2
View File
@@ -103,7 +103,7 @@ const is_institutional = config.theme === 'institutional';
{can_search && search_upstream_failed && (
<p class="search-page__hint search-page__hint--warn" role="alert">
Não foi possível obter resultados. Tenta novamente dentro de momentos.
{ui.search_upstream_error}
</p>
)}
@@ -132,7 +132,7 @@ const is_institutional = config.theme === 'institutional';
</div>
{paginated.total_pages > 1 && (
<nav class="pagination" aria-label="Pagination">
<nav class="pagination" aria-label={ui.aria_pagination}>
{page > 1 && (
<a
href={`/search?q=${encodeURIComponent(q)}&page=${page - 1}`}