next app with basic i18n setup

This commit is contained in:
dimitar 2025-03-26 17:50:24 +01:00
parent c03ac3c172
commit 269789e5ed
30 changed files with 6221 additions and 0 deletions

41
.gitignore vendored Normal file
View File

@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
# env files (can opt-in for committing if needed)
.env*
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts

16
eslint.config.mjs Normal file
View File

@ -0,0 +1,16 @@
import { dirname } from "path";
import { fileURLToPath } from "url";
import { FlatCompat } from "@eslint/eslintrc";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
});
const eslintConfig = [
...compat.extends("next/core-web-vitals", "next/typescript"),
];
export default eslintConfig;

29
next.config.js Normal file
View File

@ -0,0 +1,29 @@
import createNextIntlPlugin from "next-intl/plugin";
const withNextIntl = createNextIntlPlugin();
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
remotePatterns: [
{
protocol: "https",
hostname: "**",
},
],
},
typescript: {
// !! WARN !!
// Dangerously allow production builds to successfully complete even if
// your project has type errors.
// !! WARN !!
ignoreBuildErrors: true,
},
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true,
},
};
export default withNextIntl(nextConfig);

5474
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

32
package.json Normal file
View File

@ -0,0 +1,32 @@
{
"name": "ngc",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"clsx": "^2.1.1",
"lucide-react": "^0.484.0",
"next": "14.1.0",
"next-intl": "^3.4.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tailwind-merge": "^3.0.2"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint-config-next": "15.2.4",
"tailwindcss": "^4",
"typescript": "^5"
}
}

5
postcss.config.mjs Normal file
View File

@ -0,0 +1,5 @@
const config = {
plugins: ["@tailwindcss/postcss"],
};
export default config;

1
public/file.svg Normal file
View File

@ -0,0 +1 @@
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>

After

Width:  |  Height:  |  Size: 391 B

1
public/globe.svg Normal file
View File

@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

1
public/next.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

1
public/vercel.svg Normal file
View File

@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>

After

Width:  |  Height:  |  Size: 128 B

1
public/window.svg Normal file
View File

@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>

After

Width:  |  Height:  |  Size: 385 B

View File

@ -0,0 +1,50 @@
import { Inter, Roboto_Mono } from "next/font/google";
import "../globals.css";
import { notFound } from "next/navigation";
import { locales } from "@/i18n/config";
import { ThemeProvider } from "@/components/theme-provider";
import { Navbar } from "@/components/navbar";
import { unstable_setRequestLocale } from "next-intl/server";
const inter = Inter({
subsets: ["latin"],
variable: "--font-inter",
});
const robotoMono = Roboto_Mono({
subsets: ["latin"],
variable: "--font-roboto-mono",
});
export function generateStaticParams() {
return locales.map((locale) => ({ locale }));
}
export default async function LocaleLayout({
children,
params: { locale },
}: {
children: React.ReactNode;
params: { locale: string };
}) {
// Validate that the incoming `locale` parameter is valid
if (!locales.includes(locale as any)) {
notFound();
}
// Enable static rendering
unstable_setRequestLocale(locale);
return (
<html lang={locale} suppressHydrationWarning>
<body className={`${inter.variable} ${robotoMono.variable} antialiased`}>
<ThemeProvider>
<Navbar />
<main className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
{children}
</main>
</ThemeProvider>
</body>
</html>
);
}

25
src/app/[locale]/page.tsx Normal file
View File

@ -0,0 +1,25 @@
import { Hero } from "@/components/hero";
import { unstable_setRequestLocale } from "next-intl/server";
type Props = {
params: { locale: string };
};
export default async function Home({ params: { locale } }: Props) {
unstable_setRequestLocale(locale);
return (
<>
<Hero />
</>
);
}
export function generateMetadata({ params: { locale } }: Props) {
unstable_setRequestLocale(locale);
return {
title: "My App",
description: "My App Description",
};
}

BIN
src/app/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

24
src/app/globals.css Normal file
View File

