first relase
This commit is contained in:
parent
d3a42ba6e9
commit
c6afce22ed
288 changed files with 55505 additions and 192 deletions
51
context/i18n.ts
Normal file
51
context/i18n.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import type { Locale } from '@/i18n-config';
|
||||
import {
|
||||
getDocLanguage,
|
||||
getLanguage,
|
||||
getPricingPageLanguage,
|
||||
} from '@/i18n-config/language';
|
||||
import { noop } from 'lodash-es';
|
||||
import { createContext, useContext } from 'use-context-selector';
|
||||
|
||||
type II18NContext = {
|
||||
locale: Locale;
|
||||
i18n: Record<string, any>;
|
||||
setLocaleOnClient: (_lang: Locale, _reloadPage?: boolean) => Promise<void>;
|
||||
};
|
||||
|
||||
const I18NContext = createContext<II18NContext>({
|
||||
locale: 'en-US',
|
||||
i18n: {},
|
||||
setLocaleOnClient: async (_lang: Locale, _reloadPage?: boolean) => {
|
||||
noop();
|
||||
},
|
||||
});
|
||||
|
||||
export const useI18N = () => useContext(I18NContext);
|
||||
export const useGetLanguage = () => {
|
||||
const { locale } = useI18N();
|
||||
|
||||
return getLanguage(locale);
|
||||
};
|
||||
export const useGetPricingPageLanguage = () => {
|
||||
const { locale } = useI18N();
|
||||
|
||||
return getPricingPageLanguage(locale);
|
||||
};
|
||||
|
||||
export const defaultDocBaseUrl = 'https://docs.dify.ai';
|
||||
export const useDocLink = (
|
||||
baseUrl?: string,
|
||||
): ((path?: string, pathMap?: { [index: string]: string }) => string) => {
|
||||
let baseDocUrl = baseUrl || defaultDocBaseUrl;
|
||||
baseDocUrl = baseDocUrl.endsWith('/') ? baseDocUrl.slice(0, -1) : baseDocUrl;
|
||||
const { locale } = useI18N();
|
||||
const docLanguage = getDocLanguage(locale);
|
||||
return (path?: string, pathMap?: { [index: string]: string }): string => {
|
||||
const pathUrl = path || '';
|
||||
let targetPath = pathMap ? pathMap[locale] || pathUrl : pathUrl;
|
||||
targetPath = targetPath.startsWith('/') ? targetPath.slice(1) : targetPath;
|
||||
return `${baseDocUrl}/${docLanguage}/${targetPath}`;
|
||||
};
|
||||
};
|
||||
export default I18NContext;
|
||||
25
context/query-client.tsx
Normal file
25
context/query-client.tsx
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
'use client';
|
||||
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
|
||||
import type { FC, PropsWithChildren } from 'react';
|
||||
|
||||
const STALE_TIME = 1000 * 60 * 30; // 30 minutes
|
||||
|
||||
const client = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
staleTime: STALE_TIME,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const TanstackQueryInitializer: FC<PropsWithChildren> = (props) => {
|
||||
const { children } = props;
|
||||
return (
|
||||
<QueryClientProvider client={client}>
|
||||
{children}
|
||||
<ReactQueryDevtools initialIsOpen={false} />
|
||||
</QueryClientProvider>
|
||||
);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue