Skip to content

Commit 9aefa21

Browse files
committed
feat: add internationalization support for comments and update language handling
1 parent 258e74f commit 9aefa21

File tree

8 files changed

+41
-23
lines changed

8 files changed

+41
-23
lines changed

_config.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,7 @@ clarity: false
283283
# -> valine -> waline -> twikoo -> gitalk -> giscus
284284
comment:
285285
# comment system title
286-
title: 说些什么吧!
287-
# or with i18n
288-
# title:
289-
# en: Say something!
290-
# zh-CN: 说些什么吧!
286+
# title: 说些什么吧!# deprecated, use i18n instead
291287
default: waline # default comment system, when you enable multiple comment systems
292288

293289
# valine comment system. https://valine.js.org
@@ -299,7 +295,7 @@ valine:
299295
appKey: # leancloud application app key
300296
pageSize: 10 # comment list page size
301297
avatar: mp # gravatar style https://valine.js.org/#/avatar
302-
lang: zh-cn # i18n: zh-cn/en
298+
# lang: zh-cn # deprecated, use html.lang instead
303299
placeholder: Just go go # valine comment input placeholder(like: Please leave your footprints )
304300
guest_info: nick,mail,link #valine comment header info
305301
recordIP: true # whether to record the IP address of the commenters
@@ -312,7 +308,7 @@ valine:
312308
waline:
313309
enable: false
314310
serverURL:
315-
lang: zh-CN
311+
# lang: zh-CN # deprecated, use html.lang instead
316312
locale: {} # https://waline.js.org/guide/features/i18n.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E8%AF%AD%E8%A8%80
317313
emoji:
318314
- https://unpkg.com/@waline/[email protected]/weibo
@@ -360,8 +356,8 @@ giscus:
360356
reactionsEnabled: 1
361357
emitMetadata: 0
362358
inputPosition: bottom
363-
# commentTheme: light # this option is invalid, because the theme is set by the theme itself
364-
lang: zh-CN
359+
# commentTheme: light # deprecated, because the theme is set by the theme itself
360+
# lang: zh-CN # deprecated, use html.lang instead
365361

366362
########################################
367363
# Search

languages/en.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,10 @@ article_copyright:
6868
date: "Published: "
6969
updated: "Updated: "
7070
license: "License: "
71-
license_content: "All articles on this blog are licensed under the %s license agreement unless otherwise stated. Please indicate the source when reprinting!"
71+
license_content: "All articles on this blog are licensed under the %s license agreement unless otherwise stated. Please indicate the source when reprinting!"
72+
73+
comments:
74+
title: "Say something!"
75+
76+
outdate:
77+
message: This article was last updated on {time}. Please note that the content may no longer be applicable.

languages/ja.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,9 @@ article_copyright:
6969
updated: "更新日: "
7070
license: "ライセンス: "
7171
license_content: 本ブログのすべての文書は、特に指定されていない限り、%s ライセンスに従っています。引用の際は出典を明記してください!
72+
73+
comments:
74+
title: "何か言ってみて!"
75+
76+
outdate:
77+
message: この記事は最終更新日:{time}。記載内容が現在有効でない可能性がありますのでご注意ください。

languages/zh-CN.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,10 @@ article_copyright:
6868
date: 本文发布时间:
6969
updated: 本文更新时间:
7070
license: 本文版权:
71-
license_content: 本博客所有文章除特别声明外,均采用 %s 许可协议。转载请注明出处!
71+
license_content: 本博客所有文章除特别声明外,均采用 %s 许可协议。转载请注明出处!
72+
73+
comments:
74+
title: 说些什么吧!
75+
76+
outdate:
77+
message: 本文最后更新于 {time},请注意文中内容可能已不适用。

languages/zh-TW.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,10 @@ article_copyright:
6868
date: 本文發佈時間:
6969
updated: 本文更新時間:
7070
license: 本文版權:
71-
license_content: 本部落格所有文章除特別聲明外,均採用 %s 授權協議。轉載請註明出處!
71+
license_content: 本部落格所有文章除特別聲明外,均採用 %s 授權協議。轉載請註明出處!
72+
73+
comments:
74+
title: 說些什麼吧!
75+
76+
outdate:
77+
message: 本文最後更新於 {time},請注意文中內容可能已不適用。

