diff --git a/docs/deployment.md b/docs/deployment.md index 62ece33..4568c38 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -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 diff --git a/docs/domains.md b/docs/domains.md index f6d0698..4f475f1 100644 --- a/docs/domains.md +++ b/docs/domains.md @@ -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` → `` 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` → `` 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): diff --git a/docs/i18n.md b/docs/i18n.md new file mode 100644 index 0000000..642460f --- /dev/null +++ b/docs/i18n.md @@ -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/.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 `` 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`. diff --git a/frontend/src/components/article/ArticleHeader.astro b/frontend/src/components/article/ArticleHeader.astro index a62c881..033f1a8 100644 --- a/frontend/src/components/article/ArticleHeader.astro +++ b/frontend/src/components/article/ArticleHeader.astro @@ -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); ---
- -
diff --git a/frontend/src/layouts/Base.astro b/frontend/src/layouts/Base.astro index 9af8370..faaf7d8 100644 --- a/frontend/src/layouts/Base.astro +++ b/frontend/src/layouts/Base.astro @@ -32,7 +32,7 @@ const canonical_url = const { Header, Footer } = getThemeComponents(config.theme); --- - + diff --git a/frontend/src/lib/ui-i18n.ts b/frontend/src/lib/ui-i18n.ts index 01d63b8..f5cb4c8 100644 --- a/frontend/src/lib/ui-i18n.ts +++ b/frontend/src/lib/ui-i18n.ts @@ -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 { diff --git a/frontend/src/pages/article/[slug].astro b/frontend/src/pages/article/[slug].astro index 941efb3..adffa83 100644 --- a/frontend/src/pages/article/[slug].astro +++ b/frontend/src/pages/article/[slug].astro @@ -92,7 +92,7 @@ const breadcrumb_schema = {
{is_institutional && ( -