Skip to content

Commit

Permalink
lang with navigator.language (#391)
Browse files Browse the repository at this point in the history
* lang with navigator.language

* fix test
  • Loading branch information
swuecho authored Nov 26, 2023
1 parent b6c0148 commit ab68766
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions e2e/tests/05_chat_session.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/06_clear_messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/09_session_answer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/10_session_answer_regenerate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions web/src/locales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 3 additions & 1 deletion web/src/store/modules/app/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ab68766

Please sign in to comment.