layout/_partial/article.ejs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,7 @@
9898
<% if (post.comments !== false && activeSystems.length) { %>
9999
<section id="comments" data-aos="<%= theme.animation.options.article.whole %>">
100100
<div class="comment-header">
101-
<% var commentTitle = theme.comment.title; %>
102-
<% if (typeof commentTitle !== 'string') { %>
103-
<% commentTitle = commentTitle[post.lang]; %>
104-
<% } %>
105-
<h2 class="comment-title"><%= commentTitle %></h2>
101+
<h2 class="comment-title"><%= __("comments.title") %></h2>
106102
<div class="comment-selector">
107103
<div class="comment-selector-wrap">
108104
<% for(const active of activeSystems) { %>

layout/_partial/post/comment.ejs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
placeholder: "<%= theme.valine.placeholder %>",
4848
pageSize: '<%= theme.valine.pageSize %>',
4949
avatar: '<%= theme.valine.avatar %>',
50-
lang: '<%= theme.valine.lang %>',
50+
lang: document.documentElement.lang || 'en',
5151
recordIP: recordIP,
5252
highlight: highlight,
5353
visitor: visitor,
@@ -77,7 +77,7 @@
7777
window.walineInstance = walineInit({
7878
el: '.waline-comment',
7979
serverURL: '<%= theme.waline.serverURL %>',
80-
lang: '<%= theme.waline.lang %>',
80+
lang: document.documentElement.lang || 'en',
8181
locale: <%- JSON.stringify(theme.waline.locale) %>,
8282
emoji: <%- JSON.stringify(theme.waline.emoji) %>,
8383
meta: <%- JSON.stringify(theme.waline.meta) %>,
@@ -108,6 +108,7 @@
108108
envId: '<%= theme.twikoo.envId %>',
109109
el: '.tcomment',
110110
region: '<%= theme.twikoo.region %>',
111+
lang: document.documentElement.lang || 'en',
111112
})
112113
}
113114
}
@@ -148,8 +149,9 @@
148149
repo: '<%= theme.gitalk.repo %>',
149150
owner: '<%= theme.gitalk.owner %>',
150151
admin: <%- JSON.stringify(theme.gitalk.admin) %>,
151-
id: gitalkId, // Ensure uniqueness and length less than 50
152-
distractionFreeMode: false // Facebook-like distraction free mode
152+
id: gitalkId,
153+
distractionFreeMode: false,
154+
language: document.documentElement.lang || 'en',
153155
})
154156
gitalk.render('gitalk-comment');
155157
}
@@ -181,7 +183,7 @@
181183
giscusScript.setAttribute('data-emit-metadata', '<%= theme.giscus.emitMetadata %>');
182184
giscusScript.setAttribute('data-input-position', '<%= theme.giscus.inputPosition %>');
183185
giscusScript.setAttribute('data-theme', domMode === 'dark' ? 'dark' : 'light');
184-
giscusScript.setAttribute('data-lang', '<%= theme.giscus.lang %>');
186+
giscusScript.setAttribute('data-lang', document.documentElement.lang || 'en');
185187
giscusScript.setAttribute('crossorigin', 'anonymous');
186188
giscusScript.async = true;
187189
container.appendChild(giscusScript);

layout/layout.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<%- partial('404', {post: page}) %>
33
<% } else { %>
44
<!DOCTYPE html>
5-
<html <% if (config.language) { %>lang="<%- config.language %>" <% } %>
5+
<html <% if (page.lang) { %>lang="<%- page.lang %>" <% } else if (config.language) { %>lang="<%- config.language %>" <% } %>
66
<% if (theme.dark_mode.enable === true) { %>
77
data-theme-mode="true"
88
<% } else if (theme.dark_mode.enable === 'auto') { %>

0 commit comments

Comments
 (0)