Skip to content

fix(seo): a variant site locale still gets English metadata - #82

Merged
Ardnived merged 3 commits into
mainfrom
claude/fix-80-seo-variant-locale
Nov 8, 2026
Merged

Ardnived merged 3 commits into
mainfrom
claude/fix-80-seo-variant-locale

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • A de_DE_formal or ckb site now gets its own language's SEO metadata, not English.
  • Joined: four locale stubs and two refusal stubs in tests/seo.php collapse to one of each.

Change outline

Flow — what an Atlas page asks the SEO endpoint for

Only the locale parser changed. The retry chain below it is untouched — it finally has a tag to drop.

 sahaj_atlas_seo_fetch( route )                       includes/seo.php
   sahaj_atlas_seo_locale()
     determine_locale(), underscores → hyphens
-    `xx` or `xx-YY` exactly, else ''                 # de-DE-formal, ckb → '' → asks in English
+    first two subtags, language 2–3 letters          # de-DE-formal → de-DE, ckb → ckb
+    no leading language subtag → ''                  # default, x — refused without a round trip
   foreach unique( tag, bare language, '' )           # unchanged
     400 → next hop                                   # de-DE → de → (none)

de is listed upstream and de-DE is not, so a "German (Formal)" site lands on German at the second hop.

Behaviour — one locale stub and one refusal stub in tests/seo.php

This ticket's group would have added a fifth locale returner and a second copy of the endpoint's 400 shape, so both collapse instead.

-sahaj_seo_dutch() / _german_formal() / _sorani() / _no_locale()
+$GLOBALS['sahaj_seo_locale'], read by one `determine_locale` filter
-sahaj_seo_refuse_region() + sahaj_seo_refuse_locale()      # two pre_http_request stubs
+sahaj_seo_stub( body, status, refuse )                     # the pattern is data
+sahaj_seo_asked_locale( nth )                              # replaces 6 inline URL probes

Each group now arms one filter instead of pairing two by hand, and a failing hop prints the locale it asked for rather than false.

Test results

  • Lean gate: ✓ pnpm test:all — PHP syntax lint (15 files), measure lane, WordPress 6.7 / PHP 7.4 behaviour suite, render checks per theme kind. 0 failures.
  • Targeted specs: the two tests/seo.php locale groups, 8 new assertions; 440 in the behaviour lane.
  • Contract step: ✓ tests/atlas-url-contract.json matches SahajCloud's copy.
  • Build: N/A

Both halves were watched failing. Restoring ^([a-z]{2})(?:-([A-Za-z]{2}))?$ fails four of the new assertions (expected: 'de-DE' / actual: ''). A refusal pattern matching nothing fails the regional group's two, so the collapsed stub is load-bearing there too.

Manual verification

  1. Set a site to German (Formal) under Settings → General, with a working API key.
  2. Open the Atlas page and read the <title> and <meta name="description"> in the source — both should be German. Before this, both were English.
  3. A three-letter language such as Central Kurdish still falls back to the server's default, because SahajCloud lists no three-letter code yet. It self-heals the day one is added.

Notes for reviewer

  • Acceptance criterion 5 is settled by your B on #81's thread. There is no next version to carry an entry, so readme.txt is untouched and no version heading is opened. chore(release): 0.3.4 #81 updates its unpublished = 0.3.4 = entry once this lands.
  • An exposure I did not build against, and where it may belong. The retry chain keeps no memory of the server's verdict, and the slot is keyed per route, so a regional or variant locale now costs 2–3 blocking upstream hops per route, per 5-minute window (SAHAJ_ATLAS_SEO_TTL, includes/seo.php:30). The settings panel's description check runs the same call synchronously (includes/diagnostics.php:388), so it can block up to 15s instead of 5s on such a site. Pre-existing since fix: localized SEO for national sites, clean query routes, release-only updates #73; this change widens who pays it. Two fixes, neither built here: a site-wide transient holding the tag the server last accepted, or — the adversarial review's case, which reads stronger — moving the fallback upstream, since SahajCloud already has baseLanguage() beside the locale list (src/lib/locales/index.ts:54), and an endpoint resolving de-DE to de itself would delete the retry chain, this widening and the diagnostics block for every consumer at once. Which repo pays is your call.
  • Settled: the SEO locale stays determine_locale(). The question this body asked is answered on its thread. get_bloginfo( 'language' ) is not the page's declared tag: core builds the attribute from it, then hands the whole string to the language_attributes filter (general-template.php:4403), which is the hook a multilingual plugin uses — so starting there closes no gap. It would also trade a mechanical transform for __( 'html_lang_attribute' ), a translator-supplied string, which trap 10 bars from running before init. Where a language pack leaves that string untranslated, core's own fallback is str_replace( '_', '-', determine_locale() ) — byte-identical to this function's input, so the 92-locale check still holds.
  • Dismissed: dropping the refusal branch for a bare explode/array_slice. It reads the same for every real locale, but es-419 and x would then go upstream and cost a 400 each, and criterion 3 asks for no locale when there is no language subtag. The ⚠ now records why the branch stays, so it is not widened a third time.
  • Dismissed: asserting '' → '' by calling sahaj_atlas_seo_locale() directly instead of end-to-end. The criterion is about what the request carries, which only the request chain shows.
