Skip to content

Commit

Permalink
perf(i18n): set the global default locales to "en" (cotes2020#979)
Browse files Browse the repository at this point in the history
- avoid missing labels caused by languages ​​outside of locales
- also improved the code style
  • Loading branch information
cotes2020 authored and seod0209 committed Feb 25, 2024
1 parent 89b9625 commit 2840c9c
Show file tree
Hide file tree
Showing 19 changed files with 513 additions and 562 deletions.
28 changes: 20 additions & 8 deletions _includes/datetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,30 @@
See: ${JS_ROOT}/utils/locale-dateime.js
-->

{% assign df_strftime = site.data.locales[include.lang].df.post.strftime | default: '%d/%m/%Y' %}
{% assign df_dayjs = site.data.locales[include.lang].df.post.dayjs | default: 'DD/MM/YYYY' %}
{% assign df_strftime = site.data.locales[include.lang].df.post.strftime |
default: '%d/%m/%Y' %} {% assign df_dayjs =
site.data.locales[include.lang].df.post.dayjs | default: 'DD/MM/YYYY' %}

<time
{% if include.class %}
class="{{ include.class }}"
{% endif %}
{%
if
include.class
%}
class="{{ include.class }}"
{%
endif
%}
data-ts="{{ include.date | date: '%s' }}"
data-df="{{ df_dayjs }}"
{% if include.tooltip %}
data-bs-toggle="tooltip" data-bs-placement="bottom"
{% endif %}
{%
if
include.tooltip
%}
data-bs-toggle="tooltip"
data-bs-placement="bottom"
{%
endif
%}
>
{{ include.date | date: df_strftime }}
</time>
46 changes: 21 additions & 25 deletions _includes/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,37 @@

<footer
aria-label="Site Info"
class="
d-flex flex-column justify-content-center text-muted
flex-lg-row justify-content-lg-between align-items-lg-center pb-lg-3
"
class="d-flex flex-column justify-content-center text-muted flex-lg-row justify-content-lg-between align-items-lg-center pb-lg-3"
>
<p>
{{- '©' }}
<time>{{ 'now' | date: '%Y' }}</time>

{% if site.social.links %}
<a href="{{ site.social.links[0] }}">{{ site.social.name }}</a>.
{% else %}
<em class="fst-normal">{{ site.social.name }}</em>.
{% endif %}

{% if site.data.locales[include.lang].copyright.brief %}
<span
data-bs-toggle="tooltip"
data-bs-placement="top"
title="{{ site.data.locales[include.lang].copyright.verbose }}"
>
{{- site.data.locales[include.lang].copyright.brief -}}
</span>
<a href="{{ site.social.links[0] }}">{{ site.social.name }}</a>. {% else %}
<em class="fst-normal">{{ site.social.name }}</em>. {% endif %} {% if
site.data.locales[include.lang].copyright.brief %}
<span
data-bs-toggle="tooltip"
data-bs-placement="top"
title="{{ site.data.locales[include.lang].copyright.verbose }}"
>
{{- site.data.locales[include.lang].copyright.brief -}}
</span>
{% endif %}
</p>

<p>
{%- capture _platform -%}
<a href="https://jekyllrb.com" target="_blank" rel="noopener">Jekyll</a>
{%- endcapture -%}

{%- capture _theme -%}
<a href="https://github.com/cotes2020/jekyll-theme-chirpy" target="_blank" rel="noopener">Chirpy</a>
{%- endcapture -%}

{{ site.data.locales[include.lang].meta | replace: ':PLATFORM', _platform | replace: ':THEME', _theme }}
<a href="https://jekyllrb.com" target="_blank" rel="noopener">Jekyll</a>
{%- endcapture -%} {%- capture _theme -%}
<a
href="https://github.com/cotes2020/jekyll-theme-chirpy"
target="_blank"
rel="noopener"
>Chirpy</a
>
{%- endcapture -%} {{ site.data.locales[include.lang].meta | replace:
':PLATFORM', _platform | replace: ':THEME', _theme }}
</p>
</footer>
54 changes: 27 additions & 27 deletions _includes/post-nav.html
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
<!-- Navigation buttons at the bottom of the post. -->

<nav class="post-navigation d-flex justify-content-between" aria-label="Post Navigation">
<nav
class="post-navigation d-flex justify-content-between"
aria-label="Post Navigation"
>
{% assign previous = site.data.locales[include.lang].post.button.previous %}
{% assign next = site.data.locales[include.lang].post.button.next %}

{% if page.previous.url %}
<a
href="{{ site.baseurl }}{{ page.previous.url }}"
class="btn btn-outline-primary"
aria-label="{{ previous }}"
>
<p>{{ page.previous.title }}</p>
</a>
{% assign next = site.data.locales[include.lang].post.button.next %} {% if
page.previous.url %}
<a
href="{{ site.baseurl }}{{ page.previous.url }}"
class="btn btn-outline-primary"
aria-label="{{ previous }}"
>
<p>{{ page.previous.title }}</p>
</a>
{% else %}
<div class="btn btn-outline-primary disabled" aria-label="{{ previous }}">
<p>-</p>
</div>
{% endif %}

{% if page.next.url %}
<a
href="{{ site.baseurl }}{{page.next.url}}"
class="btn btn-outline-primary"
aria-label="{{ next }}"
>
<p>{{ page.next.title }}</p>
</a>
<div class="btn btn-outline-primary disabled" aria-label="{{ previous }}">
<p>-</p>
</div>
{% endif %} {% if page.next.url %}
<a
href="{{ site.baseurl }}{{page.next.url}}"
class="btn btn-outline-primary"
aria-label="{{ next }}"
>
<p>{{ page.next.title }}</p>
</a>
{% else %}
<div class="btn btn-outline-primary disabled" aria-label="{{ next }}">
<p>-</p>
</div>
<div class="btn btn-outline-primary disabled" aria-label="{{ next }}">
<p>-</p>
</div>
{% endif %}
</nav>
67 changes: 36 additions & 31 deletions _includes/post-sharing.html
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
<!-- Post sharing snippet -->

<div class="share-wrapper d-flex align-items-center">
<span class="share-label text-muted">{{ site.data.locales[include.lang].post.share }}</span>
<span class="share-label text-muted"
>{{ site.data.locales[include.lang].post.share }}</span
>
<span class="share-icons">
{% capture title %}{{ page.title }} - {{ site.title }}{% endcapture %}
{% assign title = title | uri_escape %}
{% assign url = page.url | absolute_url | url_encode %}

{% for share in site.data.share.platforms -%}
{%- capture tooltip -%}
data-bs-toggle="tooltip" data-bs-placement="top" title="{{ share.type }}" aria-label="{{ share.type }}"
{%- endcapture -%}

{% if share.type == 'Mastodon' %}
<script defer type="module" src="https://cdn.jsdelivr.net/npm/@justinribeiro/share-to-mastodon/+esm"></script>
<button class="btn text-start" {{ tooltip }}>
<share-to-mastodon
class="share-mastodon"
message="{{ title }}"
url="{{ url }}"
{%- if share.instances -%}
customInstanceList="{{ share.instances | jsonify | xml_escape }}"
{%- endif %}
>
<i class="fa-fw {{ share.icon }}"></i>
</share-to-mastodon>
</button>

{% continue %}
{% endif %}
{% capture title %}{{ page.title }} - {{ site.title }}{% endcapture %} {%
assign title = title | uri_escape %} {% assign url = page.url | absolute_url
| url_encode %} {% for share in site.data.share.platforms -%} {%- capture
tooltip -%} data-bs-toggle="tooltip" data-bs-placement="top" title="{{
share.type }}" aria-label="{{ share.type }}" {%- endcapture -%} {% if
share.type == 'Mastodon' %}
<script
defer
type="module"
src="https://cdn.jsdelivr.net/npm/@justinribeiro/share-to-mastodon/+esm"
></script>
<button class="btn text-start" {{ tooltip }}>
<share-to-mastodon
class="share-mastodon"
message="{{ title }}"
url="{{ url }}"
{%-
if
share.instances
-%}
customInstanceList="{{ share.instances | jsonify | xml_escape }}"
{%-
endif
%}
>
<i class="fa-fw {{ share.icon }}"></i>
</share-to-mastodon>
</button>

