Commit 8b4d7fe
feat(i18n): PR-P G-35 follow-through — translate AI envelope on publish
User feedback: PR-P G-35 schema landed but the visible behaviour
didn't change yet — `titleLocalized` was still always undefined,
so the consumer kept hitting the PL canonical fallback. Adding
the real generator hook now.
`lib/ai-pipeline/generate.ts`:
- new `translateEnvelopeFields(plPayload, targetLang)` helper.
One Haiku call per non-pl lang; tight system prompt locks the
same proper-noun list as the spec translator (BLIK, PKO, NBP,
Tauron, IKE, IKZE, RRSO, WIBOR, WIRON, Katowice, Warszawa,
Śląsk, Nikiszowiec, Varso Tower, ETF, S&P 500, WIG20). Returns
PL fallback on parse failure (the consumer then falls back to
`lang="pl"` rendering — no observable regression).
`lib/ai-pipeline/publish.ts` `runPipeline`:
- PL envelope strings extracted into `plTitle`/`plTagline`/
`plDescription` so the canonical fields and the localized maps
use the same source string.
- When `ANTHROPIC_API_KEY` is set, fan out 3 parallel
`translateEnvelopeFields` calls (uk/cs/en). Each `.catch(() =>
plPayload)` so a single-language outage doesn't kill the whole
publish. Aggregated into `titleLocalized` / `taglineLocalized`
/ `descriptionLocalized` Records and stamped onto the envelope.
- When the API key is absent (mock-fallback dev path) the
localized maps stay undefined; the consumer keeps showing PL
with `lang="pl"`.
Cost estimate: 3 extra Haiku calls per publish × 3 envelope
strings ≈ 60 input + 200 output tokens each = ~$0.001 per
rotation (negligible vs the existing spec translation).
Existing live envelopes (3 currently in Redis: fast/medium/slow)
were published before this commit so they have no localized maps.
They'll naturally rotate on schedule (1 h / 6 h / 12 h cycles)
and the next-generation replacements WILL be translated. An admin
backfill endpoint that re-translates currently-live envelopes is
documented as a Sprint H follow-up.
Validation:
- pnpm typecheck → 0 errors
- pnpm test → 719/719
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 73edf39 commit 8b4d7fe
2 files changed
Lines changed: 106 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
332 | 333 | | |
333 | 334 | | |
334 | 335 | | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
335 | 389 | | |
336 | 390 | | |
337 | 391 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
233 | 278 | | |
234 | 279 | | |
235 | | - | |
236 | | - | |
237 | | - | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
238 | 286 | | |
239 | 287 | | |
240 | 288 | | |
| |||
0 commit comments