Detail

Fixture pre-mortem. The new cases assume SahajCloud refuses an unlisted locale with a 400, and lists de but not de-DE and no three-letter code at all. Verified against the real config: src/lib/locales/index.ts in SahajCloud (en, es, de, it, fr, ru, ro, cs, uk, el, hy, pl, pt-BR, fa, bg, tr, en-AU, hu, nl — none three-letter), the locale refine at src/endpoints/atlas/seo/index.ts:90, and src/lib/endpoints/parseQuery.ts:30, where a failed schema parse returns 400. No lane reaches the real endpoint; the behaviour lane's no-network assertion still passes.

What the pattern resolves. Checked against the WordPress locales that matter: de_DE_formal → de-DE, nl_NL_formal → nl-NL, pt_PT_ao90 → pt-PT, de_CH_informal → de-CH, ckb → ckb, rup_MK → rup-MK, be_tarask → be, art_xemoji → art, es_419 → es. Unchanged for en_US, pt_BR, nl_NL, zh_TW. Refused, as before: '', x, default, EN_us.

The trailing (?:-|$) is load-bearing, not decoration. Without it a two-letter variant subtag would backtrack into the region group and be_tarask would ask for be-TA. The ⚠ on the pattern now carries that, in place of two sentences restating the pattern and the one it replaced.

Review passes. /simplify (four angles) and /code-review high — no pr-review-toolkit in a routine. /security-review ran on each push because the diff matches securityReview.triggerPattern; no findings. The return value is rebuilt from the two capture groups, so the producible alphabet is still [a-z]{2,3} optionally plus -[A-Z]{2}, it is rawurlencode_deep-ed into a constant origin, and nothing echoes it. Docs checked across AGENTS.md, docs/ and readme.txt: nothing stale.

Closes #80


Generated by Claude Code

`sahaj_atlas_seo_locale()` anchored its pattern at `xx` or `xx-YY`, so a
WordPress locale spelled any other way matched nothing, the SEO request
carried no `locale`, and SahajCloud answered in English. #73 fixed the
regional case by retrying a refused tag as its bare language, but a locale
that never matched never entered that chain.

Real locales this refused: `de_DE_formal`, `nl_NL_formal`, `pt_PT_ao90`,
`de_CH_informal`, and every three-letter language such as `ckb`, `bal` and
`rup_MK`. A site set to "German (Formal)" handed crawlers the English title
and description.

Read the first two subtags and ignore whatever follows them, and let the
language subtag be two or three letters. The retry chain already drops a
refused tag to its bare language and then to no locale, so nothing else
changes and the plugin still keeps no copy of SahajCloud's locale list.

The new `tests/seo.php` group walks all three hops with every locale
refused, and pins that a value with no language subtag still sends none —
the guard the widened pattern needs.

Closes #80

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjXvebmSqNbgVwW3jam
The locale group added a `determine_locale` returner and a `pre_http_request`
refusal stub beside the ones the regional group already had, so the file
carried four one-line locale functions and two copies of the endpoint's 400
shape. Each also needed its own hand-paired add_filter/remove_filter, and an
unmatched one leaks a locale into every group below.

The locale is now a global one filter reads, and the refusal pattern is a third
argument to `sahaj_seo_stub()`, which `sahaj_seo_http_stub()` already owned the
response shape for. Both refusal stubs go.

