fix translations
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-11-16 14:57:05 +08:00
parent f339e5e2f0
commit b1a3add1d9
50 changed files with 391 additions and 428 deletions

View File

@@ -1,39 +1,6 @@
import { DEFAULT_LOCALE, SUPPORTED_LOCALES } from "@/config/i18n";
import { getRequestConfig } from "next-intl/server";
import { cookies } from "next/headers";
import { readFileSync, readdirSync, statSync } from "fs";
import { join } from "path";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function loadMessagesFromDir(dirPath: string): Record<string, any> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const messages: Record<string, any> = {};
try {
const items = readdirSync(dirPath);
for (const item of items) {
const fullPath = join(dirPath, item);
const stat = statSync(fullPath);
if (stat.isDirectory()) {
const dirMessages = loadMessagesFromDir(fullPath);
Object.assign(messages, { [item]: dirMessages });
} else if (item.endsWith(".json")) {
try {
const content = readFileSync(fullPath, "utf-8");
const jsonContent = JSON.parse(content);
Object.assign(messages, { [item.replace(".json", "")]: jsonContent });
} catch (error) {
console.warn(`Failed to load JSON file ${fullPath}:`, error);
}
}
}
} catch (error) {
console.warn(`Failed to read directory ${dirPath}:`, error);
}
return messages;
}
export default getRequestConfig(async () => {
const store = await cookies();
@@ -43,11 +10,8 @@ export default getRequestConfig(async () => {
return locale;
})();
const messagesPath = join(process.cwd(), "public/messages", locale);
const messages = loadMessagesFromDir(messagesPath);
return {
locale,
messages,
messages: (await import(`../../messages/${locale}.json`)).default,
};
});