@ -0,0 +1,24 @@
@import "tailwindcss";
:root {
--background: #ffffff;
--foreground: #171717;
}
.dark {
--background: #0a0a0a;
--foreground: #ededed;
}
@theme inline {
--color-background: var(--background);
--color-foreground: var(--foreground);
--font-sans: var(--font-inter);
--font-mono: var(--font-roboto-mono);
}
body {
background: var(--background);
color: var(--foreground);
font-family: var(--font-sans), system-ui, sans-serif;
}

26
src/app/layout.tsx Normal file
View File

@ -0,0 +1,26 @@
import { Inter, Roboto_Mono } from "next/font/google";
import "./globals.css";
const inter = Inter({
subsets: ["latin"],
variable: "--font-inter",
});
const robotoMono = Roboto_Mono({
subsets: ["latin"],
variable: "--font-roboto-mono",
});
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html suppressHydrationWarning>
<body className={`${inter.variable} ${robotoMono.variable} antialiased`}>
{children}
</body>
</html>
);
}

6
src/app/page.tsx Normal file
View File

@ -0,0 +1,6 @@
import { redirect } from "next/navigation";
import { defaultLocale } from "@/i18n/config";
export default function RootPage() {
redirect(`/${defaultLocale}`);
}

79
src/components/hero.tsx Normal file
View File

@ -0,0 +1,79 @@
import { getTranslations } from "next-intl/server";
import { Button } from "./ui/button";
import Image from "next/image";
export async function Hero() {
const t = await getTranslations("hero");
return (
<div className="relative isolate overflow-hidden bg-gray-900">
<svg
className="absolute inset-0 -z-10 h-full w-full stroke-white/10 [mask-image:radial-gradient(100%_100%_at_top_right,white,transparent)]"
aria-hidden="true"
>
<defs>
<pattern
id="983e3e4c-de6d-4c3f-8d64-b9761d1534cc"
width={200}
height={200}
x="50%"
y={-1}
patternUnits="userSpaceOnUse"
>
<path d="M.5 200V.5H200" fill="none" />
</pattern>
</defs>
<svg x="50%" y={-1} className="overflow-visible fill-gray-800/20">
<path
d="M-200 0h201v201h-201Z M600 0h201v201h-201Z M-400 600h201v201h-201Z M200 800h201v201h-201Z"
strokeWidth={0}
/>
</svg>
<rect
width="100%"
height="100%"
strokeWidth={0}
fill="url(#983e3e4c-de6d-4c3f-8d64-b9761d1534cc)"
/>
</svg>
<div
className="absolute left-[calc(50%-4rem)] top-10 -z-10 transform-gpu blur-3xl sm:left-[calc(50%-18rem)] lg:left-48 lg:top-[calc(50%-30rem)] xl:left-[calc(50%-24rem)]"
aria-hidden="true"
>
<div
className="aspect-[1108/632] w-[69.25rem] bg-gradient-to-r from-[#80caff] to-[#4f46e5] opacity-20"
style={{
clipPath:
"polygon(73.6% 51.7%, 91.7% 11.8%, 100% 46.4%, 97.4% 82.2%, 92.5% 84.9%, 75.7% 64%, 55.3% 47.5%, 46.5% 49.4%, 45% 62.9%, 50.3% 87.2%, 21.3% 64.1%, 0.1% 100%, 5.4% 51.1%, 21.4% 63.9%, 58.9% 0.2%, 73.6% 51.7%)",
}}
/>
</div>
<div className="mx-auto max-w-7xl px-6 pb-24 pt-10 sm:pb-32 lg:flex lg:px-8 lg:py-40">
<div className="mx-auto max-w-2xl flex-shrink-0 lg:mx-0 lg:max-w-xl lg:pt-8">
<h1 className="mt-10 text-4xl font-bold tracking-tight text-white sm:text-6xl">
{t("title")}{" "}
<span className="text-blue-500">{t("titleColored")}</span>
</h1>
<p className="mt-6 text-lg leading-8 text-gray-300">
{t("description")}
</p>
<div className="mt-10 flex items-center gap-x-6">
<Button variant="primary">{t("primaryButton")}</Button>
<Button variant="secondary">{t("secondaryButton")}</Button>
</div>
</div>
<div className="mx-auto mt-16 flex max-w-2xl sm:mt-24 lg:ml-10 lg:mt-0 lg:mr-0 lg:max-w-none lg:flex-none xl:ml-32">
<div className="max-w-3xl flex-none sm:max-w-5xl lg:max-w-none">
<Image
src="/hero-image.webp"
alt="App screenshot"
width={2432}
height={1442}
className="w-[76rem] rounded-md bg-white/5 shadow-2xl ring-1 ring-white/10"
/>
</div>
</div>
</div>
</div>
);
}

