8000 feat(i18n): locale fallback chain and hreflang links by Klehm · Pull Request #64 · Klehm/content-blocks-project · GitHub
[go: up one dir, main page]

Skip to content

feat(i18n): locale fallback chain and hreflang links - #64

Merged
Klehm merged 2 commits into
masterfrom
feat/i18n-fallback-chain-and-hreflang
Sep 29, 2026
Merged

Klehm merged 2 commits into
masterfrom
feat/i18n-fallback-chain-and-hreflang

Conversation

@Klehm
@Klehm Klehm commented Sep 29, 2026
Copy link
Copy Markdown
Owner

Closes the two remaining i18n items of the ROADMAP's "after 1.0" list, other than per-locale publishing from the builder.

Locale fallback chain (opt-in)

content_blocks_i18n:
    fallbacks:
        fr_CA: fr               # one locale
        pt_BR: [pt_PT, es]      # or an ordered list
  • Per field: for each field, the first locale of the chain with a value wins, then the source. Tab titles and localized media follow the same chain.
  • Empty by default, so no page changes on upgrade (the 1.x rule for rendered output).
  • The public page reads the fallback's published value, the preview its draft.
  • Not transitive: each chain is complete as written.
  • Progress ignores it: an untranslated fr_CA field is still missing in the workbench and content-blocks:i18n:status.
  • Config checked at boot: the source cannot be a key or a fallback, and a locale cannot be its own fallback. Keys stay verbatim (zh-Hant).
  • LocaleFallbacksProviderInterface: a host can supply the chains from a service, the same way TargetLocalesProviderInterface supplies the locales (default ConfiguredLocaleFallbacksProvider reads the config). What a provider returns is filtered at runtime.
  • The prefetch warms every locale of the chain (one query per locale).

hreflang links

{{ cb_i18n_hreflang(page.contentArea) }}
  • One <link rel="alternate" hreflang> per language the host's LocalizedPageUrlResolverInterface gives a URL for, the current one included.
  • URLs are made absolute from the request, pt_BR becomes pt-BR, and x-default points at the source (x_default: false to drop it).
  • Prints nothing for a single-language page or a null area.
  • cb_i18n_alternates(area) returns the same data for custom markup.

The sandbox's public page now prints the tags, and its <html lang> follows the request locale.

Docs

The guide gets new "Fallback chain", "Fallbacks from the host" and "hreflang links" sections. The internals doc gets the rationale (#the-fallback-chain). The BC page adds the two Twig functions and the new interface. The README, CHANGELOG, ROADMAP and CLAUDE.md are updated.

Tests

  • i18n PHPUnit: 240, green. New: FallbackChainTest, LocaleFallbacksProviderTest, HreflangExtensionTest, plus config and wiring cases.
  • Playwright: 204, green, including the new i18n-hreflang.spec.js.
  • PHPStan, php-cs-fixer, internal links and the roave BC check: clean.

🤖 Generated with Claude Code

Klehm and others added 2 commits September 29, 2026 11:46
- `content_blocks_i18n.fallbacks` (opt-in, empty by default): an untranslated
  field of a locale reads the listed targets before the source, per field, tab
  titles and localized media included. Chains are not transitive; progress
  still counts the field as missing. A host can supply the chains through
  `LocaleFallbacksProviderInterface`, as it does the target locales.
- `cb_i18n_hreflang(area)` prints `<link rel="alternate" hreflang>` tags from
  `LocalizedPageUrlResolverInterface`, absolute, with `x-default` on the source;
  `cb_i18n_alternates(area)` returns the data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
VitePress parses an inline {{ … }} as a Vue expression, and the named
argument read as a type annotation, which failed the docs build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Klehm
Klehm merged commit 468196f into master Sep 29, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0