locale upgrade
This commit is contained in:
@@ -2,6 +2,16 @@ import { NextIntlClientProvider } from "next-intl";
|
||||
import { setRequestLocale } from "next-intl/server";
|
||||
import React from "react";
|
||||
import ConsentBanner from "../components/ConsentBanner";
|
||||
import { getLocalizedMessage } from "@/lib/i18n-loader";
|
||||
|
||||
async function loadEnhancedMessages(locale: string) {
|
||||
// Lade basis JSON Messages
|
||||
const baseMessages = (await import(`../../messages/${locale}.json`)).default;
|
||||
|
||||
// Erweitere mit Directus (wenn verfügbar)
|
||||
// Für jetzt: return base messages, Directus wird per Server Component geladen
|
||||
return baseMessages;
|
||||
}
|
||||
|
||||
export default async function LocaleLayout({
|
||||
children,
|
||||
@@ -15,7 +25,7 @@ export default async function LocaleLayout({
|
||||
setRequestLocale(locale);
|
||||
// Load messages explicitly by route locale to avoid falling back to the wrong
|
||||
// language when request-level locale detection is unavailable/misconfigured.
|
||||
const messages = (await import(`../../messages/${locale}.json`)).default;
|
||||
const messages = await loadEnhancedMessages(locale);
|
||||
|
||||
return (
|
||||
<NextIntlClientProvider locale={locale} messages={messages}>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Metadata } from "next";
|
||||
import HomePage from "../_ui/HomePage";
|
||||
import HomePageServer from "../_ui/HomePageServer";
|
||||
import { getLanguageAlternates, toAbsoluteUrl } from "@/lib/seo";
|
||||
|
||||
export async function generateMetadata({
|
||||
@@ -17,7 +17,12 @@ export async function generateMetadata({
|
||||
};
|
||||
}
|
||||
|
||||
export default function Page() {
|
||||
return <HomePage />;
|
||||
export default async function Page({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ locale: string }>;
|
||||
}) {
|
||||
const { locale } = await params;
|
||||
return <HomePageServer locale={locale} />;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,20 +32,32 @@ export default async function ProjectPage({
|
||||
where: { slug, published: true },
|
||||
include: {
|
||||
translations: {
|
||||
where: { locale },
|
||||
select: { title: true, description: true },
|
||||
select: { title: true, description: true, content: true, locale: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
if (!project) return notFound();
|
||||
|
||||
const tr = project.translations?.[0];
|
||||
const trPreferred = project.translations?.find((t) => t.locale === locale && (t?.title || t?.description));
|
||||
const trDefault = project.translations?.find(
|
||||
(t) => t.locale === project.defaultLocale && (t?.title || t?.description),
|
||||
);
|
||||
const tr = trPreferred ?? trDefault;
|
||||
const { translations: _translations, ...rest } = project;
|
||||
const localizedContent = (() => {
|
||||
if (typeof tr?.content === "string") return tr.content;
|
||||
if (tr?.content && typeof tr.content === "object" && "markdown" in tr.content) {
|
||||
const markdown = (tr.content as Record<string, unknown>).markdown;
|
||||
if (typeof markdown === "string") return markdown;
|
||||
}
|
||||
return project.content;
|
||||
})();
|
||||
const localized = {
|
||||
...rest,
|
||||
title: tr?.title ?? project.title,
|
||||
description: tr?.description ?? project.description,
|
||||
content: localizedContent,
|
||||
};
|
||||
|
||||
return <ProjectDetailClient project={localized} locale={locale} />;
|
||||
|
||||
@@ -32,14 +32,17 @@ export default async function ProjectsPage({
|
||||
orderBy: { createdAt: "desc" },
|
||||
include: {
|
||||
translations: {
|
||||
where: { locale },
|
||||
select: { title: true, description: true },
|
||||
select: { title: true, description: true, locale: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const localized = projects.map((p) => {
|
||||
const tr = p.translations?.[0];
|
||||
const trPreferred = p.translations?.find((t) => t.locale === locale && (t?.title || t?.description));
|
||||
const trDefault = p.translations?.find(
|
||||
(t) => t.locale === p.defaultLocale && (t?.title || t?.description),
|
||||
);
|
||||
const tr = trPreferred ?? trDefault;
|
||||
const { translations: _translations, ...rest } = p;
|
||||
return {
|
||||
...rest,
|
||||
|
||||
136
app/_ui/HomePageServer.tsx
Normal file
136
app/_ui/HomePageServer.tsx
Normal file
@@ -0,0 +1,136 @@
|
||||
import Header from "../components/Header.server";
|
||||
import Script from "next/script";
|
||||
import ActivityFeedClient from "./ActivityFeedClient";
|
||||
import {
|
||||
getHeroTranslations,
|
||||
getAboutTranslations,
|
||||
getProjectsTranslations,
|
||||
getContactTranslations,
|
||||
getFooterTranslations,
|
||||
} from "@/lib/translations-loader";
|
||||
import {
|
||||
HeroClient,
|
||||
AboutClient,
|
||||
ProjectsClient,
|
||||
ContactClient,
|
||||
FooterClient,
|
||||
} from "../components/ClientWrappers";
|
||||
|
||||
interface HomePageServerProps {
|
||||
locale: string;
|
||||
}
|
||||
|
||||
export default async function HomePageServer({ locale }: HomePageServerProps) {
|
||||
// Parallel laden aller Translations
|
||||
const [heroT, aboutT, projectsT, contactT, footerT] = await Promise.all([
|
||||
getHeroTranslations(locale),
|
||||
getAboutTranslations(locale),
|
||||
getProjectsTranslations(locale),
|
||||
getContactTranslations(locale),
|
||||
getFooterTranslations(locale),
|
||||
]);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen">
|
||||
<Script
|
||||
id={"structured-data"}
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: JSON.stringify({
|
||||
"@context": "https://schema.org",
|
||||
"@type": "Person",
|
||||
name: "Dennis Konkol",
|
||||
url: "https://dk0.dev",
|
||||
jobTitle: "Software Engineer",
|
||||
address: {
|
||||
"@type": "PostalAddress",
|
||||
addressLocality: "Osnabrück",
|
||||
addressCountry: "Germany",
|
||||
},
|
||||
sameAs: [
|
||||
"https://github.com/Denshooter",
|
||||
"https://linkedin.com/in/dkonkol",
|
||||
],
|
||||
}),
|
||||
}}
|
||||
/>
|
||||
<ActivityFeedClient />
|
||||
<Header locale={locale} />
|
||||
{/* Spacer to prevent navbar overlap */}
|
||||
<div className="h-24 md:h-32" aria-hidden="true"></div>
|
||||
<main className="relative">
|
||||
<HeroClient locale={locale} translations={heroT} />
|
||||
|
||||
{/* Wavy Separator 1 - Hero to About */}
|
||||
<div className="relative h-24 overflow-hidden">
|
||||
<svg
|
||||
className="absolute inset-0 w-full h-full"
|
||||
viewBox="0 0 1440 120"
|
||||
preserveAspectRatio="none"
|
||||
>
|
||||
<path
|
||||
d="M0,64 C240,96 480,32 720,64 C960,96 1200,32 1440,64 L1440,120 L0,120 Z"
|
||||
fill="url(#gradient1)"
|
||||
/>
|
||||
<defs>
|
||||
<linearGradient id="gradient1" x1="0%" y1="0%" x2="100%" y2="0%">
|
||||
<stop offset="0%" stopColor="#BAE6FD" stopOpacity="0.4" />
|
||||
<stop offset="50%" stopColor="#DDD6FE" stopOpacity="0.4" />
|
||||
<stop offset="100%" stopColor="#FBCFE8" stopOpacity="0.4" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<AboutClient locale={locale} translations={aboutT} />
|
||||
|
||||
{/* Wavy Separator 2 - About to Projects */}
|
||||
<div className="relative h-24 overflow-hidden">
|
||||
<svg
|
||||
className="absolute inset-0 w-full h-full"
|
||||
viewBox="0 0 1440 120"
|
||||
preserveAspectRatio="none"
|
||||
>
|
||||
<path
|
||||
d="M0,64 C360,96 720,32 1080,64 C1200,96 1320,32 1440,64 L1440,0 L0,0 Z"
|
||||
fill="url(#gradient2)"
|
||||
/>
|
||||
<defs>
|
||||
<linearGradient id="gradient2" x1="0%" y1="0%" x2="100%" y2="0%">
|
||||
<stop offset="0%" stopColor="#A7F3D0" stopOpacity="0.3" />
|
||||
<stop offset="50%" stopColor="#BFDBFE" stopOpacity="0.3" />
|
||||
<stop offset="100%" stopColor="#DDD6FE" stopOpacity="0.3" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<ProjectsClient locale={locale} translations={projectsT} />
|
||||
|
||||
{/* Wavy Separator 3 - Projects to Contact */}
|
||||
<div className="relative h-24 overflow-hidden">
|
||||
<svg
|
||||
className="absolute inset-0 w-full h-full"
|
||||
viewBox="0 0 1440 120"
|
||||
preserveAspectRatio="none"
|
||||
>
|
||||
<path
|
||||
d="M0,32 C240,64 480,0 720,32 C960,64 1200,0 1440,32 L1440,120 L0,120 Z"
|
||||
fill="url(#gradient3)"
|
||||
/>
|
||||
<defs>
|
||||
<linearGradient id="gradient3" x1="0%" y1="0%" x2="100%" y2="0%">
|
||||
<stop offset="0%" stopColor="#FDE68A" stopOpacity="0.3" />
|
||||
<stop offset="50%" stopColor="#FCA5A5" stopOpacity="0.3" />
|
||||
<stop offset="100%" stopColor="#C4B5FD" stopOpacity="0.3" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<ContactClient locale={locale} translations={contactT} />
|
||||
</main>
|
||||
<FooterClient locale={locale} translations={footerT} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { ExternalLink, Calendar, ArrowLeft, Github as GithubIcon, Share2 } from
|
||||
import Link from "next/link";
|
||||
import { useEffect } from "react";
|
||||
import ReactMarkdown from "react-markdown";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
export type ProjectDetailData = {
|
||||
id: number;
|
||||
@@ -28,6 +29,10 @@ export default function ProjectDetailClient({
|
||||
project: ProjectDetailData;
|
||||
locale: string;
|
||||
}) {
|
||||
const tCommon = useTranslations("common");
|
||||
const tDetail = useTranslations("projects.detail");
|
||||
const tShared = useTranslations("projects.shared");
|
||||
|
||||
// Track page view (non-blocking)
|
||||
useEffect(() => {
|
||||
try {
|
||||
@@ -64,7 +69,7 @@ export default function ProjectDetailClient({
|
||||
className="inline-flex items-center space-x-2 text-stone-500 hover:text-stone-900 transition-colors group"
|
||||
>
|
||||
<ArrowLeft size={20} className="group-hover:-translate-x-1 transition-transform" />
|
||||
<span className="font-medium">Back to Projects</span>
|
||||
<span className="font-medium">{tCommon("backToProjects")}</span>
|
||||
</Link>
|
||||
</motion.div>
|
||||
|
||||
@@ -82,7 +87,7 @@ export default function ProjectDetailClient({
|
||||
<div className="flex gap-2 shrink-0 pt-2">
|
||||
{project.featured && (
|
||||
<span className="px-4 py-1.5 bg-stone-900 text-stone-50 text-xs font-bold rounded-full shadow-sm">
|
||||
Featured
|
||||
{tShared("featured")}
|
||||
</span>
|
||||
)}
|
||||
<span className="px-4 py-1.5 bg-white border border-stone-200 text-stone-600 text-xs font-medium rounded-full shadow-sm">
|
||||
@@ -99,7 +104,7 @@ export default function ProjectDetailClient({
|
||||
<div className="flex items-center space-x-2">
|
||||
<Calendar size={18} />
|
||||
<span className="font-mono">
|
||||
{new Date(project.date).toLocaleDateString(undefined, {
|
||||
{new Date(project.date).toLocaleDateString(locale || undefined, {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
@@ -183,7 +188,7 @@ export default function ProjectDetailClient({
|
||||
<div className="bg-white/50 backdrop-blur-xl border border-white/60 p-6 rounded-2xl shadow-sm sticky top-32">
|
||||
<h3 className="font-bold text-stone-900 mb-4 flex items-center gap-2">
|
||||
<Share2 size={18} />
|
||||
Project Links
|
||||
{tDetail("links")}
|
||||
</h3>
|
||||
<div className="space-y-3">
|
||||
{project.live && project.live.trim() && project.live !== "#" ? (
|
||||
@@ -193,12 +198,12 @@ export default function ProjectDetailClient({
|
||||
rel="noopener noreferrer"
|
||||
className="flex items-center justify-between w-full px-4 py-3 bg-stone-900 text-stone-50 rounded-xl font-medium hover:bg-stone-800 hover:scale-[1.02] transition-all shadow-md group"
|
||||
>
|
||||
<span>Live Demo</span>
|
||||
<span>{tDetail("liveDemo")}</span>
|
||||
<ExternalLink size={18} className="group-hover:translate-x-1 transition-transform" />
|
||||
</a>
|
||||
) : (
|
||||
<div className="px-4 py-3 bg-stone-100 text-stone-400 rounded-xl font-medium text-sm text-center border border-stone-200 cursor-not-allowed">
|
||||
Live demo not available
|
||||
{tDetail("liveNotAvailable")}
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -209,14 +214,14 @@ export default function ProjectDetailClient({
|
||||
rel="noopener noreferrer"
|
||||
className="flex items-center justify-between w-full px-4 py-3 bg-white border border-stone-200 text-stone-700 rounded-xl font-medium hover:bg-stone-50 hover:text-stone-900 hover:border-stone-300 transition-all shadow-sm group"
|
||||
>
|
||||
<span>View Source</span>
|
||||
<span>{tDetail("viewSource")}</span>
|
||||
<GithubIcon size={18} className="group-hover:rotate-12 transition-transform" />
|
||||
</a>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="mt-8 pt-6 border-t border-stone-100">
|
||||
<h4 className="text-xs font-bold text-stone-400 uppercase tracking-wider mb-3">Tech Stack</h4>
|
||||
<h4 className="text-xs font-bold text-stone-400 uppercase tracking-wider mb-3">{tDetail("techStack")}</h4>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{project.tags.map((tag) => (
|
||||
<span
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useEffect, useMemo, useState } from "react";
|
||||
import { motion } from "framer-motion";
|
||||
import { ExternalLink, Github, Calendar, ArrowLeft, Search } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
export type ProjectListItem = {
|
||||
id: number;
|
||||
@@ -27,7 +28,11 @@ export default function ProjectsPageClient({
|
||||
projects: ProjectListItem[];
|
||||
locale: string;
|
||||
}) {
|
||||
const [selectedCategory, setSelectedCategory] = useState("All");
|
||||
const tCommon = useTranslations("common");
|
||||
const tList = useTranslations("projects.list");
|
||||
const tShared = useTranslations("projects.shared");
|
||||
|
||||
const [selectedCategory, setSelectedCategory] = useState("all");
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
@@ -37,13 +42,13 @@ export default function ProjectsPageClient({
|
||||
|
||||
const categories = useMemo(() => {
|
||||
const unique = Array.from(new Set(projects.map((p) => p.category))).filter(Boolean);
|
||||
return ["All", ...unique];
|
||||
return ["all", ...unique];
|
||||
}, [projects]);
|
||||
|
||||
const filteredProjects = useMemo(() => {
|
||||
let result = projects;
|
||||
|
||||
if (selectedCategory !== "All") {
|
||||
if (selectedCategory !== "all") {
|
||||
result = result.filter((project) => project.category === selectedCategory);
|
||||
}
|
||||
|
||||
@@ -77,16 +82,13 @@ export default function ProjectsPageClient({
|
||||
className="inline-flex items-center space-x-2 text-stone-500 hover:text-stone-800 transition-colors mb-8 group"
|
||||
>
|
||||
<ArrowLeft size={20} className="group-hover:-translate-x-1 transition-transform" />
|
||||
<span>Back to Home</span>
|
||||
<span>{tCommon("backToHome")}</span>
|
||||
</Link>
|
||||
|
||||
<h1 className="text-5xl md:text-6xl font-black font-sans mb-6 text-stone-900 tracking-tight">
|
||||
My Projects
|
||||
{tList("title")}
|
||||
</h1>
|
||||
<p className="text-xl text-stone-600 max-w-3xl font-light leading-relaxed">
|
||||
Explore my portfolio of projects, from web applications to mobile apps. Each project showcases different
|
||||
skills and technologies.
|
||||
</p>
|
||||
<p className="text-xl text-stone-600 max-w-3xl font-light leading-relaxed">{tList("intro")}</p>
|
||||
</motion.div>
|
||||
|
||||
{/* Filters & Search */}
|
||||
@@ -108,7 +110,7 @@ export default function ProjectsPageClient({
|
||||
: "bg-white text-stone-600 border-stone-200 hover:bg-stone-50 hover:border-stone-300"
|
||||
}`}
|
||||
>
|
||||
{category}
|
||||
{category === "all" ? tList("all") : category}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
@@ -118,7 +120,7 @@ export default function ProjectsPageClient({
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 text-stone-400" size={18} />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search projects..."
|
||||
placeholder={tList("searchPlaceholder")}
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="w-full pl-10 pr-4 py-2 bg-white border border-stone-200 rounded-full text-stone-800 placeholder:text-stone-400 focus:outline-none focus:ring-2 focus:ring-stone-200 focus:border-stone-400 transition-all"
|
||||
@@ -172,7 +174,7 @@ export default function ProjectsPageClient({
|
||||
{project.featured && (
|
||||
<div className="absolute top-3 left-3 z-20">
|
||||
<div className="px-3 py-1 bg-[#292524]/80 backdrop-blur-md text-[#fdfcf8] text-[10px] font-bold uppercase tracking-widest rounded-full shadow-sm border border-white/10">
|
||||
Featured
|
||||
{tShared("featured")}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@@ -273,15 +275,15 @@ export default function ProjectsPageClient({
|
||||
|
||||
{filteredProjects.length === 0 && (
|
||||
<div className="text-center py-20">
|
||||
<p className="text-stone-500 text-lg">No projects found matching your criteria.</p>
|
||||
<p className="text-stone-500 text-lg">{tList("noResults")}</p>
|
||||
<button
|
||||
onClick={() => {
|
||||
setSelectedCategory("All");
|
||||
setSelectedCategory("all");
|
||||
setSearchQuery("");
|
||||
}}
|
||||
className="mt-4 text-stone-800 font-medium hover:underline"
|
||||
>
|
||||
Clear filters
|
||||
{tList("clearFilters")}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
79
app/api/i18n/[namespace]/route.ts
Normal file
79
app/api/i18n/[namespace]/route.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getLocalizedMessage } from '@/lib/i18n-loader';
|
||||
import enMessages from '@/messages/en.json';
|
||||
import deMessages from '@/messages/de.json';
|
||||
|
||||
// Cache für 5 Minuten
|
||||
export const revalidate = 300;
|
||||
|
||||
const messagesMap = { en: enMessages, de: deMessages };
|
||||
|
||||
/**
|
||||
* GET /api/i18n/[namespace]?locale=en
|
||||
* Lädt alle Keys eines Namespace aus Directus oder JSON
|
||||
*/
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
{ params }: { params: { namespace: string } }
|
||||
) {
|
||||
const namespace = params.namespace;
|
||||
const locale = req.nextUrl.searchParams.get('locale') || 'en';
|
||||
|
||||
// Normalize locale (de-DE -> de)
|
||||
const normalizedLocale = locale.startsWith('de') ? 'de' : 'en';
|
||||
|
||||
try {
|
||||
// Hole alle Keys aus JSON für diesen Namespace
|
||||
const jsonData = messagesMap[normalizedLocale as 'en' | 'de'];
|
||||
const namespaceData = getNestedValue(jsonData, namespace);
|
||||
|
||||
if (!namespaceData || typeof namespaceData !== 'object') {
|
||||
return NextResponse.json({}, { status: 200 });
|
||||
}
|
||||
|
||||
// Flatten das Objekt zu flachen Keys
|
||||
const flatKeys = flattenObject(namespaceData);
|
||||
|
||||
// Lade jeden Key aus Directus (mit Fallback auf JSON)
|
||||
const result: Record<string, string> = {};
|
||||
|
||||
await Promise.all(
|
||||
Object.entries(flatKeys).map(async ([key, jsonValue]) => {
|
||||
const fullKey = `${namespace}.${key}`;
|
||||
const value = await getLocalizedMessage(fullKey, locale);
|
||||
result[key] = value || String(jsonValue);
|
||||
})
|
||||
);
|
||||
|
||||
return NextResponse.json(result, {
|
||||
headers: {
|
||||
'Cache-Control': 'public, s-maxage=300, stale-while-revalidate=600',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('i18n API error:', error);
|
||||
return NextResponse.json({ error: 'Failed to load translations' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
// Helper: Holt verschachtelte Werte aus Objekt
|
||||
function getNestedValue(obj: any, path: string): any {
|
||||
return path.split('.').reduce((current, key) => current?.[key], obj);
|
||||
}
|
||||
|
||||
// Helper: Flatten verschachteltes Objekt zu flachen Keys
|
||||
function flattenObject(obj: any, prefix = ''): Record<string, string> {
|
||||
const result: Record<string, string> = {};
|
||||
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
const newKey = prefix ? `${prefix}.${key}` : key;
|
||||
|
||||
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
||||
Object.assign(result, flattenObject(value, newKey));
|
||||
} else {
|
||||
result[newKey] = String(value);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
94
app/api/messages/route.ts
Normal file
94
app/api/messages/route.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getLocalizedMessage } from '@/lib/i18n-loader';
|
||||
import enMessages from '@/messages/en.json';
|
||||
import deMessages from '@/messages/de.json';
|
||||
|
||||
// Cache für 5 Minuten
|
||||
export const revalidate = 300;
|
||||
|
||||
const messagesMap = { en: enMessages, de: deMessages };
|
||||
|
||||
/**
|
||||
* GET /api/messages?locale=en
|
||||
* Lädt ALLE Messages aus Directus + JSON Fallback
|
||||
* Wird von next-intl als messages source verwendet
|
||||
*/
|
||||
export async function GET(req: NextRequest) {
|
||||
const locale = req.nextUrl.searchParams.get('locale') || 'en';
|
||||
|
||||
// Normalize locale (de-DE -> de)
|
||||
const normalizedLocale = locale.startsWith('de') ? 'de' : 'en';
|
||||
|
||||
try {
|
||||
// Starte mit JSON als Basis
|
||||
const jsonMessages = messagesMap[normalizedLocale as 'en' | 'de'];
|
||||
|
||||
// Clone das Objekt
|
||||
const messages = JSON.parse(JSON.stringify(jsonMessages));
|
||||
|
||||
// Flatten alle Keys
|
||||
const allKeys = getAllKeys(messages);
|
||||
|
||||
// Lade jeden Key aus Directus (überschreibt JSON wenn vorhanden)
|
||||
await Promise.all(
|
||||
allKeys.map(async (key) => {
|
||||
try {
|
||||
const value = await getLocalizedMessage(key, locale);
|
||||
if (value && value !== key) {
|
||||
// Überschreibe den Wert im messages Objekt
|
||||
setNestedValue(messages, key, value);
|
||||
}
|
||||
} catch (error) {
|
||||
// Fallback auf JSON Wert (schon vorhanden)
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
return NextResponse.json(messages, {
|
||||
headers: {
|
||||
'Cache-Control': 'public, s-maxage=300, stale-while-revalidate=600',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Messages API error:', error);
|
||||
// Fallback: Return nur JSON messages
|
||||
return NextResponse.json(messagesMap[normalizedLocale as 'en' | 'de'], {
|
||||
headers: {
|
||||
'Cache-Control': 'public, s-maxage=60',
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Helper: Sammle alle Keys aus verschachteltem Objekt
|
||||
function getAllKeys(obj: any, prefix = ''): string[] {
|
||||
const keys: string[] = [];
|
||||
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
const fullKey = prefix ? `${prefix}.${key}` : key;
|
||||
|
||||
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
||||
keys.push(...getAllKeys(value, fullKey));
|
||||
} else {
|
||||
keys.push(fullKey);
|
||||
}
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
// Helper: Setze Wert in verschachteltem Objekt
|
||||
function setNestedValue(obj: any, path: string, value: any) {
|
||||
const keys = path.split('.');
|
||||
const lastKey = keys.pop()!;
|
||||
|
||||
let current = obj;
|
||||
for (const key of keys) {
|
||||
if (!(key in current)) {
|
||||
current[key] = {};
|
||||
}
|
||||
current = current[key];
|
||||
}
|
||||
|
||||
current[lastKey] = value;
|
||||
}
|
||||
@@ -42,11 +42,13 @@ export async function PUT(
|
||||
locale?: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
content?: string;
|
||||
};
|
||||
|
||||
const locale = body.locale || "en";
|
||||
const title = body.title?.trim();
|
||||
const description = body.description?.trim();
|
||||
const content = typeof body.content === "string" ? body.content.trim() : undefined;
|
||||
|
||||
if (!title || !description) {
|
||||
return NextResponse.json({ error: "title and description are required" }, { status: 400 });
|
||||
@@ -59,10 +61,12 @@ export async function PUT(
|
||||
locale,
|
||||
title,
|
||||
description,
|
||||
content: content ?? null,
|
||||
},
|
||||
update: {
|
||||
title,
|
||||
description,
|
||||
content: content ?? null,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
111
app/components/ClientWrappers.tsx
Normal file
111
app/components/ClientWrappers.tsx
Normal file
@@ -0,0 +1,111 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* Transitional Wrapper für bestehende Components
|
||||
* Nutzt direkt JSON Messages statt komplexe Translation-Loader
|
||||
*/
|
||||
|
||||
import { NextIntlClientProvider } from 'next-intl';
|
||||
import Hero from './Hero';
|
||||
import About from './About';
|
||||
import Projects from './Projects';
|
||||
import Contact from './Contact';
|
||||
import Footer from './Footer';
|
||||
import type {
|
||||
HeroTranslations,
|
||||
AboutTranslations,
|
||||
ProjectsTranslations,
|
||||
ContactTranslations,
|
||||
FooterTranslations,
|
||||
} from '@/types/translations';
|
||||
import enMessages from '@/messages/en.json';
|
||||
import deMessages from '@/messages/de.json';
|
||||
|
||||
const messageMap = { en: enMessages, de: deMessages };
|
||||
|
||||
function getNormalizedLocale(locale: string): 'en' | 'de' {
|
||||
return locale.startsWith('de') ? 'de' : 'en';
|
||||
}
|
||||
|
||||
export function HeroClient({ locale, translations }: { locale: string; translations: HeroTranslations }) {
|
||||
const normalLocale = getNormalizedLocale(locale);
|
||||
const baseMessages = messageMap[normalLocale];
|
||||
|
||||
const messages = {
|
||||
home: {
|
||||
hero: baseMessages.home.hero
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<NextIntlClientProvider locale={locale} messages={messages}>
|
||||
<Hero />
|
||||
</NextIntlClientProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export function AboutClient({ locale, translations }: { locale: string; translations: AboutTranslations }) {
|
||||
const normalLocale = getNormalizedLocale(locale);
|
||||
const baseMessages = messageMap[normalLocale];
|
||||
|
||||
const messages = {
|
||||
home: {
|
||||
about: baseMessages.home.about
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<NextIntlClientProvider locale={locale} messages={messages}>
|
||||
<About />
|
||||
</NextIntlClientProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export function ProjectsClient({ locale, translations }: { locale: string; translations: ProjectsTranslations }) {
|
||||
const normalLocale = getNormalizedLocale(locale);
|
||||
const baseMessages = messageMap[normalLocale];
|
||||
|
||||
const messages = {
|
||||
home: {
|
||||
projects: baseMessages.home.projects
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<NextIntlClientProvider locale={locale} messages={messages}>
|
||||
<Projects />
|
||||
</NextIntlClientProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export function ContactClient({ locale, translations }: { locale: string; translations: ContactTranslations }) {
|
||||
const normalLocale = getNormalizedLocale(locale);
|
||||
const baseMessages = messageMap[normalLocale];
|
||||
|
||||
const messages = {
|
||||
home: {
|
||||
contact: baseMessages.home.contact
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<NextIntlClientProvider locale={locale} messages={messages}>
|
||||
<Contact />
|
||||
</NextIntlClientProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export function FooterClient({ locale, translations }: { locale: string; translations: FooterTranslations }) {
|
||||
const normalLocale = getNormalizedLocale(locale);
|
||||
const baseMessages = messageMap[normalLocale];
|
||||
|
||||
const messages = {
|
||||
footer: baseMessages.footer
|
||||
};
|
||||
|
||||
return (
|
||||
<NextIntlClientProvider locale={locale} messages={messages}>
|
||||
<Footer />
|
||||
</NextIntlClientProvider>
|
||||
);
|
||||
}
|
||||
12
app/components/Header.server.tsx
Normal file
12
app/components/Header.server.tsx
Normal file
@@ -0,0 +1,12 @@
|
||||
import { getNavTranslations } from '@/lib/translations-loader';
|
||||
import HeaderClient from './HeaderClient';
|
||||
|
||||
interface HeaderProps {
|
||||
locale: string;
|
||||
}
|
||||
|
||||
export default async function Header({ locale }: HeaderProps) {
|
||||
const translations = await getNavTranslations(locale);
|
||||
|
||||
return <HeaderClient locale={locale} translations={translations} />;
|
||||
}
|
||||
249
app/components/HeaderClient.tsx
Normal file
249
app/components/HeaderClient.tsx
Normal file
@@ -0,0 +1,249 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { motion, AnimatePresence } from "framer-motion";
|
||||
import { Menu, X, Mail } from "lucide-react";
|
||||
import { SiGithub, SiLinkedin } from "react-icons/si";
|
||||
import Link from "next/link";
|
||||
import { usePathname, useSearchParams } from "next/navigation";
|
||||
import type { NavTranslations } from "@/types/translations";
|
||||
|
||||
interface HeaderClientProps {
|
||||
locale: string;
|
||||
translations: NavTranslations;
|
||||
}
|
||||
|
||||
export default function HeaderClient({ locale, translations }: HeaderClientProps) {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [scrolled, setScrolled] = useState(false);
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const isHome = pathname === `/${locale}` || pathname === `/${locale}/`;
|
||||
|
||||
useEffect(() => {
|
||||
const handleScroll = () => {
|
||||
setScrolled(window.scrollY > 50);
|
||||
};
|
||||
|
||||
window.addEventListener("scroll", handleScroll);
|
||||
return () => window.removeEventListener("scroll", handleScroll);
|
||||
}, []);
|
||||
|
||||
const navItems = [
|
||||
{ name: translations.home, href: `/${locale}` },
|
||||
{ name: translations.about, href: isHome ? "#about" : `/${locale}#about` },
|
||||
{ name: translations.projects, href: isHome ? "#projects" : `/${locale}/projects` },
|
||||
{ name: translations.contact, href: isHome ? "#contact" : `/${locale}#contact` },
|
||||
];
|
||||
|
||||
const socialLinks = [
|
||||
{ icon: SiGithub, href: "https://github.com/Denshooter", label: "GitHub" },
|
||||
{
|
||||
icon: SiLinkedin,
|
||||
href: "https://linkedin.com/in/dkonkol",
|
||||
label: "LinkedIn",
|
||||
},
|
||||
{ icon: Mail, href: "mailto:contact@dk0.dev", label: "Email" },
|
||||
];
|
||||
|
||||
const pathWithoutLocale = pathname.replace(new RegExp(`^/${locale}`), "") || "";
|
||||
const qs = searchParams.toString();
|
||||
const query = qs ? `?${qs}` : "";
|
||||
const enHref = `/en${pathWithoutLocale}${query}`;
|
||||
const deHref = `/de${pathWithoutLocale}${query}`;
|
||||
|
||||
return (
|
||||
<>
|
||||
<motion.header
|
||||
initial={false}
|
||||
animate={{ y: 0, opacity: 1 }}
|
||||
transition={{ duration: 0.3, ease: "easeOut" }}
|
||||
className="fixed top-6 left-0 right-0 z-50 flex justify-center px-4 pointer-events-none"
|
||||
>
|
||||
<div
|
||||
className={`pointer-events-auto transition-all duration-500 ease-out ${
|
||||
scrolled ? "w-full max-w-5xl" : "w-full max-w-7xl"
|
||||
}`}
|
||||
>
|
||||
<motion.div
|
||||
initial={false}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ duration: 0.3, ease: "easeOut" }}
|
||||
className={`backdrop-blur-xl transition-all duration-500 flex justify-between items-center ${
|
||||
scrolled
|
||||
? "bg-white/95 border border-stone-200/50 shadow-[0_8px_30px_rgba(0,0,0,0.12)] rounded-full px-6 py-3"
|
||||
: "bg-white/85 border border-stone-200/30 shadow-[0_4px_24px_rgba(0,0,0,0.08)] px-4 py-4 rounded-full"
|
||||
}`}
|
||||
>
|
||||
<motion.div
|
||||
whileHover={{ scale: 1.05 }}
|
||||
className="flex items-center space-x-2"
|
||||
>
|
||||
<Link
|
||||
href={`/${locale}`}
|
||||
className="text-2xl font-black font-sans text-stone-900 tracking-tighter liquid-hover flex items-center"
|
||||
>
|
||||
dk<span className="text-red-500">0</span>
|
||||
</Link>
|
||||
</motion.div>
|
||||
|
||||
<nav className="hidden md:flex items-center space-x-8">
|
||||
{navItems.map((item) => (
|
||||
<motion.div
|
||||
key={item.name}
|
||||
whileHover={{ y: -2 }}
|
||||
whileTap={{ scale: 0.95 }}
|
||||
>
|
||||
<Link
|
||||
href={item.href}
|
||||
className="text-stone-700 hover:text-stone-900 font-medium transition-colors relative liquid-hover"
|
||||
>
|
||||
{item.name}
|
||||
</Link>
|
||||
</motion.div>
|
||||
))}
|
||||
|
||||
{/* Language Switcher */}
|
||||
<div className="flex items-center space-x-2 ml-4 pl-4 border-l border-stone-300">
|
||||
<Link
|
||||
href={enHref}
|
||||
className={`px-2 py-1 text-sm font-medium rounded transition-all ${
|
||||
locale === "en"
|
||||
? "bg-stone-900 text-white"
|
||||
: "text-stone-600 hover:text-stone-900 hover:bg-stone-100"
|
||||
}`}
|
||||
>
|
||||
EN
|
||||
</Link>
|
||||
<Link
|
||||
href={deHref}
|
||||
className={`px-2 py-1 text-sm font-medium rounded transition-all ${
|
||||
locale === "de"
|
||||
? "bg-stone-900 text-white"
|
||||
: "text-stone-600 hover:text-stone-900 hover:bg-stone-100"
|
||||
}`}
|
||||
>
|
||||
DE
|
||||
</Link>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<motion.button
|
||||
whileHover={{ scale: 1.05, rotate: 90 }}
|
||||
whileTap={{ scale: 0.95 }}
|
||||
onClick={() => setIsOpen(!isOpen)}
|
||||
className="md:hidden p-2 rounded-lg bg-stone-100 hover:bg-stone-200 text-stone-700 transition-colors"
|
||||
aria-label="Toggle menu"
|
||||
>
|
||||
{isOpen ? <X size={24} /> : <Menu size={24} />}
|
||||
</motion.button>
|
||||
</motion.div>
|
||||
</div>
|
||||
</motion.header>
|
||||
|
||||
<AnimatePresence>
|
||||
{isOpen && (
|
||||
<motion.div
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
transition={{ duration: 0.2 }}
|
||||
className="fixed inset-0 bg-stone-900/50 backdrop-blur-sm z-40 md:hidden"
|
||||
onClick={() => setIsOpen(false)}
|
||||
/>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
|
||||
<AnimatePresence>
|
||||
{isOpen && (
|
||||
<motion.div
|
||||
initial={{ x: "100%", opacity: 0 }}
|
||||
animate={{ x: 0, opacity: 1 }}
|
||||
exit={{ x: "100%", opacity: 0 }}
|
||||
transition={{ type: "spring", damping: 30, stiffness: 300 }}
|
||||
className="fixed right-0 top-0 h-full w-80 bg-white shadow-2xl z-50 md:hidden overflow-y-auto"
|
||||
>
|
||||
<div className="p-6">
|
||||
<div className="flex justify-between items-center mb-8">
|
||||
<Link
|
||||
href={`/${locale}`}
|
||||
className="text-2xl font-black text-stone-900"
|
||||
onClick={() => setIsOpen(false)}
|
||||
>
|
||||
dk<span className="text-red-500">0</span>
|
||||
</Link>
|
||||
<button
|
||||
onClick={() => setIsOpen(false)}
|
||||
className="p-2 rounded-lg bg-stone-100 hover:bg-stone-200 text-stone-700"
|
||||
aria-label="Close menu"
|
||||
>
|
||||
<X size={24} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<nav className="space-y-2">
|
||||
{navItems.map((item) => (
|
||||
<Link
|
||||
key={item.name}
|
||||
href={item.href}
|
||||
onClick={() => setIsOpen(false)}
|
||||
className="block px-4 py-3 text-stone-700 hover:bg-stone-50 rounded-lg font-medium transition-colors"
|
||||
>
|
||||
{item.name}
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
{/* Language Switcher Mobile */}
|
||||
<div className="flex gap-2 mt-6 pt-6 border-t border-stone-200">
|
||||
<Link
|
||||
href={enHref}
|
||||
onClick={() => setIsOpen(false)}
|
||||
className={`flex-1 px-4 py-2 text-center font-medium rounded-lg transition-all ${
|
||||
locale === "en"
|
||||
? "bg-stone-900 text-white"
|
||||
: "bg-stone-100 text-stone-600 hover:bg-stone-200"
|
||||
}`}
|
||||
>
|
||||
EN
|
||||
</Link>
|
||||
<Link
|
||||
href={deHref}
|
||||
onClick={() => setIsOpen(false)}
|
||||
className={`flex-1 px-4 py-2 text-center font-medium rounded-lg transition-all ${
|
||||
locale === "de"
|
||||
? "bg-stone-900 text-white"
|
||||
: "bg-stone-100 text-stone-600 hover:bg-stone-200"
|
||||
}`}
|
||||
>
|
||||
DE
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div className="mt-8 pt-6 border-t border-stone-200">
|
||||
<div className="flex justify-center space-x-6">
|
||||
{socialLinks.map((link) => {
|
||||
const Icon = link.icon;
|
||||
return (
|
||||
<a
|
||||
key={link.label}
|
||||
href={link.href}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="p-3 rounded-lg bg-stone-100 hover:bg-stone-900 hover:text-white text-stone-700 transition-all"
|
||||
aria-label={link.label}
|
||||
>
|
||||
<Icon size={20} />
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
)}
|
||||
</AnimatePresence>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -60,7 +60,7 @@ function EditorPageContent() {
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const [isCreating, setIsCreating] = useState(!projectId);
|
||||
const [editLocale, setEditLocale] = useState(initialLocale);
|
||||
const [baseTexts, setBaseTexts] = useState<{ title: string; description: string } | null>(null);
|
||||
const [baseTexts, setBaseTexts] = useState<{ title: string; description: string; content: string } | null>(null);
|
||||
const [showPreview, setShowPreview] = useState(false);
|
||||
const [_isTyping, setIsTyping] = useState(false);
|
||||
const [history, setHistory] = useState<typeof formData[]>([]);
|
||||
@@ -96,6 +96,7 @@ function EditorPageContent() {
|
||||
setBaseTexts({
|
||||
title: foundProject.title || "",
|
||||
description: foundProject.description || "",
|
||||
content: foundProject.content || "",
|
||||
});
|
||||
const initialData = {
|
||||
title: foundProject.title || "",
|
||||
@@ -145,19 +146,64 @@ function EditorPageContent() {
|
||||
});
|
||||
if (!response.ok) return;
|
||||
const data = await response.json();
|
||||
const tr = data.translation as { title?: string; description?: string } | null;
|
||||
if (tr?.title && tr?.description) {
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
title: tr.title || prev.title,
|
||||
description: tr.description || prev.description,
|
||||
}));
|
||||
const tr = data.translation as { title?: string; description?: string; content?: unknown } | null;
|
||||
const translatedContent = (() => {
|
||||
if (typeof tr?.content === "string") return tr.content;
|
||||
if (tr?.content && typeof tr.content === "object" && "markdown" in tr.content) {
|
||||
const markdown = (tr.content as Record<string, unknown>).markdown;
|
||||
if (typeof markdown === "string") return markdown;
|
||||
}
|
||||
return null;
|
||||
})();
|
||||
|
||||
if (tr?.title || tr?.description || translatedContent !== null) {
|
||||
setFormData((prev) => {
|
||||
const next = {
|
||||
...prev,
|
||||
title: tr?.title || prev.title,
|
||||
description: tr?.description || prev.description,
|
||||
content: translatedContent ?? prev.content,
|
||||
};
|
||||
return next;
|
||||
});
|
||||
if (translatedContent !== null) {
|
||||
shouldUpdateContentRef.current = true;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// ignore translation load failures
|
||||
}
|
||||
}, []);
|
||||
|
||||
const switchLocale = useCallback(
|
||||
(next: string) => {
|
||||
setEditLocale(next);
|
||||
if (projectId) {
|
||||
const newUrl = `/editor?id=${projectId}&locale=${encodeURIComponent(next)}`;
|
||||
window.history.replaceState({}, "", newUrl);
|
||||
}
|
||||
|
||||
if (next === "en" && baseTexts) {
|
||||
setFormData((prev) => {
|
||||
const nextData = {
|
||||
...prev,
|
||||
title: baseTexts.title,
|
||||
description: baseTexts.description,
|
||||
content: baseTexts.content,
|
||||
};
|
||||
return nextData;
|
||||
});
|
||||
shouldUpdateContentRef.current = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (projectId) {
|
||||
loadTranslation(projectId, next);
|
||||
}
|
||||
},
|
||||
[projectId, baseTexts, loadTranslation],
|
||||
);
|
||||
|
||||
// Check authentication and load project
|
||||
useEffect(() => {
|
||||
const init = async () => {
|
||||
@@ -188,6 +234,7 @@ function EditorPageContent() {
|
||||
live: "",
|
||||
image: "",
|
||||
};
|
||||
setBaseTexts({ title: "", description: "", content: "" });
|
||||
setFormData(initialData);
|
||||
setOriginalFormData(initialData);
|
||||
setHistory([initialData]);
|
||||
@@ -240,11 +287,12 @@ function EditorPageContent() {
|
||||
const saveTitle = editLocale === "en" ? formData.title.trim() : (baseTexts?.title || formData.title.trim());
|
||||
const saveDescription =
|
||||
editLocale === "en" ? formData.description.trim() : (baseTexts?.description || formData.description.trim());
|
||||
const saveContent = editLocale === "en" ? formData.content.trim() : (baseTexts?.content || formData.content.trim());
|
||||
|
||||
const saveData = {
|
||||
title: saveTitle,
|
||||
description: saveDescription,
|
||||
content: formData.content.trim(),
|
||||
content: saveContent,
|
||||
category: formData.category,
|
||||
tags: formData.tags,
|
||||
github: formData.github.trim() || null,
|
||||
@@ -302,12 +350,21 @@ function EditorPageContent() {
|
||||
locale: editLocale,
|
||||
title: formData.title.trim(),
|
||||
description: formData.description.trim(),
|
||||
content: formData.content.trim(),
|
||||
}),
|
||||
});
|
||||
} catch {
|
||||
// ignore translation save failures
|
||||
}
|
||||
}
|
||||
|
||||
if (editLocale === "en") {
|
||||
setBaseTexts({
|
||||
title: savedProject.title || "",
|
||||
description: savedProject.description || "",
|
||||
content: savedProject.content || "",
|
||||
});
|
||||
}
|
||||
|
||||
// Update project ID if it was a new project
|
||||
if (!projectId && savedProject.id) {
|
||||
@@ -706,27 +763,40 @@ function EditorPageContent() {
|
||||
<label className="block text-sm font-medium text-stone-300 mb-2">
|
||||
Language
|
||||
</label>
|
||||
<div className="custom-select">
|
||||
<select
|
||||
value={editLocale}
|
||||
onChange={(e) => {
|
||||
const next = e.target.value;
|
||||
setEditLocale(next);
|
||||
if (projectId) {
|
||||
// Update URL for deep-linking and reload translation
|
||||
const newUrl = `/editor?id=${projectId}&locale=${encodeURIComponent(next)}`;
|
||||
window.history.replaceState({}, "", newUrl);
|
||||
loadTranslation(projectId, next);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<option value="en">English (default)</option>
|
||||
<option value="de">Deutsch</option>
|
||||
</select>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="custom-select">
|
||||
<select
|
||||
value={editLocale}
|
||||
onChange={(e) => switchLocale(e.target.value)}
|
||||
>
|
||||
<option value="en">English (default)</option>
|
||||
<option value="de">Deutsch</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="inline-flex rounded-lg overflow-hidden border border-stone-700/40">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => switchLocale("en")}
|
||||
className={`px-3 py-1 text-sm ${
|
||||
editLocale === "en" ? "bg-stone-700 text-white" : "bg-stone-800 text-stone-300 hover:bg-stone-700"
|
||||
}`}
|
||||
>
|
||||
EN
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => switchLocale("de")}
|
||||
className={`px-3 py-1 text-sm ${
|
||||
editLocale === "de" ? "bg-stone-700 text-white" : "bg-stone-800 text-stone-300 hover:bg-stone-700"
|
||||
}`}
|
||||
>
|
||||
DE
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{editLocale !== "en" && (
|
||||
<p className="text-xs text-stone-400 mt-2">
|
||||
Title/description are saved as a translation. Other fields are global.
|
||||
Title, description, and content are saved as a translation. Other fields are global.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user