From 827a63ea56a1f43e8433e90e4a2f639438778edf Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Sat, 7 Nov 2026 21:22:38 +0800 Subject: [PATCH] Fix zh-TW emoji picker showing Simplified Chinese labels --- packages/comment-widget/src/emoji-button.ts | 33 ++++++++++++++++++- .../tests/emoji-locale.browser.test.js | 33 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 packages/comment-widget/tests/emoji-locale.browser.test.js diff --git a/packages/comment-widget/src/emoji-button.ts b/packages/comment-widget/src/emoji-button.ts index 04a65b5..9c90e73 100644 --- a/packages/comment-widget/src/emoji-button.ts +++ b/packages/comment-widget/src/emoji-button.ts @@ -18,9 +18,40 @@ import { createRef, type Ref, ref } from 'lit/directives/ref.js'; import { getLocale } from './locale'; import baseStyles from './styles/base'; +// emoji-mart does not ship a Traditional Chinese translation. +const zhTW = { + search: '搜尋', + search_no_results_1: '喔不!', + search_no_results_2: '找不到相關表情', + pick: '選擇一個表情…', + add_custom: '新增自訂表情', + categories: { + activity: '活動', + custom: '自訂', + flags: '旗幟', + foods: '食物與飲品', + frequent: '最近使用', + nature: '動物與自然', + objects: '物品', + people: '表情與角色', + places: '旅行與景點', + search: '搜尋結果', + symbols: '符號', + }, + skins: { + choose: '選擇預設膚色', + 1: '預設', + 2: '白色', + 3: '偏白', + 4: '中等', + 5: '偏黑', + 6: '黑色', + }, +}; + const localeMap = { 'zh-CN': zh, - 'zh-TW': zh, + 'zh-TW': zhTW, en: en, es: es, }; diff --git a/packages/comment-widget/tests/emoji-locale.browser.test.js b/packages/comment-widget/tests/emoji-locale.browser.test.js new file mode 100644 index 0000000..d52ef30 --- /dev/null +++ b/packages/comment-widget/tests/emoji-locale.browser.test.js @@ -0,0 +1,33 @@ +import { assert, test } from 'vitest'; +import { until } from './browser-helpers.js'; + +test('Emoji picker uses Traditional Chinese for zh-TW', async () => { + // biome-ignore lint/suspicious/noDocumentCookie: Exercise the widget's existing locale cookie contract. + document.cookie = 'language=zh-TW; path=/'; + + await import('../src/emoji-button.ts'); + const emoji = document.createElement('emoji-button'); + document.body.append(emoji); + + await emoji.handleOpenEmojiPicker(new MouseEvent('click')); + await until(() => + document + .querySelector('em-emoji-picker') + ?.shadowRoot?.querySelector('input') + ); + + const picker = document.querySelector('em-emoji-picker'); + assert( + picker.shadowRoot.querySelector('input').placeholder === '搜尋', + 'Search placeholder must be Traditional Chinese' + ); + + const categoryLabels = [ + ...picker.shadowRoot.querySelectorAll('button[aria-label]'), + ].map((button) => button.getAttribute('aria-label')); + assert( + categoryLabels.includes('表情與角色') && + !categoryLabels.includes('表情与角色'), + 'Category labels must be Traditional Chinese' + ); +});