From ab68766c8aff0fade08fc4bb79cc998e176ffa2f Mon Sep 17 00:00:00 2001 From: Hao Wu Date: Sun, 26 Nov 2023 11:35:54 +0800 Subject: [PATCH] lang with navigator.language (#391) * lang with navigator.language * fix test --- e2e/tests/05_chat_session.spec.ts | 4 ++-- e2e/tests/06_clear_messages.spec.ts | 2 +- e2e/tests/09_session_answer.spec.ts | 2 +- e2e/tests/10_session_answer_regenerate.spec.ts | 2 +- web/src/locales/index.ts | 3 +-- web/src/store/modules/app/helper.ts | 4 +++- 6 files changed, 9 insertions(+), 8 deletions(-) diff --git a/e2e/tests/05_chat_session.spec.ts b/e2e/tests/05_chat_session.spec.ts index ca30a9f2..71f5e6cc 100644 --- a/e2e/tests/05_chat_session.spec.ts +++ b/e2e/tests/05_chat_session.spec.ts @@ -38,13 +38,13 @@ test('test', async ({ page }) => { const session_1 = sessions_1[0]; expect(session_1.topic).toBe('test_session_topic'); - await page.getByRole('button', { name: '新对话' }).click(); + await page.getByRole('button', { name: 'New Chat' }).click(); await page.getByTestId('edit_session_topic').click(); await page.getByTestId('edit_session_topic_input').locator('input').click(); await page.getByTestId('edit_session_topic_input').locator('input').fill('test_session_topic_2'); await page.getByTestId('save_session_topic').click(); - await page.getByRole('button', { name: '新对话' }).click(); + await page.getByRole('button', { name: 'New Chat' }).click(); await page.getByTestId('edit_session_topic').click(); await page.getByTestId('edit_session_topic_input').locator('input').fill('test_session_topic_3'); await page.getByTestId('save_session_topic').click(); diff --git a/e2e/tests/06_clear_messages.spec.ts b/e2e/tests/06_clear_messages.spec.ts index 63b25a09..e7767331 100644 --- a/e2e/tests/06_clear_messages.spec.ts +++ b/e2e/tests/06_clear_messages.spec.ts @@ -42,7 +42,7 @@ test('after clear conversation, only system message remains', async ({ page }) = // clear await page.getByRole('contentinfo').getByRole('button').first().click(); - await page.getByRole('button', { name: '是' }).click(); + await page.getByRole('button', { name: 'Yes' }).click(); // sleep 500 ms await page.waitForTimeout(1000); diff --git a/e2e/tests/09_session_answer.spec.ts b/e2e/tests/09_session_answer.spec.ts index 4c714018..0d56f7d1 100644 --- a/e2e/tests/09_session_answer.spec.ts +++ b/e2e/tests/09_session_answer.spec.ts @@ -12,7 +12,7 @@ test('test', async ({ page }) => { await page.getByTestId('signup').click(); await page.waitForTimeout(1000); - await page.locator('a').filter({ hasText: '新对话' }).click(); + await page.locator('a').filter({ hasText: 'New Chat' }).click(); // set debug mode await page.getByRole('contentinfo').getByRole('button').nth(3).click(); diff --git a/e2e/tests/10_session_answer_regenerate.spec.ts b/e2e/tests/10_session_answer_regenerate.spec.ts index bfc35581..7bd230ff 100644 --- a/e2e/tests/10_session_answer_regenerate.spec.ts +++ b/e2e/tests/10_session_answer_regenerate.spec.ts @@ -17,7 +17,7 @@ test('test', async ({ page }) => { await page.getByTestId('signup').click(); await page.waitForTimeout(1000); - await page.locator('a').filter({ hasText: '新对话' }).click(); + await page.locator('a').filter({ hasText: 'New Chat' }).click(); // set debug mode await page.getByRole('contentinfo').getByRole('button').nth(3).click(); diff --git a/web/src/locales/index.ts b/web/src/locales/index.ts index 91e86fb4..476578b1 100644 --- a/web/src/locales/index.ts +++ b/web/src/locales/index.ts @@ -5,10 +5,9 @@ import zhCN from './zh-CN.json' import zhTW from './zh-TW.json' import type { Language } from '@/store/modules/app/helper' -const defaultLocale = navigator.language.split('-')[0] const i18n = createI18n({ - locale: defaultLocale, + locale: navigator.language.split('-')[0], fallbackLocale: 'en', allowComposition: true, messages: { diff --git a/web/src/store/modules/app/helper.ts b/web/src/store/modules/app/helper.ts index a15b07e2..f7b93784 100644 --- a/web/src/store/modules/app/helper.ts +++ b/web/src/store/modules/app/helper.ts @@ -12,8 +12,10 @@ export interface AppState { language: Language } +const defaultLanguage = navigator.language as Language + export function defaultSetting(): AppState { - return { siderCollapsed: false, theme: 'light', language: 'zh-CN' } + return { siderCollapsed: false, theme: 'light', language: defaultLanguage } } export function getLocalSetting(): AppState {