182
src/components/navbar.tsx Normal file
View File

@ -0,0 +1,182 @@
// // ngc/src/components/navbar.tsx
// "use client";
// import { useTheme } from "./theme-provider";
// import Link from "next/link";
// import { usePathname } from "next/navigation";
// import { Sun, Moon, Globe } from "lucide-react";
// import { useState } from "react";
// const languages = [
// { code: "en", name: "English", flag: "🇬🇧" },
// { code: "mk", name: "Македонски", flag: "🇲🇰" },
// { code: "sr", name: "Српски", flag: "🇷🇸" },
// ];
// export function Navbar() {
// const { theme, toggleTheme } = useTheme();
// const pathname = usePathname();
// const [showLanguages, setShowLanguages] = useState(false);
// const currentLang = pathname.split("/")[1];
// const currentPath = pathname.split("/").slice(2).join("/");
// return (
// <nav className="border-b dark:border-gray-700">
// <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
// <div className="flex justify-between h-16 items-center">
// <div className="flex items-center">
// <Link
// href={`/${currentLang}`}
// className="text-lg font-semibold hover:text-gray-600 dark:hover:text-gray-300"
// >
// Logo
// </Link>
// </div>
// <div className="flex items-center gap-4">
// <div className="relative">
// <button
// onClick={() => setShowLanguages(!showLanguages)}
// className="p-2 rounded-md hover:bg-gray-100 dark:hover:bg-gray-800"
// aria-label="Language selector"
// >
// <Globe className="h-5 w-5" />
// </button>
// {showLanguages && (
// <div className="absolute right-0 mt-2 w-48 rounded-md shadow-lg bg-white dark:bg-gray-800 ring-1 ring-black ring-opacity-5">
// <div className="py-1">
// {languages.map((lang) => (
// <Link
// key={lang.code}
// href={`/${lang.code}/${currentPath}`}
// className={`block px-4 py-2 text-sm ${
// currentLang === lang.code
// ? "bg-gray-100 dark:bg-gray-700"
// : "hover:bg-gray-100 dark:hover:bg-gray-700"
// } flex items-center gap-2`}
// onClick={() => setShowLanguages(false)}
// >
// <span className="text-base">{lang.flag}</span>
// {/* <span>{lang.name}</span> */}
// </Link>
// ))}
// </div>
// </div>
// )}
// </div>
// <button
// onClick={toggleTheme}
// className="p-2 rounded-md hover:bg-gray-100 dark:hover:bg-gray-800"
// aria-label="Toggle theme"
// >
// {theme === "light" ? (
// <Moon className="h-5 w-5" />
// ) : (
// <Sun className="h-5 w-5" />
// )}
// </button>
// </div>
// </div>
// </div>
// </nav>
// );
// }
// ngc/src/components/navbar.tsx
"use client";
import { useTheme } from "./theme-provider";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { Sun, Moon } from "lucide-react";
import { useState } from "react";
const languages = [
{ code: "en", name: "English", flag: "🇬🇧" },
{ code: "mk", name: "Македонски", flag: "🇲🇰" },
{ code: "sr", name: "Српски", flag: "🇷🇸" },
];
export function Navbar() {
const { theme, toggleTheme } = useTheme();
const pathname = usePathname();
const [showLanguages, setShowLanguages] = useState(false);
const currentLang = pathname.split("/")[1];
const currentPath = pathname.split("/").slice(2).join("/");
// Find the current language object
const currentLanguage =
languages.find((lang) => lang.code === currentLang) || languages[0];
return (
<nav className="border-b dark:border-gray-700">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex justify-between h-16 items-center">
<div className="flex items-center">
<Link
href={`/${currentLang}`}
className="text-lg font-semibold hover:text-gray-600 dark:hover:text-gray-300"
>
Logo
</Link>
</div>
<div className="flex items-center gap-4">
<div className="relative">
<button
onClick={() => setShowLanguages(!showLanguages)}
className="p-2 rounded-md hover:bg-gray-100 dark:hover:bg-gray-800 flex items-center gap-2"
aria-label="Language selector"
>
<span
className="text-xl"
role="img"
aria-label={currentLanguage.name}
>
{currentLanguage.flag}
</span>
</button>
{showLanguages && (
<div className="absolute right-0 mt-2 w-48 rounded-md shadow-lg bg-white dark:bg-gray-800 ring-1 ring-black ring-opacity-5">
<div className="py-1">
{languages.map((lang) => (
<Link
key={lang.code}
href={`/${lang.code}/${currentPath}`}
className={`block px-4 py-2 text-sm ${
currentLang === lang.code
? "bg-gray-100 dark:bg-gray-700"
: "hover:bg-gray-100 dark:hover:bg-gray-700"
} flex items-center gap-2`}
onClick={() => setShowLanguages(false)}
>
<span className="text-base">{lang.flag}</span>
{/* <span>{lang.name}</span> */}
</Link>
))}
</div>
</div>
)}
</div>
<button
onClick={toggleTheme}
className="p-2 rounded-md hover:bg-gray-100 dark:hover:bg-gray-800"
aria-label="Toggle theme"
>
{theme === "light" ? (
<Moon className="h-5 w-5" />
) : (
<Sun className="h-5 w-5" />
)}
</button>
</div>
</div>
</div>
</nav>
);
}

