Skip to content

Add i18n support for date spans and event labels in OG image - #18

Merged
enricobattocchi merged 1 commit into
mainfrom
claude/fix-api-language-display-Vp7Rs
May 10, 2026
Merged

Add i18n support for date spans and event labels in OG image#18
enricobattocchi merged 1 commit into
mainfrom
claude/fix-api-language-display-Vp7Rs

Conversation

@enricobattocchi

Copy link
Copy Markdown
Owner

Summary

This PR adds internationalization (i18n) support for date span formatting and event labels in the Open Graph image generation route. Previously, date spans were hardcoded to use English locale ("en-US"), and event labels had no translation support.

Key Changes

  • Added interpolate() function: Resolves {name}-style placeholder substitution in template strings
  • Added resolvePlural() function: Handles ICU plural message syntax (e.g., {count, plural, one {# year} other {# years}}) with proper locale-aware plural rules via Intl.PluralRules
  • Added makeTranslator() function: Factory function that creates locale-aware translator functions for specific message namespaces
  • Updated computeTimeline() call: Now passes the user's selected language (lang) instead of hardcoded "en-US", and provides a translator function (spanT) for date span formatting
  • Updated eventDisplayName() calls: Now passes an event label translator (eventLabelT) to support translated event names

Implementation Details

  • The plural resolution supports both explicit count matching (e.g., =0) and locale-specific plural categories (one, other, few, many, etc.)
  • The # character in plural branches is replaced with the actual count value
  • Fallback behavior: if a translation key is missing, the key itself is returned; if a plural category is not found, "other" is used as fallback
  • Translators are created once per request for the selected language and message namespace, improving efficiency

https://claude.ai/code/session_011KuHfmw1stcTUTwH4gCZya

The /api/og route was passing the lang param to fetchWikidataEvents
(so Wikidata labels came back localized), but downstream rendering
fell back to English: eventDisplayName was called without a t function
(hardcoded "Birth of...", "Death of..."), computeTimeline was called
without spanT (defaultSpanT returns "year/years"), and the locale was
hardcoded to "en-US" so month names rendered in English.

Add a small ICU plural resolver and wire translators for the eventLabel
and date namespaces, and pass the requested lang as the locale.
@github-actions

Copy link
Copy Markdown

@enricobattocchi
enricobattocchi merged commit aace1bb into main May 10, 2026
1 check passed
@enricobattocchi
enricobattocchi deleted the claude/fix-api-language-display-Vp7Rs branch May 10, 2026 19:42
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.

2 participants