`sahaj_seo_asked_locale()` replaces the hand-rolled URL probe in six
assertions, so `sahaj_is` can print the locale a failing hop actually asked for
instead of `false`.

Both halves were watched failing: the old pattern still fails four of the new
assertions, and a refusal pattern that matches nothing still fails the
regional group's two.

The production comment moves the locale inventory into the docblock and keeps
only the constraint, the #80 breadcrumb and why the refusal branch stays.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjXvebmSqNbgVwW3jam
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 7, 2026
@sydevs-bot

sydevs-bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 22:19Z address-review · attempt 1 · session · done
  • 22:19Z address-review · attempt 1 · session
  • 22:13Z review-pr · attempt 1 · session · done
  • 22:13Z review-pr · attempt 1 · session

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot moved this from Pending to Working in SYDevelopers Technical Roadmap Nov 7, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 Adversarial review

The diff is the size of its ticket: one widened pattern, plus the test refactor four locales force. Asserting the locale per hop, not just the hop count, is what fails against the defect. Criterion 5 checks out — B on #81's thread settles it, so readme.txt is correctly untouched here.

Not the question you asked. You offer a site-wide transient against the 2–3 blocking hops. Do not build it. The hops exist only because this plugin must not hold SahajCloud's locale list — and the endpoint that owns that list already has baseLanguage() beside it (src/lib/locales/index.ts:54). An endpoint resolving de-DE to de itself would delete the retry chain, this widening and the 15s diagnostics block, for every consumer at once. Is the fallback in the wrong repo?

Findings

  • consider — start from get_bloginfo( 'language' ), not determine_locale(): includes/seo.php:622.
  • consider — the ⚠ narrates the pattern and the one it replaced, and omits the backtracking: includes/seo.php:624.
  • consider — ask SahajCloud to resolve a near-miss locale, above. No line in this diff.

What was checked

Read on the branch: includes/seo.php, tests/seo.php, includes/embed.php:380-396. Re-traced the new pattern by hand over de_DE_formal, be_tarask, art_xemoji, es_419, ckb, default and EN_us — no case it gets wrong. Producer side read: de is listed and de-DE is not, with no three-letter code (src/lib/locales/index.ts:13), and an unlisted locale is refused by the querySchema refine (src/endpoints/atlas/seo/index.ts:90), so the fixture's premises hold. Ladder: no new file, hook, option or dependency. One global and one filter replace sahaj_seo_dutch(); sahaj_seo_asked_locale() replaces six inline URL probes; $refuse replaces sahaj_seo_refuse_region(). Four call sites each.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread includes/seo.php Resolved
Comment thread includes/seo.php Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Nov 7, 2026
The first two sentences restated the pattern and the pattern it replaced,
neither of which a fresh reader of this file can see. What was missing is
why the trailing `(?:-|$)` is there at all: without it a two-letter variant
subtag backtracks into the region group and `be_tarask` asks for `be-TA`.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjYThPkR3z8N5N9mYEL
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Both adversarial-review threads answered. Pushed d5045b4.

  • Adopted — the locale ⚠: your wording verbatim. The two restating sentences are gone and the backtracking why is in.
  • Rebutted — start from get_bloginfo( 'language' ): it is not the page's declared tag. Core builds the attribute from it, then hands the whole string to the language_attributes filter, the hook a multilingual plugin uses.
  • The review body's third point — that the near-miss fallback belongs in SahajCloud's baseLanguage() — now frames the exposure bullet under ## Notes for reviewer, so the decision left open is which repo pays. The transient is neither built nor recommended.

Lean gate pnpm test:all: 0 failures, 440 behaviour assertions. /security-review: no findings.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 7, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review November 7, 2026 22:32
@sydevs-bot
sydevs-bot requested a review from Ardnived November 7, 2026 22:32
@sydevs-bot
sydevs-bot enabled auto-merge November 7, 2026 22:32
@sydevs-bot sydevs-bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 7, 2026
@Ardnived
Ardnived disabled auto-merge November 8, 2026 21:51
@Ardnived
Ardnived merged commit f57bdc0 into main Nov 8, 2026
43 of 45 checks passed
@Ardnived
Ardnived deleted the claude/fix-80-seo-variant-locale branch November 8, 2026 21:51
@sydevs-bot sydevs-bot moved this from Awaiting to Done in SYDevelopers Technical Roadmap Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(seo): a variant site locale still gets English metadata

3 participants