diff --git a/docs/widget/src/components/CommentList.js b/docs/widget/src/components/CommentList.js index 88d43fb..912ec62 100644 --- a/docs/widget/src/components/CommentList.js +++ b/docs/widget/src/components/CommentList.js @@ -35,6 +35,7 @@ export class CommentList extends Component { */ constructor(container, props = {}) { super(container, props); + this.t = props.t || ((k) => k); this.loadingComponent = null; this.paginationComponent = null; this.commentItems = new Map(); // 缓存 CommentItem 实例,key 为 comment.id @@ -120,7 +121,7 @@ export class CommentList extends Component { const emptyEl = this.createElement('div', { className: 'cwd-empty', children: [ - this.createTextElement('p', '暂无评论,快来抢沙发吧!', 'cwd-empty-text') + this.createTextElement('p', this.t('noComments'), 'cwd-empty-text') ] }); root.appendChild(emptyEl); diff --git a/docs/widget/src/core/CWDComments.js b/docs/widget/src/core/CWDComments.js index 539a672..e7332bf 100644 --- a/docs/widget/src/core/CWDComments.js +++ b/docs/widget/src/core/CWDComments.js @@ -169,7 +169,7 @@ export class CWDComments { }); // 设置语言 - let lang = serverConfig.widgetLanguage || 'auto'; + let lang = this.config.lang || serverConfig.widgetLanguage || 'auto'; if (lang === 'auto' && typeof navigator !== 'undefined') { const browserLang = navigator.language || navigator.userLanguage; if (browserLang.toLowerCase().startsWith('en')) { @@ -194,7 +194,7 @@ export class CWDComments { } } else { // 即使没有域名限制,也需要设置语言 - let lang = serverConfig.widgetLanguage || 'auto'; + let lang = this.config.lang || serverConfig.widgetLanguage || 'auto'; if (lang === 'auto' && typeof navigator !== 'undefined') { const browserLang = navigator.language || navigator.userLanguage; if (browserLang.toLowerCase().startsWith('en')) { diff --git a/docs/widget/src/dev.js b/docs/widget/src/dev.js index 8b4844b..427ed26 100644 --- a/docs/widget/src/dev.js +++ b/docs/widget/src/dev.js @@ -51,12 +51,14 @@ function populateInputs(config) { const avatarPrefixInput = document.getElementById('avatarPrefix'); const siteIdInput = document.getElementById('siteId'); const postSlugInput = document.getElementById('postSlug'); + const langSelect = document.getElementById('lang'); if (apiBaseUrlInput) apiBaseUrlInput.value = config.apiBaseUrl || DEFAULT_CONFIG.apiBaseUrl; if (themeSelect) themeSelect.value = config.theme || DEFAULT_CONFIG.theme; if (avatarPrefixInput) avatarPrefixInput.value = config.avatarPrefix || DEFAULT_CONFIG.avatarPrefix; if (siteIdInput) siteIdInput.value = config.siteId || DEFAULT_CONFIG.siteId || ''; if (postSlugInput) postSlugInput.value = config.postSlug || DEFAULT_CONFIG.postSlug || ''; + if (langSelect) langSelect.value = config.lang || DEFAULT_CONFIG.lang; } /** @@ -67,7 +69,8 @@ function getConfigFromInputs() { const theme = document.getElementById('theme')?.value || DEFAULT_CONFIG.theme; const siteId = document.getElementById('siteId')?.value || DEFAULT_CONFIG.siteId || ''; const postSlug = document.getElementById('postSlug')?.value || DEFAULT_CONFIG.postSlug || ''; - return { apiBaseUrl, theme, siteId, postSlug }; + const lang = document.getElementById('lang')?.value || DEFAULT_CONFIG.lang; + return { apiBaseUrl, theme, siteId, postSlug, lang }; } /** @@ -98,6 +101,7 @@ async function initWidget() { apiBaseUrl: config.apiBaseUrl, siteId: config.siteId, postSlug: config.postSlug, + lang: config.lang, }); widgetInstance.mount(); } catch (error) {} diff --git a/docs/widget/src/locales/index.js b/docs/widget/src/locales/index.js index 78b4b14..d0cca5d 100644 --- a/docs/widget/src/locales/index.js +++ b/docs/widget/src/locales/index.js @@ -64,7 +64,7 @@ export const locales = { verifyAdmin: '退出验证', formTitle: '发表评论', loadMore: '加载更多', - noComments: '暂无评论', + noComments: '暂无评论,快来抢沙发吧!', delete: '删除', confirmDelete: '确定删除这条评论吗?', deleteSuccess: '删除成功',