Noticias multiidioma (ES/EN) con fallback
home_noticia gana columnas titulo_en/contenido_en (sql/add_news_en.sql). getNoticias(locale) usa la versión EN si existe, si no cae al español (título y contenido independientes); la fecha también se formatea por idioma. El panel de admin permite escribir la traducción al crear y EDITAR noticias existentes (nuevo PUT /api/admin/news/[id], updateNews). Claves Admin nuevas (título/ contenido EN, editar/guardar). Probado: /en/ muestra EN, /es/ ES; PUT guardado (403 sin sesión). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+10
-4
@@ -31,16 +31,22 @@ export function expansionFromGamebuild(gamebuild: number): string {
|
||||
return 'Unknown'
|
||||
}
|
||||
|
||||
export async function getNoticias(limit = 50): Promise<Noticia[]> {
|
||||
/**
|
||||
* Noticias localizadas. Con `locale='en'` usa `titulo_en`/`contenido_en` si
|
||||
* existen; si están vacías, cae a la versión en español (título y contenido de
|
||||
* forma independiente). El texto original (titulo/contenido) siempre es ES.
|
||||
*/
|
||||
export async function getNoticias(locale = 'es', limit = 50): Promise<Noticia[]> {
|
||||
const [rows] = await db(DB.default).query<RowDataPacket[]>(
|
||||
'SELECT id, titulo, contenido, fecha_publicacion, enlace FROM home_noticia ORDER BY fecha_publicacion DESC LIMIT ?',
|
||||
'SELECT id, titulo, titulo_en, contenido, contenido_en, fecha_publicacion, enlace FROM home_noticia ORDER BY fecha_publicacion DESC LIMIT ?',
|
||||
[limit],
|
||||
)
|
||||
const en = locale === 'en'
|
||||
return rows.map((r) => ({
|
||||
id: r.id,
|
||||
titulo: r.titulo,
|
||||
titulo: en && r.titulo_en ? r.titulo_en : r.titulo,
|
||||
fecha: r.fecha_publicacion ? new Date(r.fecha_publicacion).toISOString() : null,
|
||||
contenido: r.contenido,
|
||||
contenido: en && r.contenido_en ? r.contenido_en : r.contenido,
|
||||
enlace: r.enlace || null,
|
||||
}))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user