Skip to content

fix(BlogList): support arbitrary locale for date formatting#96

Merged
SoonIter merged 1 commit into
rstackjs:mainfrom
dragomano:blog_list
May 21, 2026
Merged

fix(BlogList): support arbitrary locale for date formatting#96
SoonIter merged 1 commit into
rstackjs:mainfrom
dragomano:blog_list

Conversation

@dragomano
Copy link
Copy Markdown
Contributor

Problem

The BlogList component accepts a lang prop, but date formatting ignores it. The locale is hardcoded to either zh-CN or en-US, so any other language (Russian, German, Japanese, etc.) always renders dates in English format regardless of the lang value passed.

Root cause

In BlogList, the Intl.DateTimeFormat instance is created with a hardcoded locale:

const dateFormatter = new Intl.DateTimeFormat('zh' === lang ? 'zh-CN' : 'en-US', dateFormatOptions);

Fix

Pass lang directly to Intl.DateTimeFormat, keeping the zhzh-CN normalization and falling back to en-US only when lang is not provided:

const dateFormatter = new Intl.DateTimeFormat(lang === 'zh' ? 'zh-CN' : lang || 'en-US', dateFormatOptions);

Why this is safe

Intl.DateTimeFormat accepts any valid BCP 47 language tag. If an unsupported tag is passed, it falls back gracefully. Existing behavior for zh and en is unchanged.

Fixes #95

@SoonIter SoonIter changed the title BlogList: support arbitrary locale for date formatting fix(BlogList): support arbitrary locale for date formatting May 21, 2026
@SoonIter SoonIter merged commit 0a5ca0f into rstackjs:main May 21, 2026
2 of 3 checks passed
@dragomano dragomano deleted the blog_list branch May 21, 2026 03:44
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.

BlogList: date formatting ignores lang prop, always renders in English

2 participants