Skip to content

Commit 61fdbcb

Browse files
committed
perf(i18n): set the global default locales to "en" (cotes2020#979)
Avoid missing labels caused by languages ​​outside of locales.
1 parent aca79c1 commit 61fdbcb

23 files changed

+423
-348
lines changed

_includes/datetime.html

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
-->
55

66
{% assign wrap_elem = include.wrap | default: 'em' %}
7-
{% assign df_strftime = site.data.locales[site.lang].df.post.strftime | default: '%d/%m/%Y' %}
8-
{% assign df_dayjs = site.data.locales[site.lang].df.post.dayjs | default: 'DD/MM/YYYY' %}
7+
{% assign df_strftime = site.data.locales[include.lang].df.post.strftime | default: '%d/%m/%Y' %}
8+
{% assign df_dayjs = site.data.locales[include.lang].df.post.dayjs | default: 'DD/MM/YYYY' %}
99

10-
<{{ wrap_elem }} class="{% if include.class %}{{ include.class }}{% endif %}"
11-
data-ts="{{ include.date | date: '%s' }}"
12-
data-df="{{ df_dayjs }}"
13-
{% if include.tooltip %}data-toggle="tooltip" data-placement="bottom"{% endif %}>
10+
<{{ wrap_elem }}
11+
class="{% if include.class %}{{ include.class }}{% endif %}"
12+
data-ts="{{ include.date | date: '%s' }}"
13+
data-df="{{ df_dayjs }}"
14+
{% if include.tooltip %}
15+
data-toggle="tooltip" data-placement="bottom"
16+
{% endif %}
17+
>
1418
{{ include.date | date: df_strftime }}
1519
</{{ wrap_elem }}>

_includes/footer.html

+13-7
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@
55
<div class="d-flex justify-content-between align-items-center text-muted ml-md-3 mr-md-3">
66
<div class="footer-left">
77
<p class="mb-0">
8-
© {{ 'now' | date: "%Y" }}
8+
© {{ 'now' | date: '%Y' }}
99
<a href="{{ site.social.links[0] }}">{{ site.social.name }}</a>.
10-
{% if site.data.locales[site.lang].copyright.brief %}
11-
<span data-toggle="tooltip" data-placement="top"
12-
title="{{ site.data.locales[site.lang].copyright.verbose }}">{{ site.data.locales[site.lang].copyright.brief }}</span>
10+
{% if site.data.locales[include.lang].copyright.brief %}
11+
<span
12+
data-toggle="tooltip"
13+
data-placement="top"
14+
title="{{ site.data.locales[include.lang].copyright.verbose }}"
15+
>
16+
{{- site.data.locales[include.lang].copyright.brief -}}
17+
</span>
1318
{% endif %}
1419
</p>
1520
</div>
1621

1722
<div class="footer-right">
1823
<p class="mb-0">
19-
2024
{%- capture _platform -%}
2125
<a href="https://jekyllrb.com" target="_blank" rel="noopener">Jekyll</a>
2226
{%- endcapture -%}
@@ -25,9 +29,11 @@
2529
<a href="https://github.com/cotes2020/jekyll-theme-chirpy" target="_blank" rel="noopener">Chirpy</a>
2630
{%- endcapture -%}
2731

28-
{{ site.data.locales[site.lang].meta
32+
{{
33+
site.data.locales[include.lang].meta
2934
| default: 'Using the :PLATFORM theme :THEME.'
30-
| replace: ':PLATFORM', _platform | replace: ':THEME', _theme
35+
| replace: ':PLATFORM', _platform
36+
| replace: ':THEME', _theme
3137
}}
3238
</p>
3339
</div>

_includes/lang.html

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{% comment %}
2+
Detect appearance language and return it through variable "lang"
3+
{% endcomment %}
4+
{% if site.data.locales[site.lang] %}
5+
{% assign lang = site.lang %}
6+
{% else %}
7+
{% assign lang = 'en' %}
8+
{% endif %}

_includes/post-nav.html

+27-20
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
1-
<!--
2-
Navigation buttons at the bottom of the post.
3-
-->
1+
<!-- Navigation buttons at the bottom of the post. -->
42

53
<div class="post-navigation d-flex justify-content-between">
64
{% if page.previous.url %}
7-
<a href="{{ site.baseurl }}{{ page.previous.url }}" class="btn btn-outline-primary"
8-
prompt="{{ site.data.locales[site.lang].post.button.previous }}">
9-
<p>{{ page.previous.title }}</p>
10-
</a>
5+
<a
6+
href="{{ site.baseurl }}{{ page.previous.url }}"
7+
class="btn btn-outline-primary"
8+
prompt="{{ site.data.locales[include.lang].post.button.previous }}"
9+
>
10+
<p>{{ page.previous.title }}</p>
11+
</a>
1112
{% else %}
12-
<div class="btn btn-outline-primary disabled"
13-
prompt="{{ site.data.locales[site.lang].post.button.previous }}">
14-
<p>-</p>
15-
</div>
13+
<div
14+
class="btn btn-outline-primary disabled"
15+
prompt="{{ site.data.locales[include.lang].post.button.previous }}"
16+
>
17+
<p>-</p>
18+
</div>
1619
{% endif %}
1720

1821
{% if page.next.url %}
19-
<a href="{{ site.baseurl }}{{page.next.url}}" class="btn btn-outline-primary"
20-
prompt="{{ site.data.locales[site.lang].post.button.next }}">
21-
<p>{{ page.next.title }}</p>
22-
</a>
22+
<a
23+
href="{{ site.baseurl }}{{page.next.url}}"
24+
class="btn btn-outline-primary"
25+
prompt="{{ site.data.locales[include.lang].post.button.next }}"
26+
>
27+
<p>{{ page.next.title }}</p>
28+
</a>
2329
{% else %}
24-
<div class="btn btn-outline-primary disabled"
25-
prompt="{{ site.data.locales[site.lang].post.button.next }}">
26-
<p>-</p>
27-
</div>
30+
<div
31+
class="btn btn-outline-primary disabled"
32+
prompt="{{ site.data.locales[include.lang].post.button.next }}"
33+
>
34+
<p>-</p>
35+
</div>
2836
{% endif %}
29-
3037
</div>

_includes/post-sharing.html

+21-13
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
1-
<!--
2-
Post sharing snippet
3-
-->
1+
<!-- Post sharing snippet -->
42

53
<div class="share-wrapper">
6-
<span class="share-label text-muted mr-1">{{ site.data.locales[site.lang].post.share }}</span>
4+
<span class="share-label text-muted mr-1">{{ site.data.locales[include.lang].post.share }}</span>
75
<span class="share-icons">
86
{% capture title %}{{ page.title }} - {{ site.title }}{% endcapture %}
97
{% assign title = title | uri_escape %}
108
{% assign url = page.url | absolute_url | url_encode %}
119

1210
{% for share in site.data.share.platforms %}
1311
{% assign link = share.link | replace: 'TITLE', title | replace: 'URL', url %}
14-
<a href="{{ link }}" data-toggle="tooltip" data-placement="top"
15-
title="{{ share.type }}" target="_blank" rel="noopener" aria-label="{{ share.type }}">
16-
<i class="fa-fw {{ share.icon }}"></i>
17-
</a>
12+
<a
13+
href="{{ link }}"
14+
data-toggle="tooltip"
15+
data-placement="top"
16+
title="{{ share.type }}"
17+
target="_blank"
18+
rel="noopener"
19+
aria-label="{{ share.type }}"
20+
>
21+
<i class="fa-fw {{ share.icon }}"></i>
22+
</a>
1823
{% endfor %}
1924

20-
<i id="copy-link" class="fa-fw fas fa-link small"
21-
data-toggle="tooltip" data-placement="top"
22-
title="{{ site.data.locales[site.lang].post.button.share_link.title }}"
23-
data-title-succeed="{{ site.data.locales[site.lang].post.button.share_link.succeed }}">
25+
<i
26+
id="copy-link"
27+
class="fa-fw fas fa-link small"
28+
data-toggle="tooltip"
29+
data-placement="top"
30+
title="{{ site.data.locales[include.lang].post.button.share_link.title }}"
31+
data-title-succeed="{{ site.data.locales[include.lang].post.button.share_link.succeed }}"
32+
>
2433
</i>
25-
2634
</span>
2735
</div>

_includes/read-time.html

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
<!--
2-
Calculate the post's reading time, and display the word count in tooltip
3-
-->
1+
<!-- Calculate the post's reading time, and display the word count in tooltip -->
42

5-
{% assign words = include.content | strip_html | number_of_words: "auto" %}
3+
{% assign words = include.content | strip_html | number_of_words: 'auto' %}
64

7-
<!-- words per minute -->
5+
<!-- words per minute -->
86

97
{% assign wpm = 180 %}
108
{% assign min_time = 1 %}
@@ -16,15 +14,24 @@
1614
{% endunless %}
1715

1816
{% capture read_prompt %}
19-
{{- site.data.locales[site.lang].post.read_time.prompt -}}
17+
{{- site.data.locales[include.lang].post.read_time.prompt -}}
2018
{% endcapture %}
2119

2220
<!-- return element -->
23-
<span class="readtime" data-toggle="tooltip" data-placement="bottom"
24-
title="{{ words }} {{ site.data.locales[site.lang].post.words }}">
25-
<em>{{- read_time -}}{{" "}}{{- site.data.locales[site.lang].post.read_time.unit -}}</em>
21+
<span
22+
class="readtime"
23+
data-toggle="tooltip"
24+
data-placement="bottom"
25+
title="{{ words }} {{ site.data.locales[include.lang].post.words }}"
26+
>
27+
<em>
28+
{{- read_time -}}
29+
{{ ' ' }}
30+
{{- site.data.locales[include.lang].post.read_time.unit -}}
31+
</em>
2632
{%- if include.prompt -%}
2733
{%- assign _prompt_words = read_prompt | number_of_words: 'auto' -%}
28-
{%- unless _prompt_words > 1 -%}{{ " " }}{%- endunless -%}{{ read_prompt }}
34+
{%- unless _prompt_words > 1 -%}{{ ' ' }}{%- endunless -%}
35+
{{ read_prompt }}
2936
{%- endif -%}
3037
</span>

_includes/refactor-content.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
| append: '<div class="code-header">'
226226
| append: _label
227227
| append: '<button aria-label="copy" data-title-succeed="'
228-
| append: site.data.locales[site.lang].post.button.copy_code.succeed
228+
| append: site.data.locales[include.lang].post.button.copy_code.succeed
229229
| append: '"><i class="far fa-clipboard"></i></button></div>'
230230
| append: '<div class="highlight"><code>'
231231
%}

_includes/related-posts.html

+37-33
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<!--
2-
Recommend the other 3 posts according to the tags and categories of the current post,
3-
if the number is not enough, use the other latest posts to supplement.
2+
Recommend the other 3 posts according to the tags and categories of the current post,
3+
if the number is not enough, use the other latest posts to supplement.
44
-->
55

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

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

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

15-
{% assign SEPARATOR = ":" %}
15+
{% assign SEPARATOR = ':' %}
1616

17-
{% assign score_list = "" | split: "" %}
17+
{% assign score_list = '' | split: '' %}
1818
{% assign last_index = site.posts.size | minus: 1 %}
1919

2020
{% for i in (0..last_index) %}
@@ -42,11 +42,9 @@
4242
{% capture score_item %}{{ score }}{{ SEPARATOR }}{{ i }}{% endcapture %}
4343
{% assign score_list = score_list | push: score_item %}
4444
{% endif %}
45-
4645
{% endfor %}
4746

48-
49-
{% assign index_list = "" | split: "" %}
47+
{% assign index_list = '' | split: '' %}
5048

5149
{% if score_list.size > 0 %}
5250
{% assign score_list = score_list | sort | reverse %}
@@ -56,13 +54,13 @@
5654
{% endfor %}
5755
{% endif %}
5856

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

6260
{% if less > 0 %}
6361
{% for i in (0..last_index) %}
6462
{% assign post = site.posts[i] %}
65-
{% if post.url != page.url %}
63+
{% if post.url != page.url %}
6664
{% capture cur_index %}{{ i }}{% endcapture %}
6765
{% unless index_list contains cur_index %}
6866
{% assign index_list = index_list | push: cur_index %}
@@ -77,27 +75,33 @@
7775

7876
{% if index_list.size > 0 %}
7977
<div id="related-posts" class="mb-2 mb-sm-4">
80-
<h3 class="pt-2 mb-4 ml-1"
81-
data-toc-skip>{{ site.data.locales[site.lang].post.relate_posts }}</h3>
78+
<h3
79+
class="pt-2 mb-4 ml-1"
80+
data-toc-skip
81+
>
82+
{{ site.data.locales[include.lang].post.relate_posts }}
83+
</h3>
8284
<div class="card-deck mb-4">
83-
{% for entry in index_list %}
84-
{% assign index = entry | plus: 0 %}
85-
{% assign post = site.posts[index] %}
86-
<div class="card">
87-
<a href="{{ post.url | relative_url }}">
88-
<div class="card-body">
89-
{% include datetime.html date=post.date class="small" %}
90-
<h3 class="pt-0 mt-1 mb-3" data-toc-skip>{{ post.title }}</h3>
91-
<div class="text-muted small">
92-
<p>
93-
{% include no-linenos.html content=post.content %}
94-
{{ content | markdownify | strip_html | truncate: 200 | escape }}
95-
</p>
85+
{% for entry in index_list %}
86+
{% assign index = entry | plus: 0 %}
87+
{% assign post = site.posts[index] %}
88+
<div class="card">
89+
<a href="{{ post.url | relative_url }}">
90+
<div class="card-body">
91+
{% include datetime.html date=post.date class="small" lang=include.lang %}
92+
<h3 class="pt-0 mt-1 mb-3" data-toc-skip>{{ post.title }}</h3>
93+
<div class="text-muted small">
94+
<p>
95+
{% include no-linenos.html content=post.content %}
96+
{{ content | markdownify | strip_html | truncate: 200 | escape }}
97+
</p>
98+
</div>
9699
</div>
97-
</div>
98-
</a>
99-
</div>
100-
{% endfor %}
101-
</div> <!-- .card-deck -->
102-
</div> <!-- #related-posts -->
100+
</a>
101+
</div>
102+
{% endfor %}
103+
</div>
104+
<!-- .card-deck -->
105+
</div>
106+
<!-- #related-posts -->
103107
{% endif %}

_includes/search-loader.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</div>
1515
{% endcapture %}
1616

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

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

0 commit comments

Comments
 (0)