mirror of
https://github.com/aljazceru/claude-code-viewer.git
synced 2026-01-01 20:54:23 +01:00
feat: add i18n support, avaiable languages are 'en' and 'ja'
This commit is contained in:
@@ -8,6 +8,7 @@ const LayerImpl = Effect.gen(function* () {
|
||||
unifySameTitleSession: true,
|
||||
enterKeyBehavior: "shift-enter-send",
|
||||
permissionMode: "default",
|
||||
locale: "ja",
|
||||
});
|
||||
|
||||
const setUserConfig = (newConfig: UserConfig) =>
|
||||
|
||||
@@ -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),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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>;
|
||||
|
||||
8
src/server/lib/config/getUserConfigOnServerComponent.ts
Normal file
8
src/server/lib/config/getUserConfigOnServerComponent.ts
Normal 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);
|
||||
};
|
||||
13
src/server/lib/config/parseUserConfig.ts
Normal file
13
src/server/lib/config/parseUserConfig.ts
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user