{% assign link = share.link | replace: 'TITLE', title | replace: 'URL', url %}
{% continue %} {% endif %} {% assign link = share.link | replace: 'TITLE',
title | replace: 'URL', url %}

<a href="{{ link }}" target="_blank" rel="noopener" {{ tooltip }}>
<i class="fa-fw {{ share.icon }}"></i>
</a>
<a href="{{ link }}" target="_blank" rel="noopener" {{ tooltip }}>
<i class="fa-fw {{ share.icon }}"></i>
</a>
{% endfor %}

<button
Expand Down
29 changes: 9 additions & 20 deletions _includes/read-time.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,10 @@

<!-- words per minute -->

{% assign wpm = 180 %}
{% assign min_time = 1 %}

{% assign read_time = words | divided_by: wpm %}

{% unless read_time > 0 %}
{% assign read_time = min_time %}
{% endunless %}

{% capture read_prompt %}
{{- site.data.locales[include.lang].post.read_time.prompt -}}
{% endcapture %}
{% assign wpm = 180 %} {% assign min_time = 1 %} {% assign read_time = words |
divided_by: wpm %} {% unless read_time > 0 %} {% assign read_time = min_time %}
{% endunless %} {% capture read_prompt %} {{-
site.data.locales[include.lang].post.read_time.prompt -}} {% endcapture %}

<!-- return element -->
<span
Expand All @@ -25,13 +17,10 @@
title="{{ words }} {{ site.data.locales[include.lang].post.words }}"
>
<em>
{{- read_time -}}
{{ ' ' }}
{{- site.data.locales[include.lang].post.read_time.unit -}}
{{- read_time -}} {{ ' ' }} {{-
site.data.locales[include.lang].post.read_time.unit -}}
</em>
{%- if include.prompt -%}
{%- assign _prompt_words = read_prompt | number_of_words: 'auto' -%}
{%- unless _prompt_words > 1 -%}{{ ' ' }}{%- endunless -%}
{{ read_prompt }}
{%- endif -%}
{%- if include.prompt -%} {%- assign _prompt_words = read_prompt |
number_of_words: 'auto' -%} {%- unless _prompt_words > 1 -%}{{ ' ' }}{%-
endunless -%} {{ read_prompt }} {%- endif -%}
</span>
Loading

0 comments on commit 2840c9c

Please sign in to comment.