House rules also machine translated and added loadrules universal lib

This commit is contained in:
2025-09-15 17:46:34 +03:00
parent a9f33e9ec0
commit 5771581013
6 changed files with 255 additions and 37 deletions

View File

@@ -3,6 +3,7 @@ import ReactMarkdown, { Components } from "react-markdown";
import { vipnagorgialla } from "@/components/Vipnagorgialla";
import SectionDivider from "@/components/SectionDivider";
import { getTranslations, setRequestLocale } from "next-intl/server";
import { loadRulesBun } from "@/lib/loadRules";
export default async function Page({
params,
@@ -12,8 +13,7 @@ export default async function Page({
const { locale } = await params;
setRequestLocale(locale);
const t = await getTranslations({ locale });
const file = Bun.file("src/data/kodukord.md");
const content = await file.text();
const content = await loadRulesBun("kodukord", locale as "et" | "en");
return (
<div>

View File

@@ -3,6 +3,7 @@ import ReactMarkdown, { Components } from "react-markdown";
import { vipnagorgialla } from "@/components/Vipnagorgialla";
import SectionDivider from "@/components/SectionDivider";
import { getTranslations, setRequestLocale } from "next-intl/server";
import { loadRulesBun } from "@/lib/loadRules";
// Map of valid slugs to their translation keys
const rulesMap = {
@@ -28,20 +29,10 @@ async function getRuleContent(slug: string, locale: string) {
const ruleConfig = rulesMap[slug as RuleSlug];
try {
// Try to load the file for the current locale first
let filePath = `src/data/rules/${locale}/${slug}.md`;
let file = Bun.file(filePath);
// Check if file exists, if not fallback to Estonian
if (!(await file.exists()) && locale !== "et") {
console.warn(
`Rules file not found for ${slug} in ${locale}, falling back to Estonian`,
);
filePath = `src/data/rules/et/${slug}.md`;
file = Bun.file(filePath);
}
const content = await file.text();
const content = await loadRulesBun(
slug as "cs2" | "lol",
locale as "et" | "en",
);
return {
content,
titleKey: ruleConfig.titleKey,