diff --git a/app/api/i18n/locale/route.ts b/app/api/i18n/locale/route.ts deleted file mode 100644 index 6125f5f..0000000 --- a/app/api/i18n/locale/route.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { cookies } from "next/headers"; -import { NextResponse } from "next/server"; -import { getSqliteConnection } from "@/server/db/client"; -import { instanceLocales } from "@/server/db/schema"; -import { DomainError } from "@/server/domain/errors"; -import { buildLocaleCookie, normalizeLocaleCode } from "@/server/i18n/locale"; -import { eq } from "drizzle-orm"; - -export const runtime = "nodejs"; -export const dynamic = "force-dynamic"; - -export async function POST(request: Request) { - try { - const payload = await request.json(); - const locale = normalizeLocaleCode(typeof payload.locale === "string" ? payload.locale : null); - if (!locale) { - throw new DomainError("VALIDATION_ERROR", "validation.invalidLocale", { - messageKey: "validation.invalidLocale", - }); - } - - const row = getSqliteConnection().db - .select({ code: instanceLocales.code, status: instanceLocales.status }) - .from(instanceLocales) - .where(eq(instanceLocales.code, locale)) - .get(); - if (!row || row.status === "archived") { - throw new DomainError("UNSUPPORTED_LOCALE", "validation.unsupportedLocale", { - messageKey: "validation.unsupportedLocale", - }); - } - - (await cookies()).set(buildLocaleCookie(row.code)); - return NextResponse.json({ ok: true, data: { locale: row.code } }); - } catch (error) { - const normalized = error instanceof DomainError - ? error - : new DomainError("VALIDATION_ERROR", "validation.unsupportedLocale", { - messageKey: "validation.unsupportedLocale", - }); - return NextResponse.json( - { - ok: false, - error: { - code: normalized.code, - message: normalized.message, - messageKey: normalized.details?.messageKey, - }, - }, - { status: normalized.status }, - ); - } -} diff --git a/components/i18n/locale-select-form.tsx b/components/i18n/locale-select-form.tsx deleted file mode 100644 index 887b119..0000000 --- a/components/i18n/locale-select-form.tsx +++ /dev/null @@ -1,58 +0,0 @@ -"use client"; - -import { useState, useTransition } from "react"; -import { Label } from "poyraz-ui/atoms"; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from "poyraz-ui/molecules"; - -type LocaleOption = { - code: string; - nativeName: string; - name: string; -}; - -type LocaleSelectFormProps = { - label: string; - value: string; - locales: LocaleOption[]; -}; - -export function LocaleSelectForm({ label, value, locales }: LocaleSelectFormProps) { - const [currentLocale, setCurrentLocale] = useState(value); - const [pending, startTransition] = useTransition(); - - function handleChange(locale: string) { - setCurrentLocale(locale); - startTransition(async () => { - await fetch("/api/i18n/locale", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ locale }), - }); - window.location.reload(); - }); - } - - return ( -
- - -
- ); -}