Skip to content

feat: support i18nMonth for date in list item #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hucste
Copy link
Contributor

@hucste hucste commented Aug 5, 2020

if i18n exists, the month into this list item is not correctly displayed. Actually, only in english.
With this fixe, month is displayed segun language code.

@reuixiy
Copy link
Owner

reuixiy commented Aug 8, 2020

So as the comment in config.toml,

# Translate the month? (valid for title)
i18nMonth = false

I don't think this is a bug. Though, it could be an enhancement.

Also, in your code, if i18nMonth is enabled, then the listDateFormat will not be respected -- it's hard-coded to "January 2" format. But there are many different date formats in different countries, see:

In other words, the character is i18ned but the format is not, or is destroyed.

@reuixiy reuixiy changed the title Fix: display correctly month if languageCode ne EN feat: support i18nMonth for date in list item Aug 8, 2020
@hucste
Copy link
Contributor Author

hucste commented Aug 8, 2020

Ok, I understand the problem. For the moment, I don't known how fix it.
but you have to admit that having the dates, once in FR (or other lang), once in EN, so sucks. :(
(I thought I'd come up with a solution and move things along...)

@reuixiy reuixiy force-pushed the main branch 3 times, most recently from 2254ba4 to 535b7f6 Compare February 19, 2025 04:12
@reuixiy reuixiy requested a review from Copilot June 7, 2025 05:03
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for an i18nMonth parameter to render translated month names in list items and handles a French-specific ordinal for the first day.

  • Introduces a conditional on .Site.Params.i18nMonth
  • Extracts and translates the month via i18n
  • Applies a <sup>er</sup> suffix for French “1er” dates
Comments suppressed due to low confidence (1)

layouts/partials/utils/list-item.html:19

  • This introduces a new i18nMonth config flag. Please update the project’s configuration reference or README to document this parameter and the expected translation keys for month names.
{{ if .Site.Params.i18nMonth }}

<time datetime="{{ .PublishDate.Format "2006-01-02T15:04:05-07:00" }}" class="list-item-time">{{ .PublishDate.Format .Site.Params.listDateFormat }}</time>
<time datetime="{{ .PublishDate.Format "2006-01-02T15:04:05-07:00" }}" class="list-item-time">
{{ if .Site.Params.i18nMonth }}
{{ $month := .PublishDate.Format "January" }}{{ $month := i18n (lower $month) }}
Copy link
Preview

Copilot AI Jun 7, 2025

Choose a reason for hiding this comment

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

Declaring $month twice can be confusing and may shadow variables. Consider combining into a single statement, e.g.: {{ $month := i18n (lower .PublishDate.Format "January") }}.

Suggested change
{{ $month := .PublishDate.Format "January" }}{{ $month := i18n (lower $month) }}
{{ $month := i18n (lower .PublishDate.Format "January") }}

Copilot uses AI. Check for mistakes.

{{ if .Site.Params.i18nMonth }}
{{ $month := .PublishDate.Format "January" }}{{ $month := i18n (lower $month) }}
{{ $day := .PublishDate.Format "2" }}
{{ if findRE "fr" .Site.LanguageCode }}{{ $day }}{{ if eq $day "1" }}<sup>er</sup>{{ end }} {{ $month }}
Copy link
Preview

Copilot AI Jun 7, 2025

Choose a reason for hiding this comment

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

Using findRE to detect the French locale can match unintended codes. Prefer hasPrefix or a direct equality check, e.g.: {{ if hasPrefix .Site.LanguageCode "fr" }} or {{ if eq .Site.LanguageCode "fr" }}.

Suggested change
{{ if findRE "fr" .Site.LanguageCode }}{{ $day }}{{ if eq $day "1" }}<sup>er</sup>{{ end }} {{ $month }}
{{ if hasPrefix .Site.LanguageCode "fr" }}{{ $day }}{{ if eq $day "1" }}<sup>er</sup>{{ end }} {{ $month }}

Copilot uses AI. Check for mistakes.

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