diff --git a/build.gradle b/build.gradle
index 2f2a1e0..c820687 100644
--- a/build.gradle
+++ b/build.gradle
@@ -41,6 +41,6 @@ build {
}
halo {
- version = "2.18.0"
+ version = "2.20"
debug = true
}
diff --git a/packages/comment-widget/lit-localize.json b/packages/comment-widget/lit-localize.json
new file mode 100644
index 0000000..6d04a27
--- /dev/null
+++ b/packages/comment-widget/lit-localize.json
@@ -0,0 +1,19 @@
+{
+ "$schema": "https://raw.githubusercontent.com/lit/lit/main/packages/localize-tools/config.schema.json",
+ "sourceLocale": "en",
+ "targetLocales": [
+ "es",
+ "zh-CN",
+ "zh-TW"
+ ],
+ "tsConfig": "./tsconfig.json",
+ "output": {
+ "mode": "runtime",
+ "outputDir": "./src/generated/locales",
+ "localeCodesModule": "./src/generated/locale-codes.ts"
+ },
+ "interchange": {
+ "format": "xliff",
+ "xliffDir": "./xliff/"
+ }
+}
\ No newline at end of file
diff --git a/packages/comment-widget/package.json b/packages/comment-widget/package.json
index 3d40b22..bcd10e7 100644
--- a/packages/comment-widget/package.json
+++ b/packages/comment-widget/package.json
@@ -36,6 +36,7 @@
"@emoji-mart/data": "^1.1.2",
"@halo-dev/api-client": "^2.14.0",
"@lit/context": "^1.1.0",
+ "@lit/localize": "^0.12.2",
"dayjs": "^1.11.10",
"emoji-mart": "^5.5.2",
"javascript-time-ago": "^2.5.9",
@@ -43,6 +44,7 @@
"lodash-es": "^4.17.21"
},
"devDependencies": {
+ "@lit/localize-tools": "^0.8.0",
"@types/lodash-es": "^4.17.12",
"lit-analyzer": "^2.0.3"
}
diff --git a/packages/comment-widget/src/base-comment-item.ts b/packages/comment-widget/src/base-comment-item.ts
index 0a01e09..f902a31 100644
--- a/packages/comment-widget/src/base-comment-item.ts
+++ b/packages/comment-widget/src/base-comment-item.ts
@@ -4,6 +4,7 @@ import { property } from 'lit/decorators.js';
import { formatDate, timeAgo } from './utils/date';
import baseStyles from './styles/base';
import varStyles from './styles/var';
+import { msg } from '@lit/localize';
export class BaseCommentItem extends LitElement {
@property({ type: String })
@@ -45,7 +46,7 @@ export class BaseCommentItem extends LitElement {
${timeAgo(this.creationTime)}
- ${!this.approved ? html`审核中
` : ''}
+ ${!this.approved ? html`${msg('Reviewing')}
` : ''}
diff --git a/packages/comment-widget/src/base-form.ts b/packages/comment-widget/src/base-form.ts
index 460b92a..df8b75b 100644
--- a/packages/comment-widget/src/base-form.ts
+++ b/packages/comment-widget/src/base-form.ts
@@ -19,6 +19,7 @@ import './icons/icon-loading';
import { ToastManager } from './lit-toast';
import baseStyles from './styles/base';
import varStyles from './styles/var';
+import { msg } from '@lit/localize';
export class BaseForm extends LitElement {
@consume({ context: baseUrlContext })
@@ -99,7 +100,7 @@ export class BaseForm extends LitElement {
const response = await fetch(`/apis/api.commentwidget.halo.run/v1alpha1/captcha/-/generate`);
if (!response.ok) {
- this.toastManager?.error('获取验证码失败');
+ this.toastManager?.error(msg('Failed to obtain verification code'));
return;
}
@@ -111,7 +112,13 @@ export class BaseForm extends LitElement {
}
async handleLogout() {
- if (window.confirm('点击确定将跳转至退出登录页面,请确保正在编辑的内容已保存。')) {
+ if (
+ window.confirm(
+ msg(
+ 'Click OK to jump to the logout page, Please make sure the content being edited has been saved.'
+ )
+ )
+ ) {
try {
window.location.href = '/logout';
} catch (error) {
@@ -125,7 +132,7 @@ export class BaseForm extends LitElement {
${this.currentUser?.spec.avatar ? html`
` : ''}
${this.currentUser?.spec.displayName || this.currentUser?.metadata.name}
`;
}
@@ -169,7 +176,7 @@ export class BaseForm extends LitElement {
- (或登录账号)
+ ${msg('(Or login)')}
`
: ''}
@@ -210,14 +217,18 @@ export class BaseForm extends LitElement {
class="form__button--login"
type="button"
>
- 登录
+ ${msg('Login')}
`
: ''}
diff --git a/packages/comment-widget/src/comment-form.ts b/packages/comment-widget/src/comment-form.ts
index 197b1fd..1274e9b 100644
--- a/packages/comment-widget/src/comment-form.ts
+++ b/packages/comment-widget/src/comment-form.ts
@@ -17,6 +17,7 @@ import {
} from './context';
import { ToastManager } from './lit-toast';
import { getCaptchaCodeHeader, isRequireCaptcha } from './utils/captcha';
+import { msg } from '@lit/localize';
export class CommentForm extends LitElement {
@consume({ context: baseUrlContext })
@@ -91,14 +92,14 @@ export class CommentForm extends LitElement {
};
if (!this.currentUser && !this.allowAnonymousComments) {
- this.toastManager?.warn('请先登录');
+ this.toastManager?.warn(msg('Please login first'));
this.submitting = false;
return;
}
if (!this.currentUser && this.allowAnonymousComments) {
if (!displayName || !email) {
- this.toastManager?.warn('请先登录或者完善信息');
+ this.toastManager?.warn(msg('Please log in or complete the information first'));
this.submitting = false;
return;
} else {
@@ -130,15 +131,15 @@ export class CommentForm extends LitElement {
this.baseFormRef.value?.handleFetchCaptcha();
if (!response.ok) {
- throw new Error('评论失败,请稍后重试');
+ throw new Error(msg('Comment failed, please try again later'));
}
const newComment = (await response.json()) as Comment;
if (newComment.spec.approved) {
- this.toastManager?.success('评论成功');
+ this.toastManager?.success(msg('Comment submitted successfully'));
} else {
- this.toastManager?.success('评论成功,等待审核');
+ this.toastManager?.success(msg('Comment submitted successfully, pending review'));
}
this.dispatchEvent(new CustomEvent('reload'));
diff --git a/packages/comment-widget/src/comment-item.ts b/packages/comment-widget/src/comment-item.ts
index 25edca7..672153b 100644
--- a/packages/comment-widget/src/comment-item.ts
+++ b/packages/comment-widget/src/comment-item.ts
@@ -13,6 +13,7 @@ import varStyles from './styles/var';
import { Ref, createRef, ref } from 'lit/directives/ref.js';
import { CommentReplies } from './comment-replies';
import { getPolicyInstance } from './avatar/avatar-policy';
+import { msg } from '@lit/localize';
export class CommentItem extends LitElement {
@consume({ context: baseUrlContext })
@@ -178,7 +179,7 @@ export class CommentItem extends LitElement {
${this.withReplies
? html` (this.showReplyForm = !this.showReplyForm)}"
>
- 上一页
+ ${msg('Previous')}
${this.renderPageNumbers()}
@@ -116,7 +117,7 @@ export class CommentPagination extends LitElement {
@click=${() => this.gotoPage(this.page + 1)}
?disabled=${this.page === this.totalPages}
>
- 下一页
+ ${msg('Next')}