From cc6c76859cf372ec2d35e038ab1c98d37f2f4f95 Mon Sep 17 00:00:00 2001 From: adevopg Date: Tue, 14 Jul 2026 19:50:20 +0000 Subject: [PATCH] =?UTF-8?q?Foro=20multiidioma:=20nombres/descripciones=20d?= =?UTF-8?q?e=20categor=C3=ADas=20y=20foros=20(ES/EN)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit forum_categories.name_en y forums.name_en/description_en (sql/add_forum_en.sql, aplicado en prod y traducidos los existentes: Comunidad/Anuncios/Discusión general). getForumIndex(locale) y getForum(id, locale) usan EN si existe, si no caen al español. Las páginas del foro pasan el locale. Labels (Temas/Mensajes) ya estaban traducidos. Verificado: /en/forum en inglés, /es/forum en español. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../app/[locale]/forum/[forumId]/page.tsx | 2 +- web-next/app/[locale]/forum/page.tsx | 2 +- web-next/lib/forum.ts | 24 ++++++++++++------- web-next/sql/add_forum_en.sql | 13 ++++++++++ 4 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 web-next/sql/add_forum_en.sql diff --git a/web-next/app/[locale]/forum/[forumId]/page.tsx b/web-next/app/[locale]/forum/[forumId]/page.tsx index 7aadca8..fdb06af 100644 --- a/web-next/app/[locale]/forum/[forumId]/page.tsx +++ b/web-next/app/[locale]/forum/[forumId]/page.tsx @@ -23,7 +23,7 @@ export default async function ForumPage({ const t = await getTranslations('Forum') const id = Number(forumId) - const forum = await getForum(id) + const forum = await getForum(id, locale) if (!forum) notFound() const total = await countTopics(id) const totalPages = Math.max(1, Math.ceil(total / PER_PAGE)) diff --git a/web-next/app/[locale]/forum/page.tsx b/web-next/app/[locale]/forum/page.tsx index 03a601a..16da9d5 100644 --- a/web-next/app/[locale]/forum/page.tsx +++ b/web-next/app/[locale]/forum/page.tsx @@ -10,7 +10,7 @@ export default async function ForumIndexPage({ params }: { params: Promise<{ loc const { locale } = await params setRequestLocale(locale) const t = await getTranslations('Forum') - const categories = await getForumIndex() + const categories = await getForumIndex(locale) return ( diff --git a/web-next/lib/forum.ts b/web-next/lib/forum.ts index dbfb40c..f29a86e 100644 --- a/web-next/lib/forum.ts +++ b/web-next/lib/forum.ts @@ -60,13 +60,14 @@ export interface SearchResult { } /** Índice del foro: categorías con sus foros visibles (+ contadores y último tema). */ -export async function getForumIndex(): Promise { +export async function getForumIndex(locale = 'es'): Promise { + const en = locale === 'en' try { const [cats] = await db(DB.web).query( - 'SELECT id, name FROM forum_categories ORDER BY `order`, id', + 'SELECT id, name, name_en FROM forum_categories ORDER BY `order`, id', ) const [forums] = await db(DB.web).query( - `SELECT f.id, f.category_id, f.name, f.description, f.icon, + `SELECT f.id, f.category_id, f.name, f.name_en, f.description, f.description_en, f.icon, (SELECT COUNT(*) FROM forum_topics t WHERE t.forum_id = f.id AND t.deleted = 0) AS topic_count, (SELECT COUNT(*) FROM forum_posts p JOIN forum_topics t ON p.topic_id = t.id WHERE t.forum_id = f.id AND p.deleted = 0 AND t.deleted = 0) AS post_count, @@ -82,12 +83,14 @@ export async function getForumIndex(): Promise { ) const byCat = new Map() for (const f of forums) { - const info = f as unknown as ForumInfo + const info = f as unknown as ForumInfo & { name_en?: string | null; description_en?: string | null } + info.name = en && info.name_en ? info.name_en : info.name + info.description = en && info.description_en ? info.description_en : info.description if (!byCat.has(info.category_id)) byCat.set(info.category_id, []) byCat.get(info.category_id)!.push(info) } return cats - .map((c) => ({ id: c.id, name: c.name, forums: byCat.get(c.id) ?? [] })) + .map((c) => ({ id: c.id, name: en && c.name_en ? c.name_en : c.name, forums: byCat.get(c.id) ?? [] })) .filter((c) => c.forums.length > 0) } catch { return [] @@ -106,13 +109,18 @@ export async function listForumsForMove(): Promise<{ id: number; name: string }[ } } -export async function getForum(id: number): Promise<{ name: string; description: string } | null> { +export async function getForum(id: number, locale = 'es'): Promise<{ name: string; description: string } | null> { + const en = locale === 'en' try { const [rows] = await db(DB.web).query( - 'SELECT name, description FROM forums WHERE id = ? AND visibility = 1 AND deleted = 0', + 'SELECT name, name_en, description, description_en FROM forums WHERE id = ? AND visibility = 1 AND deleted = 0', [id], ) - return rows[0] ? { name: rows[0].name, description: rows[0].description } : null + if (!rows[0]) return null + return { + name: en && rows[0].name_en ? rows[0].name_en : rows[0].name, + description: en && rows[0].description_en ? rows[0].description_en : rows[0].description, + } } catch { return null } diff --git a/web-next/sql/add_forum_en.sql b/web-next/sql/add_forum_en.sql new file mode 100644 index 0000000..b06281c --- /dev/null +++ b/web-next/sql/add_forum_en.sql @@ -0,0 +1,13 @@ +-- Foro multiidioma: nombre/descripción en inglés (opcional). Si están vacíos, se +-- cae a la versión en español. El texto original es ES. +ALTER TABLE forum_categories ADD COLUMN name_en VARCHAR(255) NULL AFTER name; +ALTER TABLE forums + ADD COLUMN name_en VARCHAR(45) NULL AFTER name, + ADD COLUMN description_en TEXT NULL AFTER description; + +-- Traducción de las categorías/foros existentes. +UPDATE forum_categories SET name_en = 'Community' WHERE name = 'Comunidad'; +UPDATE forums SET name_en = 'Announcements', + description_en = 'Official server news and announcements.' WHERE name = 'Anuncios'; +UPDATE forums SET name_en = 'General Discussion', + description_en = 'Talk about everything server-related with the community.' WHERE name = 'Discusión general';