Skip to content

feat: add i18n support with react-intl and initial translations #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions locales/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"send": "Senden",
"hide-tool-calls": "Werkzeugaufrufe ausblenden",
"thread-history": "Verlauf der Unterhaltung",
"type-message": "Nachricht eingeben"
}
6 changes: 6 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"send": "Send",
"hide-tool-calls": "Hide tool calls",
"thread-history": "Thread history",
"type-message": "Type your message"
}
6 changes: 6 additions & 0 deletions locales/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"send": "Enviar",
"hide-tool-calls": "Ocultar llamadas de herramientas",
"thread-history": "Historial de conversación",
"type-message": "Escribe tu mensaje"
}
6 changes: 6 additions & 0 deletions locales/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"send": "Envoyer",
"hide-tool-calls": "Masquer les appels d'outils",
"thread-history": "Historique",
"type-message": "Tapez votre message"
}
6 changes: 6 additions & 0 deletions locales/it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"send": "Invia",
"hide-tool-calls": "Nascondi chiamate degli strumenti",
"thread-history": "Cronologia delle conversazioni",
"type-message": "Scrivi il tuo messaggio"
}
6 changes: 6 additions & 0 deletions locales/nl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"send": "Verzenden",
"hide-tool-calls": "Hulpoproepen verbergen",
"thread-history": "Gespreksgeschiedenis",
"type-message": "Typ uw bericht"
}
6 changes: 6 additions & 0 deletions locales/pt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"send": "Enviar",
"hide-tool-calls": "Ocultar chamadas de ferramentas",
"thread-history": "Histórico de conversa",
"type-message": "Digite sua mensagem"
}
6 changes: 6 additions & 0 deletions locales/ru.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"send": "Отправить",
"hide-tool-calls": "Скрыть вызовы инструментов",
"thread-history": "История переписки",
"type-message": "Введите ваше сообщение"
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"nuqs": "^2.4.1",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-intl": "^7.1.11",
"react-markdown": "^10.0.1",
"react-syntax-highlighter": "^15.5.0",
"recharts": "^2.15.1",
Expand Down Expand Up @@ -84,5 +85,5 @@
"react-is": "^19.0.0-rc-69d4b800-20241021",
"@langchain/langgraph-checkpoint": "^0.0.16"
},
"packageManager": "pnpm@10.5.1"
"packageManager": "pnpm@10.10.0"
}
116 changes: 116 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import "./globals.css";
import { Inter } from "next/font/google";
import React from "react";
import { NuqsAdapter } from "nuqs/adapters/next/app";
import I18nProvider from "@/components/I18nProvider";

const inter = Inter({
subsets: ["latin"],
Expand All @@ -21,10 +22,12 @@ export default function RootLayout({
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={inter.className}>
<NuqsAdapter>{children}</NuqsAdapter>
</body>
</html>
<I18nProvider>
<html lang="en">
<body className={inter.className}>
<NuqsAdapter>{children}</NuqsAdapter>
</body>
</html>
</I18nProvider>
);
}
57 changes: 57 additions & 0 deletions src/components/I18nProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"use client";

import { IntlProvider } from "react-intl";
import en from "../../locales/en.json";
import fr from "../../locales/fr.json";
import nl from "../../locales/nl.json";
import de from "../../locales/de.json";
import es from "../../locales/es.json";
import it from "../../locales/it.json";
import pt from "../../locales/pt.json";
import ru from "../../locales/ru.json";
import { createContext, useContext, useState } from "react";

const messages = {
en,
fr,
nl,
de,
es,
it,
pt,
ru,
};

type LocaleContextType = {
locale: keyof typeof messages;
setLocale: React.Dispatch<React.SetStateAction<keyof typeof messages>>;
};

const LocaleContext = createContext<LocaleContextType | undefined>(undefined);

export function useLocale() {
const context = useContext(LocaleContext);
if (!context) {
throw new Error("useLocale must be used within a LocaleProvider");
}
return context;
}

export default function I18nProvider({
children,
}: {
children: React.ReactNode;
}) {
const [locale, setLocale] = useState<keyof typeof messages>("en");

return (
<LocaleContext.Provider value={{ locale, setLocale }}>
<IntlProvider
locale={locale}
messages={messages[locale]}
>
{children}
</IntlProvider>
</LocaleContext.Provider>
);
}
Loading