Skip to content

Commit

Permalink
perf(i18n): set the global default locales to "en" (#979)
Browse files Browse the repository at this point in the history
Avoid missing labels caused by languages ​​outside of locales.
  • Loading branch information
cotes2020 committed May 5, 2023
1 parent aca79c1 commit 61fdbcb
Show file tree
Hide file tree
Showing 23 changed files with 423 additions and 348 deletions.
16 changes: 10 additions & 6 deletions _includes/datetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
-->

{% assign wrap_elem = include.wrap | default: 'em' %}
{% assign df_strftime = site.data.locales[site.lang].df.post.strftime | default: '%d/%m/%Y' %}
{% assign df_dayjs = site.data.locales[site.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' %}

<{{ wrap_elem }} class="{% if include.class %}{{ include.class }}{% endif %}"
data-ts="{{ include.date | date: '%s' }}"
data-df="{{ df_dayjs }}"
{% if include.tooltip %}data-toggle="tooltip" data-placement="bottom"{% endif %}>
<{{ wrap_elem }}
class="{% if include.class %}{{ include.class }}{% endif %}"
data-ts="{{ include.date | date: '%s' }}"
data-df="{{ df_dayjs }}"
{% if include.tooltip %}
data-toggle="tooltip" data-placement="bottom"
{% endif %}
>
{{ include.date | date: df_strftime }}
</{{ wrap_elem }}>
20 changes: 13 additions & 7 deletions _includes/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
<div class="d-flex justify-content-between align-items-center text-muted ml-md-3 mr-md-3">
<div class="footer-left">
<p class="mb-0">
© {{ 'now' | date: "%Y" }}
© {{ 'now' | date: '%Y' }}
<a href="{{ site.social.links[0] }}">{{ site.social.name }}</a>.
{% if site.data.locales[site.lang].copyright.brief %}
<span data-toggle="tooltip" data-placement="top"
title="{{ site.data.locales[site.lang].copyright.verbose }}">{{ site.data.locales[site.lang].copyright.brief }}</span>
{% if site.data.locales[include.lang].copyright.brief %}
<span
data-toggle="tooltip"
data-placement="top"
title="{{ site.data.locales[include.lang].copyright.verbose }}"
>
{{- site.data.locales[include.lang].copyright.brief -}}
</span>
{% endif %}
</p>
</div>

<div class="footer-right">
<p class="mb-0">

{%- capture _platform -%}
<a href="https://jekyllrb.com" target="_blank" rel="noopener">Jekyll</a>
{%- endcapture -%}
Expand All @@ -25,9 +29,11 @@
<a href="https://github.com/cotes2020/jekyll-theme-chirpy" target="_blank" rel="noopener">Chirpy</a>
{%- endcapture -%}

{{ site.data.locales[site.lang].meta
{{
site.data.locales[include.lang].meta
| default: 'Using the :PLATFORM theme :THEME.'
| replace: ':PLATFORM', _platform | replace: ':THEME', _theme
| replace: ':PLATFORM', _platform
| replace: ':THEME', _theme
}}
</p>
</div>
Expand Down
8 changes: 8 additions & 0 deletions _includes/lang.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% comment %}
Detect appearance language and return it through variable "lang"
{% endcomment %}
{% if site.data.locales[site.lang] %}
{% assign lang = site.lang %}
{% else %}
{% assign lang = 'en' %}
{% endif %}
47 changes: 27 additions & 20 deletions _includes/post-nav.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
<!--
Navigation buttons at the bottom of the post.
-->
<!-- Navigation buttons at the bottom of the post. -->

<div class="post-navigation d-flex justify-content-between">
{% if page.previous.url %}
<a href="{{ site.baseurl }}{{ page.previous.url }}" class="btn btn-outline-primary"
prompt="{{ site.data.locales[site.lang].post.button.previous }}">
<p>{{ page.previous.title }}</p>
</a>
<a
href="{{ site.baseurl }}{{ page.previous.url }}"
class="btn btn-outline-primary"
prompt="{{ site.data.locales[include.lang].post.button.previous }}"
>
<p>{{ page.previous.title }}</p>
</a>
{% else %}
<div class="btn btn-outline-primary disabled"
prompt="{{ site.data.locales[site.lang].post.button.previous }}">
<p>-</p>
</div>
<div
class="btn btn-outline-primary disabled"
prompt="{{ site.data.locales[include.lang].post.button.previous }}"
>
<p>-</p>
</div>
{% endif %}

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

</div>
34 changes: 21 additions & 13 deletions _includes/post-sharing.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
<!--
Post sharing snippet
-->
<!-- Post sharing snippet -->

<div class="share-wrapper">
<span class="share-label text-muted mr-1">{{ site.data.locales[site.lang].post.share }}</span>
<span class="share-label text-muted mr-1">{{ 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 %}
{% assign link = share.link | replace: 'TITLE', title | replace: 'URL', url %}
<a href="{{ link }}" data-toggle="tooltip" data-placement="top"
title="{{ share.type }}" target="_blank" rel="noopener" aria-label="{{ share.type }}">
<i class="fa-fw {{ share.icon }}"></i>
</a>
<a
href="{{ link }}"
data-toggle="tooltip"
data-placement="top"
title="{{ share.type }}"
target="_blank"
rel="noopener"
aria-label="{{ share.type }}"
>
<i class="fa-fw {{ share.icon }}"></i>
</a>
{% endfor %}

<i id="copy-link" class="fa-fw fas fa-link small"
data-toggle="tooltip" data-placement="top"
title="{{ site.data.locales[site.lang].post.button.share_link.title }}"
data-title-succeed="{{ site.data.locales[site.lang].post.button.share_link.succeed }}">
<i
id="copy-link"
class="fa-fw fas fa-link small"
data-toggle="tooltip"
data-placement="top"
title="{{ site.data.locales[include.lang].post.button.share_link.title }}"
data-title-succeed="{{ site.data.locales[include.lang].post.button.share_link.succeed }}"
>
</i>

</span>
</div>
27 changes: 17 additions & 10 deletions _includes/read-time.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<!--
Calculate the post's reading time, and display the word count in tooltip
-->
<!-- Calculate the post's reading time, and display the word count in tooltip -->

{% assign words = include.content | strip_html | number_of_words: "auto" %}
{% assign words = include.content | strip_html | number_of_words: 'auto' %}

<!-- words per minute -->
<!-- words per minute -->

{% assign wpm = 180 %}
{% assign min_time = 1 %}
Expand All @@ -16,15 +14,24 @@
{% endunless %}

{% capture read_prompt %}
{{- site.data.locales[site.lang].post.read_time.prompt -}}
{{- site.data.locales[include.lang].post.read_time.prompt -}}
{% endcapture %}

<!-- return element -->
<span class="readtime" data-toggle="tooltip" data-placement="bottom"
title="{{ words }} {{ site.data.locales[site.lang].post.words }}">
<em>{{- read_time -}}{{" "}}{{- site.data.locales[site.lang].post.read_time.unit -}}</em>
<span
class="readtime"
data-toggle="tooltip"
data-placement="bottom"
title="{{ words }} {{ site.data.locales[include.lang].post.words }}"
>
<em>
{{- 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 }}
{%- unless _prompt_words > 1 -%}{{ ' ' }}{%- endunless -%}
{{ read_prompt }}
{%- endif -%}
</span>
2 changes: 1 addition & 1 deletion _includes/refactor-content.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
| append: '<div class="code-header">'
| append: _label
| append: '<button aria-label="copy" data-title-succeed="'
| append: site.data.locales[site.lang].post.button.copy_code.succeed
| append: site.data.locales[include.lang].post.button.copy_code.succeed
| append: '"><i class="far fa-clipboard"></i></button></div>'
| append: '<div class="highlight"><code>'
%}
Expand Down
70 changes: 37 additions & 33 deletions _includes/related-posts.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<!--
Recommend the other 3 posts according to the tags and categories of the current post,
if the number is not enough, use the other latest posts to supplement.
Recommend the other 3 posts according to the tags and categories of the current post,
if the number is not enough, use the other latest posts to supplement.
-->

<!-- The total size of related posts -->
<!-- The total size of related posts -->
{% assign TOTAL_SIZE = 3 %}

<!-- An random integer that bigger than 0 -->
<!-- An random integer that bigger than 0 -->
{% assign TAG_SCORE = 1 %}

<!-- Equals to TAG_SCORE / {max_categories_hierarchy} -->
<!-- Equals to TAG_SCORE / {max_categories_hierarchy} -->
{% assign CATEGORY_SCORE = 0.5 %}

{% assign SEPARATOR = ":" %}
{% assign SEPARATOR = ':' %}

{% assign score_list = "" | split: "" %}
{% assign score_list = '' | split: '' %}
{% assign last_index = site.posts.size | minus: 1 %}

{% for i in (0..last_index) %}
Expand Down Expand Up @@ -42,11 +42,9 @@
{% capture score_item %}{{ score }}{{ SEPARATOR }}{{ i }}{% endcapture %}
{% assign score_list = score_list | push: score_item %}
{% endif %}

{% endfor %}


{% assign index_list = "" | split: "" %}
{% assign index_list = '' | split: '' %}

{% if score_list.size > 0 %}
{% assign score_list = score_list | sort | reverse %}
Expand All @@ -56,13 +54,13 @@
{% endfor %}
{% endif %}

<!-- Fill with the other newlest posts -->
<!-- Fill with the other newlest posts -->
{% assign less = TOTAL_SIZE | minus: index_list.size %}

{% if less > 0 %}
{% for i in (0..last_index) %}
{% assign post = site.posts[i] %}
{% if post.url != page.url %}
{% if post.url != page.url %}
{% capture cur_index %}{{ i }}{% endcapture %}
{% unless index_list contains cur_index %}
{% assign index_list = index_list | push: cur_index %}
Expand All @@ -77,27 +75,33 @@

{% if index_list.size > 0 %}
<div id="related-posts" class="mb-2 mb-sm-4">
<h3 class="pt-2 mb-4 ml-1"
data-toc-skip>{{ site.data.locales[site.lang].post.relate_posts }}</h3>
<h3
class="pt-2 mb-4 ml-1"
data-toc-skip
>
{{ site.data.locales[include.lang].post.relate_posts }}
</h3>
<div class="card-deck mb-4">
{% for entry in index_list %}
{% assign index = entry | plus: 0 %}
{% assign post = site.posts[index] %}
<div class="card">
<a href="{{ post.url | relative_url }}">
<div class="card-body">
{% include datetime.html date=post.date class="small" %}
<h3 class="pt-0 mt-1 mb-3" data-toc-skip>{{ post.title }}</h3>
<div class="text-muted small">
<p>
{% include no-linenos.html content=post.content %}
{{ content | markdownify | strip_html | truncate: 200 | escape }}
</p>
{% for entry in index_list %}
{% assign index = entry | plus: 0 %}
{% assign post = site.posts[index] %}
<div class="card">
<a href="{{ post.url | relative_url }}">
<div class="card-body">
{% include datetime.html date=post.date class="small" lang=include.lang %}
<h3 class="pt-0 mt-1 mb-3" data-toc-skip>{{ post.title }}</h3>
<div class="text-muted small">
<p>
{% include no-linenos.html content=post.content %}
{{ content | markdownify | strip_html | truncate: 200 | escape }}
</p>
</div>
</div>
</div>
</a>
</div>
{% endfor %}
</div> <!-- .card-deck -->
</div> <!-- #related-posts -->
</a>
</div>
{% endfor %}
</div>
<!-- .card-deck -->
</div>
<!-- #related-posts -->
{% endif %}
2 changes: 1 addition & 1 deletion _includes/search-loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>
{% endcapture %}

{% capture not_found %}<p class="mt-5">{{ site.data.locales[site.lang].search.no_results }}</p>{% endcapture %}
{% capture not_found %}<p class="mt-5">{{ site.data.locales[include.lang].search.no_results }}</p>{% endcapture %}

<script src="{{ site.data.assets[origin].search.js | relative_url }}"></script>

Expand Down

0 comments on commit 61fdbcb

Please sign in to comment.