Skip to content

Commit 0b2a6dd

Browse files
authored
test works (#1211)
1 parent d3cf8b2 commit 0b2a6dd

32 files changed

+272
-17
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

app/layout.tsx app/[locale]/layout.tsx

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { Metadata } from "next"
21
import { Toaster } from "@/components/ui/sonner"
32
import { GlobalState } from "@/components/utility/global-state"
43
import { Providers } from "@/components/utility/providers"
4+
import TranslationsProvider from "@/components/utility/translations-provider"
5+
import initTranslations from "@/lib/i18n"
56
import { Database } from "@/supabase/types"
67
import { createServerClient } from "@supabase/ssr"
8+
import { Metadata } from "next"
79
import { Inter } from "next/font/google"
810
import { cookies } from "next/headers"
911
import { ReactNode } from "react"
@@ -13,6 +15,9 @@ const inter = Inter({ subsets: ["latin"] })
1315

1416
interface RootLayoutProps {
1517
children: ReactNode
18+
params: {
19+
locale: string
20+
}
1621
}
1722

1823
export const metadata: Metadata = {
@@ -22,7 +27,12 @@ export const metadata: Metadata = {
2227
}
2328
}
2429

25-
export default async function RootLayout({ children }: RootLayoutProps) {
30+
const i18nNamespaces = ["translation"]
31+
32+
export default async function RootLayout({
33+
children,
34+
params: { locale }
35+
}: RootLayoutProps) {
2636
const cookieStore = cookies()
2737
const supabase = createServerClient<Database>(
2838
process.env.NEXT_PUBLIC_SUPABASE_URL!,
@@ -37,14 +47,22 @@ export default async function RootLayout({ children }: RootLayoutProps) {
3747
)
3848
const session = (await supabase.auth.getSession()).data.session
3949

50+
const { t, resources } = await initTranslations(locale, i18nNamespaces)
51+
4052
return (
4153
<html lang="en" suppressHydrationWarning>
4254
<body className={inter.className}>
4355
<Providers attribute="class" defaultTheme="dark">
44-
<Toaster richColors position="top-center" duration={2000} />
45-
<div className="bg-background text-foreground flex h-screen flex-col items-center">
46-
{session ? <GlobalState>{children}</GlobalState> : children}
47-
</div>
56+
<TranslationsProvider
57+
namespaces={i18nNamespaces}
58+
locale={locale}
59+
resources={resources}
60+
>
61+
<Toaster richColors position="top-center" duration={2000} />
62+
<div className="bg-background text-foreground flex h-screen flex-col items-center">
63+
{session ? <GlobalState>{children}</GlobalState> : children}
64+
</div>
65+
</TranslationsProvider>
4866
</Providers>
4967
</body>
5068
</html>
File renamed without changes.
File renamed without changes.
File renamed without changes.

app/page.tsx app/[locale]/page.tsx

File renamed without changes.

app/setup/page.tsx app/[locale]/setup/page.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ import { TablesUpdate } from "@/supabase/types"
99
import { ChatSettings } from "@/types"
1010
import { useRouter } from "next/navigation"
1111
import { useContext, useEffect, useState } from "react"
12-
import { APIStep } from "../../components/setup/api-step"
13-
import { FinishStep } from "../../components/setup/finish-step"
14-
import { ProfileStep } from "../../components/setup/profile-step"
12+
import { APIStep } from "../../../components/setup/api-step"
13+
import { FinishStep } from "../../../components/setup/finish-step"
14+
import { ProfileStep } from "../../../components/setup/profile-step"
1515
import {
1616
SETUP_STEP_COUNT,
1717
StepContainer
18-
} from "../../components/setup/step-container"
19-
import { WorkspaceStep } from "../../components/setup/workspace-step"
18+
} from "../../../components/setup/step-container"
19+
import { WorkspaceStep } from "../../../components/setup/workspace-step"
2020

2121
export default function SetupPage() {
2222
const { profile, setProfile, setSelectedWorkspace, setWorkspaces } =
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

components/chat/chat-input.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
IconSend
1010
} from "@tabler/icons-react"
1111
import { FC, useContext, useEffect, useRef, useState } from "react"
12+
import { useTranslation } from "react-i18next"
1213
import { Input } from "../ui/input"
1314
import { TextareaAutosize } from "../ui/textarea-autosize"
1415
import { ChatCommandInput } from "./chat-command-input"
@@ -20,6 +21,8 @@ import { useSelectFileHandler } from "./chat-hooks/use-select-file-handler"
2021
interface ChatInputProps {}
2122

2223
export const ChatInput: FC<ChatInputProps> = ({}) => {
24+
const { t } = useTranslation()
25+
2326
useHotkey("l", () => {
2427
handleFocusChatInput()
2528
})
@@ -175,7 +178,9 @@ export const ChatInput: FC<ChatInputProps> = ({}) => {
175178
<TextareaAutosize
176179
textareaRef={chatInputRef}
177180
className="ring-offset-background placeholder:text-muted-foreground focus-visible:ring-ring text-md flex w-full resize-none rounded-md border-none bg-transparent px-14 py-2 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50"
178-
placeholder={`Ask anything. Type "/" for prompts, "@" for files, and "#" for tools.`}
181+
placeholder={t(
182+
`Ask anything. Type "/" for prompts, "@" for files, and "#" for tools.`
183+
)}
179184
onValueChange={handleInputChange}
180185
value={userInput}
181186
minRows={1}

components/chat/chat-ui.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Loading from "@/app/loading"
1+
import Loading from "@/app/[locale]/loading"
22
import { useChatHandler } from "@/components/chat/chat-hooks/use-chat-handler"
33
import { ChatbotUIContext } from "@/context/context"
44
import { getChatById } from "@/db/chats"

components/chat/quick-settings.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { LLMID } from "@/types"
99
import { IconChevronDown, IconRobotFace } from "@tabler/icons-react"
1010
import Image from "next/image"
1111
import { FC, useContext, useEffect, useRef, useState } from "react"
12+
import { useTranslation } from "react-i18next"
1213
import { ModelIcon } from "../models/model-icon"
1314
import { Button } from "../ui/button"
1415
import {
@@ -22,6 +23,8 @@ import { QuickSettingOption } from "./quick-setting-option"
2223
interface QuickSettingsProps {}
2324

2425
export const QuickSettings: FC<QuickSettingsProps> = ({}) => {
26+
const { t } = useTranslation()
27+
2528
useHotkey("p", () => setIsOpen(prevState => !prevState))
2629

2730
const {
@@ -201,7 +204,7 @@ export const QuickSettings: FC<QuickSettingsProps> = ({}) => {
201204

202205
{selectedPreset?.name ||
203206
selectedAssistant?.name ||
204-
"Quick Settings"}
207+
t("Quick Settings")}
205208
</div>
206209

207210
<IconChevronDown className="ml-1" />

components/sharing/share-item.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Loading from "@/app/loading"
1+
import Loading from "@/app/[locale]/loading"
22
import { ContentType } from "@/types"
33
import { User } from "@supabase/supabase-js"
44
import { IconDownload, IconLock } from "@tabler/icons-react"
-16 KB
Binary file not shown.

components/utility/global-state.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
"use client"
44

5-
import Loading from "@/app/loading"
5+
import Loading from "@/app/[locale]/loading"
66
import { ChatbotUIContext } from "@/context/context"
77
import { getAssistantWorkspacesByWorkspaceId } from "@/db/assistants"
88
import { getChatsByWorkspaceId } from "@/db/chats"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"use client"
2+
3+
import initTranslations from "@/lib/i18n"
4+
import { createInstance } from "i18next"
5+
import { I18nextProvider } from "react-i18next"
6+
7+
export default function TranslationsProvider({
8+
children,
9+
locale,
10+
namespaces,
11+
resources
12+
}: any) {
13+
const i18n = createInstance()
14+
15+
initTranslations(locale, namespaces, i18n, resources)
16+
17+
return <I18nextProvider i18n={i18n}>{children}</I18nextProvider>
18+
}

i18nConfig.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const i18nConfig = {
2+
defaultLocale: "en",
3+
locales: [
4+
"ar",
5+
"bn",
6+
"de",
7+
"en",
8+
"es",
9+
"fr",
10+
"he",
11+
"id",
12+
"it",
13+
"ja",
14+
"ko",
15+
"pt",
16+
"ru",
17+
"si",
18+
"sv",
19+
"te",
20+
"vi",
21+
"zh"
22+
]
23+
}
24+
25+
module.exports = i18nConfig

lib/i18n.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import i18nConfig from "@/i18nConfig"
2+
import { createInstance } from "i18next"
3+
import resourcesToBackend from "i18next-resources-to-backend"
4+
import { initReactI18next } from "react-i18next/initReactI18next"
5+
6+
export default async function initTranslations(
7+
locale: any,
8+
namespaces: any,
9+
i18nInstance?: any,
10+
resources?: any
11+
) {
12+
i18nInstance = i18nInstance || createInstance()
13+
14+
i18nInstance.use(initReactI18next)
15+
16+
if (!resources) {
17+
i18nInstance.use(
18+
resourcesToBackend(
19+
(language: string, namespace: string) =>
20+
import(`/public/locales/${language}/${namespace}.json`)
21+
)
22+
)
23+
}
24+
25+
await i18nInstance.init({
26+
lng: locale,
27+
resources,
28+
fallbackLng: i18nConfig.defaultLocale,
29+
supportedLngs: i18nConfig.locales,
30+
defaultNS: namespaces[0],
31+
fallbackNS: namespaces[0],
32+
ns: namespaces,
33+
preload: resources ? [] : i18nConfig.locales
34+
})
35+
36+
return {
37+
i18n: i18nInstance,
38+
resources: i18nInstance.services.resourceStore.data,
39+
t: i18nInstance.t
40+
}
41+
}

middleware.ts

+37
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
1+
// import { createClient } from "@/lib/supabase/middleware"
2+
// import { NextResponse, type NextRequest } from "next/server"
3+
4+
// export async function middleware(request: NextRequest) {
5+
// try {
6+
// const { supabase, response } = createClient(request)
7+
8+
// const session = await supabase.auth.getSession()
9+
10+
// const redirectToChat = session && request.nextUrl.pathname === "/"
11+
12+
// if (redirectToChat) {
13+
// return NextResponse.redirect(new URL("/chat", request.url))
14+
// }
15+
16+
// return response
17+
// } catch (e) {
18+
// return NextResponse.next({
19+
// request: {
20+
// headers: request.headers
21+
// }
22+
// })
23+
// }
24+
// }
25+
26+
// middleware.ts
27+
128
import { createClient } from "@/lib/supabase/middleware"
29+
import { i18nRouter } from "next-i18n-router"
230
import { NextResponse, type NextRequest } from "next/server"
31+
import i18nConfig from "./i18nConfig"
332

433
export async function middleware(request: NextRequest) {
34+
// i18n routing
35+
const i18nResult = i18nRouter(request, i18nConfig)
36+
if (i18nResult) return i18nResult
37+
538
try {
639
const { supabase, response } = createClient(request)
740

@@ -22,3 +55,7 @@ export async function middleware(request: NextRequest) {
2255
})
2356
}
2457
}
58+
59+
export const config = {
60+
matcher: "/((?!api|static|.*\\..*|_next).*)"
61+
}

0 commit comments

Comments
 (0)