Skip to content

Commit

Permalink
Merge pull request #19 from canada-ca/hotfix/localisation/dates
Browse files Browse the repository at this point in the history
fix: Update fr/index.html
  • Loading branch information
David Elisma authored May 3, 2021
2 parents ba0d271 + de236ab commit 0e21463
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 4 deletions.
90 changes: 90 additions & 0 deletions _data/locales/date.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Strings for dates
# language English
abbr_weekday:
en:
- Sun
- Mon
- Tue
- Wed
- Thu
- Fri
- Sat
fr:
- Dim
- Lun
- Mar
- Mer
- Jeu
- Ven
- Sam
full_weekday:
en:
- Sunday
- Monday
- Tuesday
- Wednesday
- Thursday
- Friday
- Saturday
fr:
- Dimanche
- Lundi
- Mardi
- Mercredi
- Jeudi
- Vendredi
- Samedi
abbr_month:
en:
- Jan
- Feb
- Mar
- Apr
- May
- Jun
- Jul
- Aug
- Sep
- Oct
- Nov
- Dec
fr:
- jan.
- fév.
- mar.
- avr.
- mai
- juin
- juil.
- août
- sept.
- oct.
- nov.
- déc.
full_month:
en:
- January
- February
- March
- April
- May
- June
- July
- August
- September
- October
- November
- December
fr:
- janvier
- février
- mars
- avril
- mai
- juin
- juillet
- août
- septembre
- octobre
- novembre
- décembre
55 changes: 55 additions & 0 deletions _includes/locale-date.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{%- comment -%}
This include allows to translate the days and months in the date by using strings in _data/locales/date.yml
This include can be called with three parameters:
- include.date: the date to be processed
- include.format: the date format. (If empty a default format will be used)
- include.lang: lang to use for translation.
{%- endcomment -%}

{%- comment -%}
If the parameter date format is empty the default format set in _config.yml is used.
If there is no default in _config, "%b %-d, %Y" is used.
{%- endcomment -%}
{%- assign locales = site.data.locales.date -%}
{%- assign date_format_to_be_translated = include.format | default: site.date_format | default: "%b %-d, %Y" -%}

{%- comment -%}
Init to have the indice of the day in the week (num_day) and the indice of the month in the year (num_mont)
Init the lang parameter depending if it's set in the include call, in the page or in the site settings
{%- endcomment -%}

{%- assign num_day = include.date | date: "%w" | plus: 0 -%}
{%- assign num_month = include.date | date: "%-m" | plus: -1 -%}
{%- assign lang = include.lang | default: page.lang | default: site.lang -%}

{%- comment -%}
Use translated abbreviated weekday if "%a" is used in the format and the translation is available in _data/locales/date.yml
{%- endcomment -%}

{%- if locales.abbr_weekday[lang][num_day] -%}
{%- assign date_format_to_be_translated = date_format_to_be_translated | replace: "%a", locales.abbr_weekday[lang][num_day] -%}
{%- endif -%}

{%- comment -%}
Use translated full weekday if "%A" is used in the format and the translation is available in _data/locales/date.yml
{%- endcomment -%}

{%- if locales.full_weekday[lang][num_day] -%}
{%- assign date_format_to_be_translated = date_format_to_be_translated | replace: "%A", locales.full_weekday[lang][num_day] -%}
{%- endif -%}

{%- comment -%}
Use translated abbreviated month if "%b" is used in the format and the translation is available in _data/locales/date.yml
{%- endcomment -%}

{%- if locales.abbr_month[lang][num_month] -%}
{%- assign date_format_to_be_translated = date_format_to_be_translated | replace: "%b", locales.abbr_month[lang][num_month] -%}
{%- endif -%}

{%- comment -%}
Use translated abbreviated weekday if "%B" is used in the format and the translation is available in _data/locales/date.yml
{%- endcomment -%}
{%- if locales.full_month[lang][num_month] -%}
{%- assign date_format_to_be_translated = date_format_to_be_translated | replace: "%B", locales.full_month[lang][num_month] -%}
{%- endif -%}
{{ include.date | date: date_format_to_be_translated }}
5 changes: 3 additions & 2 deletions en/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
layout: default
title: Canada.ca blog
---

{%- assign locales = site.data.locales.index -%}
<p>{{ locales.intro[ page.lang ] }}</p>
<section class="followus">
Expand All @@ -29,7 +30,7 @@ <h2 class="wb-inv">{{ locales.newest[ page.lang ] }}</h2>
</div>
<h3><a href="{{ post.url | remove_first: '/' | remove_first: page.lang }}" class="stretched-link">{{ post.title }}</a></h3>
<p>{{ post.description }}</p>
<p class="small"><time datetime="{{ post.date | date: "%F" }}" class="nowrap">[{{ post.date | date_to_long_string}}]</time></p>
<p class="small"><time datetime="{{ post.date | date: "%F" }}" class="nowrap">[{% include locale-date.html date=post.date format="%-d %B %Y" %}]</time></p>
</div>
</div>
{%- endfor -%}
Expand All @@ -43,7 +44,7 @@ <h2>{{ locales.searchblog[ page.lang ] }}</h2>
<li>
<h2 class="h3"><a href="{{ post.url | remove_first: '/' | remove_first: page.lang }}">{{ post.title }}</a></h2>
<p>{{ post.description }}</p>
<p class="small">{{ post.date | date_to_long_string }}</p>
<p class="small"><time datetime="{{ post.date | date: "%F" }}" class="nowrap">[{% include locale-date.html date=post.date format="%-d %B %Y" %}]</time></p>
</li>
{%- endfor -%}
</ul>
Expand Down
5 changes: 3 additions & 2 deletions fr/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
layout: default
title: Blogue de Canada.ca
---

{%- assign locales = site.data.locales.index -%}
<p>{{ locales.intro[ page.lang ] }}</p>
<section class="followus">
Expand All @@ -29,7 +30,7 @@ <h2 class="wb-inv">{{ locales.newest[ page.lang ] }}</h2>
</div>
<h3><a href="{{ post.url | remove_first: '/' | remove_first: page.lang }}" class="stretched-link">{{ post.title }}</a></h3>
<p>{{ post.description }}</p>
<p class="small"><time datetime="{{ post.date | date: "%F" }}" class="nowrap">[{{ post.date | date_to_long_string}}]</time></p>
<p class="small"><time datetime="{{ post.date | date: "%F" }}" class="nowrap">[{% include locale-date.html date=post.date format="%-d %B %Y" %}]</time></p>
</div>
</div>
{%- endfor -%}
Expand All @@ -43,7 +44,7 @@ <h2>{{ locales.searchblog[ page.lang ] }}</h2>
<li>
<h2 class="h3"><a href="{{ post.url | remove_first: '/' | remove_first: page.lang }}">{{ post.title }}</a></h2>
<p>{{ post.description }}</p>
<p class="small">{{ post.date | date_to_long_string }}</p>
<p class="small"><time datetime="{{ post.date | date: "%F" }}" class="nowrap">[{% include locale-date.html date=post.date format="%-d %B %Y" %}]</time></p>
</li>
{%- endfor -%}
</ul>
Expand Down

0 comments on commit 0e21463

Please sign in to comment.