Add i18n support for date spans and event labels in OG image - #18
Merged
Conversation
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.
|
🔗 Deploy preview: https://6a00dcc2e7d5c44d2636c181--closerintimewiki.netlify.app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
interpolate()function: Resolves{name}-style placeholder substitution in template stringsresolvePlural()function: Handles ICU plural message syntax (e.g.,{count, plural, one {# year} other {# years}}) with proper locale-aware plural rules viaIntl.PluralRulesmakeTranslator()function: Factory function that creates locale-aware translator functions for specific message namespacescomputeTimeline()call: Now passes the user's selected language (lang) instead of hardcoded "en-US", and provides a translator function (spanT) for date span formattingeventDisplayName()calls: Now passes an event label translator (eventLabelT) to support translated event namesImplementation Details
=0) and locale-specific plural categories (one, other, few, many, etc.)#character in plural branches is replaced with the actual count valuehttps://claude.ai/code/session_011KuHfmw1stcTUTwH4gCZya