Skip to content

Commit

Permalink
🐛 fix: Fix language settings may not take effect (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
mushan0x0 authored Dec 11, 2023
1 parent b2d4d4d commit a5db64e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/const/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export const DEFAUTT_AGENT_TTS_CONFIG: LobeAgentTTSConfig = {

export const VISION_MODEL_DEFAULT_MAX_TOKENS = 1000;

export const COOKIE_CACHE_DAYS = 30;

export const DEFAULT_AGENT_CONFIG: LobeAgentConfig = {
autoCreateTopicThreshold: 2,
displayMode: 'chat',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { initReactI18next } from 'react-i18next';

import { getClientConfig } from '@/config/client';
import { DEFAULT_LANG, LOBE_LOCALE_COOKIE } from '@/const/locale';
import { COOKIE_CACHE_DAYS } from '@/const/settings';
import type { Namespaces } from '@/types/locale';
import { isOnServerSide } from '@/utils/env';

Expand Down Expand Up @@ -39,6 +40,7 @@ export const createI18nNext = (lang?: string) => {
defaultNS: ['error', 'common'],
detection: {
caches: ['cookie'],
cookieMinutes: 60 * 24 * COOKIE_CACHE_DAYS,
lookupCookie: LOBE_LOCALE_COOKIE,
},
fallbackLng: DEFAULT_LANG,
Expand Down
8 changes: 7 additions & 1 deletion src/utils/cookie.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import dayjs from 'dayjs';

import { COOKIE_CACHE_DAYS } from '@/const/settings';

export const setCookie = (key: string, value: string | undefined) => {
const expires = dayjs().add(COOKIE_CACHE_DAYS, 'day').toISOString();

// eslint-disable-next-line unicorn/no-document-cookie
document.cookie = `${key}=${value};path=/;`;
document.cookie = `${key}=${value};expires=${expires};path=/;`;
};

0 comments on commit a5db64e

Please # to comment.