feat: add i18n support, avaiable languages are 'en' and 'ja'

This commit is contained in:
d-kimsuon
2025-10-19 19:51:16 +09:00
parent 170c6ec759
commit 4a4354fe63
56 changed files with 5151 additions and 279 deletions

View File

@@ -8,6 +8,7 @@ const LayerImpl = Effect.gen(function* () {
unifySameTitleSession: true,
enterKeyBehavior: "shift-enter-send",
permissionMode: "default",
locale: "ja",
});
const setUserConfig = (newConfig: UserConfig) =>

View File

@@ -1,18 +1,13 @@
import { getCookie, setCookie } from "hono/cookie";
import { createMiddleware } from "hono/factory";
import { userConfigSchema } from "../../lib/config/config";
import type { UserConfig } from "../../lib/config/config";
import { parseUserConfig } from "../../lib/config/parseUserConfig";
import type { HonoContext } from "../app";
export const configMiddleware = createMiddleware<HonoContext>(
async (c, next) => {
const cookie = getCookie(c, "ccv-config");
const parsed = (() => {
try {
return userConfigSchema.parse(JSON.parse(cookie ?? "{}"));
} catch {
return userConfigSchema.parse({});
}
})();
const parsed = parseUserConfig(cookie);
if (cookie === undefined) {
setCookie(
@@ -21,7 +16,10 @@ export const configMiddleware = createMiddleware<HonoContext>(
JSON.stringify({
hideNoUserMessageSession: true,
unifySameTitleSession: true,
}),
enterKeyBehavior: "shift-enter-send",
permissionMode: "default",
locale: "ja",
} satisfies UserConfig),
);
}

View File

@@ -1,4 +1,5 @@
import z from "zod";
import { localeSchema } from "../../../lib/i18n/schema";
export const userConfigSchema = z.object({
hideNoUserMessageSession: z.boolean().optional().default(true),
@@ -11,6 +12,7 @@ export const userConfigSchema = z.object({
.enum(["acceptEdits", "bypassPermissions", "default", "plan"])
.optional()
.default("default"),
locale: localeSchema.optional().default("en"),
});
export type UserConfig = z.infer<typeof userConfigSchema>;

View File

@@ -0,0 +1,8 @@
import { cookies } from "next/headers";
import { parseUserConfig } from "./parseUserConfig";
export const getUserConfigOnServerComponent = async () => {
const cookie = await cookies();
const userConfigJson = cookie.get("ccv-config")?.value;
return parseUserConfig(userConfigJson);
};

View File

@@ -0,0 +1,13 @@
import { userConfigSchema } from "./config";
export const parseUserConfig = (configJson: string | undefined) => {
const parsed = (() => {
try {
return userConfigSchema.parse(JSON.parse(configJson ?? "{}"));
} catch {
return userConfigSchema.parse({});
}
})();
return parsed;
};