fix(embed): add missing conversationTime and referencesDrawer i18n keys for all locales

main
AndyYang 2026-09-09 20:10:49 +08:00 committed by lyingbug
parent 5cf093706e
commit e0ee15807c
3 changed files with 265 additions and 8 deletions

View File

@ -106,6 +106,12 @@ const messages = {
"unableToGetKnowledgeBaseId": "无法获取知识库ID",
"summaryInProgress": "正在总结答案……",
"thinkingAlt": "正在思考",
"conversationTime": {
"today": "今天 {time}",
"yesterday": "昨天 {time}",
"thisYear": "{month}月{day}日 {time}",
"otherYear": "{year}年{month}月{day}日 {time}"
},
"preparingAnswer": "正在准备回答…",
"connectingModelAndGeneratingAnswer": "正在连接模型并生成回答…",
"modelStillResponding": "模型响应较慢,仍在等待…",
@ -115,6 +121,15 @@ const messages = {
"referencesDocCount": "引用了{count}篇文档",
"referencesWebCount": "参考了{count}条网页",
"referencesDocAndWebCount": "引用了{docCount}篇文档和{webCount}条网页",
"referencesDrawerTitle": "参考来源",
"referencesDrawerTitleWeb": "网页来源",
"referencesDrawerTitleDocs": "文档来源",
"referencesDrawerTitleTools": "工具结果",
"referencesDrawerTitleMixed": "参考来源",
"referencesDrawerWebSection": "网页",
"referencesDrawerDocsSection": "知识库文档",
"referencesDrawerToolsSection": "工具",
"referencesDrawerEmpty": "暂无参考来源",
"referenceChunkCount": "{count}个片段",
"fallbackHint": "未从知识库中检索到相关内容,以上为模型直接回答",
"requestInfoTitle": "请求信息",
@ -246,6 +261,7 @@ const messages = {
"loading": "加载中...",
"confirm": "确认",
"cancel": "取消",
"close": "关闭",
"copy": "复制",
"copied": "已复制",
"finish": "完成"
@ -671,6 +687,12 @@ const messages = {
"unableToGetKnowledgeBaseId": "ナレッジベースIDを取得できません",
"summaryInProgress": "回答を要約しています…",
"thinkingAlt": "思考中",
"conversationTime": {
"today": "今日{time}",
"yesterday": "昨日{time}",
"thisYear": "{month}/{day} {time}",
"otherYear": "{year}/{month}/{day} {time}"
},
"preparingAnswer": "回答を準備しています…",
"connectingModelAndGeneratingAnswer": "モデルに接続して回答を生成しています…",
"modelStillResponding": "モデルの応答に時間がかかっています。引き続きお待ちください…",
@ -680,6 +702,15 @@ const messages = {
"referencesDocCount": "{count}件のドキュメントを引用しました",
"referencesWebCount": "{count}件のWebページを参照しました",
"referencesDocAndWebCount": "{docCount}件のドキュメントと{webCount}件のWebページを引用しました",
"referencesDrawerTitle": "出典",
"referencesDrawerTitleWeb": "Webの出典",
"referencesDrawerTitleDocs": "ドキュメントの出典",
"referencesDrawerTitleTools": "ツールの実行結果",
"referencesDrawerTitleMixed": "出典",
"referencesDrawerWebSection": "Web",
"referencesDrawerDocsSection": "ドキュメント",
"referencesDrawerToolsSection": "ツール",
"referencesDrawerEmpty": "出典はありません",
"referenceChunkCount": "{count}件のチャンク",
"fallbackHint": "ナレッジベースに関連する内容が見つかりませんでした。以上はモデルによる直接の回答です。",
"requestInfoTitle": "リクエスト情報",
@ -812,6 +843,7 @@ const messages = {
"loading": "読み込み中...",
"confirm": "確認",
"cancel": "キャンセル",
"close": "閉じる",
"copy": "コピー",
"copied": "コピーしました",
"finish": "完了"
@ -1237,6 +1269,12 @@ const messages = {
"unableToGetKnowledgeBaseId": "Unable to get knowledge base ID",
"summaryInProgress": "Summarizing answer…",
"thinkingAlt": "Thinking in progress",
"conversationTime": {
"today": "Today {time}",
"yesterday": "Yesterday {time}",
"thisYear": "{month}/{day} {time}",
"otherYear": "{month}/{day}/{year} {time}"
},
"preparingAnswer": "Preparing an answer…",
"connectingModelAndGeneratingAnswer": "Connecting to the model and generating an answer…",
"modelStillResponding": "The model is taking longer than usual, still waiting…",
@ -1246,6 +1284,15 @@ const messages = {
"referencesDocCount": "Referenced {count} document(s)",
"referencesWebCount": "Referenced {count} web result(s)",
"referencesDocAndWebCount": "Referenced {docCount} document(s) and {webCount} web page(s)",
"referencesDrawerTitle": "Sources",
"referencesDrawerTitleWeb": "Web sources",
"referencesDrawerTitleDocs": "Document sources",
"referencesDrawerTitleTools": "Tool results",
"referencesDrawerTitleMixed": "Sources",
"referencesDrawerWebSection": "Web",
"referencesDrawerDocsSection": "Documents",
"referencesDrawerToolsSection": "Tools",
"referencesDrawerEmpty": "No sources available",
"referenceChunkCount": "{count} chunk(s)",
"fallbackHint": "No relevant content found in knowledge base. Above is a direct response from the model.",
"requestInfoTitle": "Request info",
@ -1378,6 +1425,7 @@ const messages = {
"loading": "Loading...",
"confirm": "Confirm",
"cancel": "Cancel",
"close": "Close",
"copy": "Copy",
"copied": "Copied",
"finish": "Finish"
@ -1750,6 +1798,7 @@ const koEmbedPublish = {
loading: '로딩 중...',
confirm: '확인',
cancel: '취소',
close: '닫기',
copy: '복사',
copied: '복사됨',
},
@ -1764,9 +1813,29 @@ const koEmbedPublish = {
followUpQuestions: '이어서 질문',
followUpQuestionsLoading: '추천 질문 로딩 중',
thinkingAlt: '생각 중',
conversationTime: {
today: '오늘 {time}',
yesterday: '어제 {time}',
thisYear: '{month}월 {day}일 {time}',
otherYear: '{year}년 {month}월 {day}일 {time}',
},
preparingAnswer: '답변을 준비하고 있습니다…',
connectingModelAndGeneratingAnswer: '모델에 연결하여 답변을 생성하고 있습니다…',
modelStillResponding: '모델 응답이 평소보다 오래 걸리고 있습니다. 계속 기다리는 중…',
referencesTitle: '{count}개의 관련 내용 참조',
referencesDocCount: '{count}개 문서 참조',
referencesWebCount: '{count}개 웹 결과 참조',
referencesDocAndWebCount: '{docCount}개 문서와 {webCount}개 웹페이지 참조',
referencesDrawerTitle: '참고 출처',
referencesDrawerTitleWeb: '웹 출처',
referencesDrawerTitleDocs: '문서 출처',
referencesDrawerTitleTools: '도구 결과',
referencesDrawerTitleMixed: '참고 출처',
referencesDrawerWebSection: '웹',
referencesDrawerDocsSection: '지식베이스 문서',
referencesDrawerToolsSection: '도구',
referencesDrawerEmpty: '참고 출처가 없습니다',
navigateToDocument: '문서 상세 보기',
refreshSuggestedQuestions: '다른 질문',
imageTooMany: '이미지는 최대 5장까지 업로드할 수 있습니다',
imageTypeSizeError: 'JPG/PNG/GIF/WEBP만 지원하며, 각 파일은 10MB 이하여야 합니다',
@ -1868,6 +1937,7 @@ const ruEmbedPublish = {
loading: 'Загрузка...',
confirm: 'Подтвердить',
cancel: 'Отмена',
close: 'Закрыть',
copy: 'Копировать',
copied: 'Скопировано',
},
@ -1882,9 +1952,29 @@ const ruEmbedPublish = {
followUpQuestions: 'Спрашивайте дальше',
followUpQuestionsLoading: 'Загрузка рекомендуемых вопросов',
thinkingAlt: 'Обдумывание...',
conversationTime: {
today: 'Сегодня {time}',
yesterday: 'Вчера {time}',
thisYear: '{day}.{month} {time}',
otherYear: '{day}.{month}.{year} {time}',
},
preparingAnswer: 'Подготовка ответа…',
connectingModelAndGeneratingAnswer: 'Подключение к модели и создание ответа…',
modelStillResponding: 'Модель отвечает дольше обычного, продолжаем ждать…',
referencesTitle: 'Использовано {count} связанного материала',
referencesDocCount: 'Использовано {count} документ(ов)',
referencesWebCount: 'Использовано {count} веб-результат(ов)',
referencesDocAndWebCount: 'Использовано {docCount} документ(ов) и {webCount} веб-страниц(ы)',
referencesDrawerTitle: 'Источники',
referencesDrawerTitleWeb: 'Веб-источники',
referencesDrawerTitleDocs: 'Документы',
referencesDrawerTitleTools: 'Результаты инструментов',
referencesDrawerTitleMixed: 'Источники',
referencesDrawerWebSection: 'Веб',
referencesDrawerDocsSection: 'Документы базы знаний',
referencesDrawerToolsSection: 'Инструменты',
referencesDrawerEmpty: 'Источники отсутствуют',
navigateToDocument: 'Подробнее о документе',
refreshSuggestedQuestions: 'Ещё',
imageTooMany: 'Можно загрузить не более 5 изображений',
imageTypeSizeError: 'Поддерживаются только JPG/PNG/GIF/WEBP, каждый файл до 10 МБ',
@ -1960,7 +2050,7 @@ const ruEmbedPublish = {
},
} as const
const SUPPORTED_LOCALES = ['zh-CN', 'en-US', 'ko-KR', 'ja-JP', 'ru-RU'] as const
export const SUPPORTED_LOCALES = ['zh-CN', 'en-US', 'ko-KR', 'ja-JP', 'ru-RU'] as const
export type EmbedLocale = (typeof SUPPORTED_LOCALES)[number]
/** Isolated from the main app `locale` key so embed preview never hijacks admin UI language. */
@ -2006,19 +2096,21 @@ function resolveInitialEmbedLocale(): EmbedLocale {
const locale = resolveInitialEmbedLocale()
export const EMBED_MESSAGES = {
'zh-CN': messages['zh-CN'],
'en-US': messages['en-US'],
'ko-KR': deepMerge(messages['en-US'], koEmbedPublish),
'ja-JP': messages['ja-JP'],
'ru-RU': deepMerge(messages['en-US'], ruEmbedPublish),
} as const
const i18n = createI18n({
legacy: false,
locale,
fallbackLocale: 'en-US',
globalInjection: true,
warnHtmlMessage: false,
messages: {
'zh-CN': messages['zh-CN'],
'en-US': messages['en-US'],
'ko-KR': deepMerge(messages['en-US'], koEmbedPublish),
'ja-JP': messages['ja-JP'],
'ru-RU': deepMerge(messages['en-US'], ruEmbedPublish),
},
messages: EMBED_MESSAGES,
})
type LocaleRef = { value: string }

View File

@ -0,0 +1,163 @@
import assert from 'node:assert/strict'
import { test } from 'node:test'
import {
EMBED_MESSAGES,
normalizeEmbedLocale,
SUPPORTED_LOCALES,
} from './embed.ts'
const EXPECTED_CONVERSATION_TIME_KEYS = [
'today',
'yesterday',
'thisYear',
'otherYear',
] as const
const EXPECTED_REFERENCES_DRAWER_KEYS = [
'referencesDrawerTitle',
'referencesDrawerTitleWeb',
'referencesDrawerTitleDocs',
'referencesDrawerTitleTools',
'referencesDrawerTitleMixed',
'referencesDrawerWebSection',
'referencesDrawerDocsSection',
'referencesDrawerToolsSection',
'referencesDrawerEmpty',
] as const
test('supported embed locales include zh-CN, en-US, ko-KR, ja-JP, ru-RU', () => {
assert.deepEqual([...SUPPORTED_LOCALES].sort(), ['en-US', 'ja-JP', 'ko-KR', 'ru-RU', 'zh-CN'].sort())
})
test('every supported locale defines conversationTime and referencesDrawer in chat', () => {
for (const locale of SUPPORTED_LOCALES) {
const bundle = EMBED_MESSAGES[locale] as {
chat?: Record<string, unknown>
common?: Record<string, unknown>
}
assert.ok(bundle, `Locale bundle for ${locale} must exist`)
assert.ok(bundle.chat, `Locale bundle for ${locale} must have chat section`)
// conversationTime checks
const conversationTime = bundle.chat.conversationTime as Record<string, string> | undefined
assert.ok(
conversationTime && typeof conversationTime === 'object',
`Locale ${locale} is missing chat.conversationTime`,
)
for (const key of EXPECTED_CONVERSATION_TIME_KEYS) {
assert.equal(
typeof conversationTime[key],
'string',
`Locale ${locale} is missing chat.conversationTime.${key}`,
)
assert.ok(
conversationTime[key].trim().length > 0,
`chat.conversationTime.${key} in ${locale} should not be empty`,
)
assert.ok(
conversationTime[key].includes('{time}'),
`chat.conversationTime.${key} in ${locale} must include {time} placeholder`,
)
}
// referencesDrawer checks
const chatBag = bundle.chat as Record<string, unknown>
for (const key of EXPECTED_REFERENCES_DRAWER_KEYS) {
const val: unknown = chatBag[key]
assert.equal(
typeof val,
'string',
`Locale ${locale} is missing chat.${key}`,
)
assert.ok(
(val as string).trim().length > 0,
`chat.${key} in ${locale} should not be empty`,
)
}
// common.close check
assert.ok(bundle.common, `Locale bundle for ${locale} must have common section`)
assert.equal(
typeof bundle.common.close,
'string',
`Locale ${locale} is missing common.close`,
)
assert.ok(
(bundle.common.close as string).trim().length > 0,
`common.close in ${locale} should not be empty`,
)
}
})
test('locale-specific translations match expected strings for missing keys', () => {
// zh-CN
const zhChat = EMBED_MESSAGES['zh-CN'].chat as Record<string, any>
const zhCommon = EMBED_MESSAGES['zh-CN'].common as Record<string, any>
assert.equal(zhChat.conversationTime.today, '今天 {time}')
assert.equal(zhChat.conversationTime.yesterday, '昨天 {time}')
assert.equal(zhChat.conversationTime.thisYear, '{month}月{day}日 {time}')
assert.equal(zhChat.conversationTime.otherYear, '{year}年{month}月{day}日 {time}')
assert.equal(zhChat.referencesDrawerTitleDocs, '文档来源')
assert.equal(zhChat.referencesDrawerEmpty, '暂无参考来源')
assert.equal(zhCommon.close, '关闭')
// en-US
const enChat = EMBED_MESSAGES['en-US'].chat as Record<string, any>
const enCommon = EMBED_MESSAGES['en-US'].common as Record<string, any>
assert.equal(enChat.conversationTime.today, 'Today {time}')
assert.equal(enChat.conversationTime.yesterday, 'Yesterday {time}')
assert.equal(enChat.conversationTime.thisYear, '{month}/{day} {time}')
assert.equal(enChat.conversationTime.otherYear, '{month}/{day}/{year} {time}')
assert.equal(enChat.referencesDrawerTitleDocs, 'Document sources')
assert.equal(enChat.referencesDrawerEmpty, 'No sources available')
assert.equal(enCommon.close, 'Close')
// ja-JP
const jaChat = EMBED_MESSAGES['ja-JP'].chat as Record<string, any>
const jaCommon = EMBED_MESSAGES['ja-JP'].common as Record<string, any>
assert.equal(jaChat.conversationTime.today, '今日{time}')
assert.equal(jaChat.conversationTime.yesterday, '昨日{time}')
assert.equal(jaChat.referencesDrawerTitleDocs, 'ドキュメントの出典')
assert.equal(jaChat.referencesDrawerEmpty, '出典はありません')
assert.equal(jaCommon.close, '閉じる')
// ko-KR
const koChat = EMBED_MESSAGES['ko-KR'].chat as Record<string, any>
const koCommon = EMBED_MESSAGES['ko-KR'].common as Record<string, any>
assert.equal(koChat.conversationTime.today, '오늘 {time}')
assert.equal(koChat.conversationTime.yesterday, '어제 {time}')
assert.equal(koChat.conversationTime.thisYear, '{month}월 {day}일 {time}')
assert.equal(koChat.conversationTime.otherYear, '{year}년 {month}월 {day}일 {time}')
assert.equal(koChat.referencesDrawerTitleDocs, '문서 출처')
assert.equal(koChat.referencesDrawerEmpty, '참고 출처가 없습니다')
assert.equal(koCommon.close, '닫기')
// ru-RU
const ruChat = EMBED_MESSAGES['ru-RU'].chat as Record<string, any>
const ruCommon = EMBED_MESSAGES['ru-RU'].common as Record<string, any>
assert.equal(ruChat.conversationTime.today, 'Сегодня {time}')
assert.equal(ruChat.conversationTime.yesterday, 'Вчера {time}')
assert.equal(ruChat.conversationTime.thisYear, '{day}.{month} {time}')
assert.equal(ruChat.conversationTime.otherYear, '{day}.{month}.{year} {time}')
assert.equal(ruChat.referencesDrawerTitleDocs, 'Документы')
assert.equal(ruChat.referencesDrawerEmpty, 'Источники отсутствуют')
assert.equal(ruCommon.close, 'Закрыть')
})
test('normalizeEmbedLocale maps tags accurately with fallback to zh-CN', () => {
assert.equal(normalizeEmbedLocale('zh-CN'), 'zh-CN')
assert.equal(normalizeEmbedLocale('zh'), 'zh-CN')
assert.equal(normalizeEmbedLocale('ZH-cn'), 'zh-CN')
assert.equal(normalizeEmbedLocale('en-US'), 'en-US')
assert.equal(normalizeEmbedLocale('en'), 'en-US')
assert.equal(normalizeEmbedLocale('EN-gb'), 'en-US')
assert.equal(normalizeEmbedLocale('ja-JP'), 'ja-JP')
assert.equal(normalizeEmbedLocale('ja'), 'ja-JP')
assert.equal(normalizeEmbedLocale('ko-KR'), 'ko-KR')
assert.equal(normalizeEmbedLocale('ko'), 'ko-KR')
assert.equal(normalizeEmbedLocale('ru-RU'), 'ru-RU')
assert.equal(normalizeEmbedLocale('ru'), 'ru-RU')
assert.equal(normalizeEmbedLocale('unknown-locale'), 'zh-CN')
assert.equal(normalizeEmbedLocale(' '), 'zh-CN')
})

View File

@ -9,8 +9,10 @@
export {
applyEmbedLocale,
EMBED_LOCALE_STORAGE_KEY,
EMBED_MESSAGES,
normalizeEmbedLocale,
readEmbedLocaleFromUrl,
SUPPORTED_LOCALES,
syncEmbedLocaleFromUrl,
type EmbedLocale,
} from '@/i18n/embed'