View File

@ -0,0 +1,47 @@
"use client";
import { createContext, useContext, useEffect, useState } from "react";
type Theme = "light" | "dark";
type ThemeProviderProps = {
children: React.ReactNode;
};
const ThemeContext = createContext<{
theme: Theme;
toggleTheme: () => void;
}>({
theme: "light",
toggleTheme: () => {},
});
export function ThemeProvider({ children }: ThemeProviderProps) {
const [theme, setTheme] = useState<Theme>("light");
useEffect(() => {
const savedTheme = localStorage.getItem("theme") as Theme;
if (savedTheme) {
setTheme(savedTheme);
document.documentElement.classList.toggle("dark", savedTheme === "dark");
} else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
setTheme("dark");
document.documentElement.classList.add("dark");
}
}, []);
const toggleTheme = () => {
const newTheme = theme === "light" ? "dark" : "light";
setTheme(newTheme);
localStorage.setItem("theme", newTheme);
document.documentElement.classList.toggle("dark");
};
return (
<ThemeContext.Provider value={{ theme, toggleTheme }}>
{children}
</ThemeContext.Provider>
);
}
export const useTheme = () => useContext(ThemeContext);

View File

@ -0,0 +1,31 @@
import { forwardRef } from "react";
import { cn } from "@/lib/utils";
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
variant?: "primary" | "secondary";
}
const Button = forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant = "primary", ...props }, ref) => {
return (
<button
className={cn(
"inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none",
{
"bg-primary text-primary-foreground hover:bg-primary/90 h-10 py-2 px-4":
variant === "primary",
"border border-input hover:bg-accent hover:text-accent-foreground h-10 py-2 px-4":
variant === "secondary",
},
className,
)}
ref={ref}
{...props}
/>
);
},
);
Button.displayName = "Button";
export { Button };

3
src/i18n/config.ts Normal file
View File

@ -0,0 +1,3 @@
export const defaultLocale = "en";
export const locales = ["en", "mk", "sr"] as const;
export type Locale = (typeof locales)[number];

