Skip to content

Commit 43be68e

Browse files
Stable: translation support
1 parent fa1f2f6 commit 43be68e

File tree

11 files changed

+73
-38
lines changed

11 files changed

+73
-38
lines changed

app/i18n.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

app/layout.tsx

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1-
import type { Metadata } from "next";
1+
"use client";
2+
23
import { Inter } from "next/font/google";
3-
import { appWithTranslation } from "./i18n";
4-
import type { AppProps } from "next/app";
54
import "./globals.css";
5+
import { I18nextProvider } from "react-i18next";
6+
import i18n from "@/i18n";
67

78
const inter = Inter({ subsets: ["latin"] });
89

9-
export const metadata: Metadata = {
10-
title: "CodeQuill",
11-
description: "Create, share, and store your codes",
12-
};
13-
14-
const RootLayout = ({ children }: any) => {
10+
export default function RootLayout({
11+
children,
12+
}: Readonly<{
13+
children: React.ReactNode;
14+
}>) {
1515
return (
16-
<html lang="en">
17-
<head>
18-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
19-
</head>
20-
<body className={inter.className}>{children}</body>
21-
</html>
16+
<I18nextProvider i18n={i18n}>
17+
<html lang="en">
18+
<head>
19+
<meta
20+
name="viewport"
21+
content="width=device-width, initial-scale=1.0"
22+
/>
23+
<meta name="title" content="CodeQuill" />
24+
<meta
25+
name="description"
26+
content="Create, share, and store your codes"
27+
/>
28+
<title>CodeQuill</title>
29+
</head>
30+
<body className={inter.className}>{children}</body>
31+
</html>
32+
</I18nextProvider>
2233
);
23-
};
24-
25-
export default appWithTranslation(RootLayout);
34+
}

app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet";
66
import { Menu } from "lucide-react";
77
import { Button } from "@/components/ui/button";
88
import axios from "axios";
9-
import { useTranslation } from "@/app/i18n";
9+
import { useTranslation } from "next-i18next";
1010

1111
const HomePage = () => {
1212
const { t } = useTranslation("common");

components/Editor.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
SelectValue,
1414
} from "@/components/ui/select";
1515
import { Check, Info, Loader2 } from "lucide-react";
16-
import { useTranslation } from "@/app/i18n";
16+
import { useTranslation } from "next-i18next";
1717

1818
const DEFAULT_LANGUAGE = "html";
1919

@@ -51,7 +51,7 @@ const CodeEditor = ({
5151
getStoredDefaultLanguage()
5252
);
5353
const [language, setLanguage] = useState(DEFAULT_LANGUAGE);
54-
const [name, setName] = useState("Untitled");
54+
const [name, setName] = useState(`${t("untitled") || "Untitled"}`);
5555
const [showPreview, setShowPreview] = useState(true);
5656
const [saveSuccess, setSaveSuccess] = useState("");
5757
const [isSaving, setIsSaving] = useState(false);
@@ -74,17 +74,17 @@ const CodeEditor = ({
7474
const project = response.data;
7575
setCode(project.code);
7676
setLanguage(project.language);
77-
setName(project?.name || "Untitled");
77+
setName(project?.name || `${t("untitled")}`);
7878
})
7979
.finally(() => {
8080
setIsLoading(false);
8181
});
8282
} else {
8383
setCode("");
8484
setLanguage(defaultLanguage);
85-
setName("Untitled");
85+
setName(`${t("untitled")}`);
8686
}
87-
}, [selectedProject, defaultLanguage]);
87+
}, [selectedProject, defaultLanguage, t]);
8888

8989
useEffect(() => {
9090
// Set dark mode based on system preference

components/Sidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
} from "@/components/ui/context-menu";
4141
import { Input } from "@/components/ui/input";
4242
import { Skeleton } from "@/components/ui/skeleton";
43-
import { useTranslation } from "@/app/i18n";
43+
import { useTranslation } from "next-i18next";
4444

4545
interface Project {
4646
id: number;

i18n.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import i18n from 'i18next';
2+
import { initReactI18next } from 'react-i18next';
3+
import common_en from '@/public/locales/en/common.json';
4+
import common_es from '@/public/locales/es/common.json';
5+
import common_fr from '@/public/locales/fr/common.json';
6+
7+
i18n
8+
.use(initReactI18next) // Passes i18n down to react-i18next
9+
.init({
10+
resources: {
11+
en: { common: common_en },
12+
es: { common: common_es },
13+
fr: { common: common_fr },
14+
},
15+
lng: 'en', // Default language
16+
fallbackLng: 'en', // Fallback language
17+
interpolation: {
18+
escapeValue: false, // React escapes by default
19+
},
20+
});
21+
22+
export default i18n;

package-lock.json

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"author": "The-Best-Codes",
44
"license": "MIT",
55
"description": "Organize, Edit, and Share your Code Snippets",
6-
"version": "1.2.0",
6+
"version": "1.2.1",
77
"private": true,
88
"scripts": {
99
"dev": "next dev",
@@ -33,6 +33,7 @@
3333
"axios": "^1.7.4",
3434
"class-variance-authority": "^0.7.0",
3535
"clsx": "^2.1.1",
36+
"fs": "^0.0.1-security",
3637
"highlight.js": "^11.10.0",
3738
"i18next": "^23.12.3",
3839
"lucide-react": "^0.407.0",

public/locales/en/common.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@
2121
"error": "Error",
2222
"save": "Save",
2323
"hide-preview": "Hide Preview",
24-
"show-preview": "Show Preview"
24+
"show-preview": "Show Preview",
25+
"untitled": "Untitled"
2526
}

public/locales/es/common.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@
2121
"error": "Error",
2222
"save": "Guardar",
2323
"hide-preview": "Ocultar Vista Previa",
24-
"show-preview": "Mostrar Vista Previa"
24+
"show-preview": "Mostrar Vista Previa",
25+
"untitled": "Sin Título"
2526
}

0 commit comments

Comments
 (0)