19
src/i18n/request.ts Normal file
View File

@ -0,0 +1,19 @@
import { getRequestConfig } from "next-intl/server";
import { locales } from "./config";
import { requestLocale } from "@/lib/request-locale";
export default getRequestConfig(async () => {
const locale = await requestLocale();
// Validate that the incoming locale parameter is valid
if (!locales.includes(locale as any)) {
throw new Error("Invalid locale");
}
return {
messages: (await import(`../messages/${locale}.json`)).default,
timeZone: "Europe/Skopje",
now: new Date(),
locale,
};
});

30
src/lib/request-locale.ts Normal file
View File

@ -0,0 +1,30 @@
import { locales, defaultLocale } from "@/i18n/config";
import { cookies, headers } from "next/headers";
export async function requestLocale() {
// Check for locale in cookie
const cookieStore = cookies();
const localeCookie = cookieStore.get("NEXT_LOCALE");
if (localeCookie?.value && locales.includes(localeCookie.value as any)) {
return localeCookie.value;
}
// Check for locale in Accept-Language header
const headersList = headers();
const acceptLanguage = headersList.get("Accept-Language");
if (acceptLanguage) {
const preferredLocale = acceptLanguage
.split(",")[0]
.split("-")[0]
.toLowerCase();
if (locales.includes(preferredLocale as any)) {
return preferredLocale;
}
}
// Fall back to default locale
return defaultLocale;
}

6
src/lib/utils.ts Normal file
View File

@ -0,0 +1,6 @@
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

13
src/messages/en.json Normal file
View File

@ -0,0 +1,13 @@
{
"home": {
"title": "Home",
"welcome": "Welcome to our site"
},
"hero": {
"title": "Building Better",
"titleColored": "Digital Solutions",
"description": "We help ambitious businesses like yours generate more profits by building awareness, driving web traffic, connecting with customers, and growing overall sales.",
"primaryButton": "Get Started",
"secondaryButton": "Learn More"
}
}

13
src/messages/mk.json Normal file
View File

@ -0,0 +1,13 @@
{
"home": {
"title": "Почетна",
"welcome": "Добредојдовте на нашата страница"
},
"hero": {
"title": "Градиме Подобри",
"titleColored": "Дигитални Решенија",
"description": "Им помагаме на амбициозните бизниси како вашиот да генерираат повеќе профит преку градење свест, зголемување на веб сообраќај, поврзување со клиенти и целокупен раст на продажбата.",
"primaryButton": "Започнете",
"secondaryButton": "Дознајте Повеќе"
}
}

13
src/messages/sr.json Normal file
View File

@ -0,0 +1,13 @@
{
"home": {
"title": "Почетна",
"welcome": "Добродошли на нашу страницу"
},
"hero": {
"title": "Градимо Боља",
"titleColored": "Дигитална Решења",
"description": "Помажемо амбициозним предузећима попут вашег да генеришу већи профит кроз изградњу свести, повећање веб саобраћаја, повезивање са клијентима и укупан раст продаје.",
"primaryButton": "Започните",
"secondaryButton": "Сазнајте Више"
}
}

25
src/middleware.ts Normal file
View File

@ -0,0 +1,25 @@
import createMiddleware from "next-intl/middleware";
import { locales, defaultLocale } from "./i18n/config";
export default createMiddleware({
// A list of all locales that are supported
locales,
// Used when no locale matches
defaultLocale,
// If this locale is matched, pathnames work without a prefix (e.g. `/about`)
localePrefix: "always",
});
// Apply middleware to all routes except static files and api routes
export const config = {
matcher: [
// Enable a redirect to a matching locale at the root
"/",
// Set a cookie to remember the previous locale for
// all requests that have a locale prefix
"/(mk|en|sr)/:path*",
// Enable redirects that add missing locales
// (e.g. `/pathnames` -> `/en/pathnames`)
"/((?!api|_next|_vercel|.*\\..*).*)",
],
};

27
tsconfig.json Normal file
View File

@ -0,0 +1,27 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}