trans-history: concepto multiidioma (helper de concepto compartido)
Extrae la lógica de concepto traducible a lib/tx-concept.ts (buildConcept + purchasedPD + SERVICE_CONCEPT) y la reutilizan points-history y trans-history. La columna Concepto de trans-history ahora se traduce (reusa History.points.concept.*) en vez de mostrar el product_name en español. Corrige también la sombra de variable en PlatformBox (map t -> tx). Verificado con la cuenta 15. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
// Concepto traducible de una transacción de home_stripelog, compartido por los
|
||||
// historiales de PD/PV y de transacciones. Devuelve una CLAVE (+ argumentos) que
|
||||
// la página traduce; `conceptRaw` es la reserva para pagos heredados sin servicio.
|
||||
|
||||
/** Slug de servicio (home_stripelog.service) -> clave de concepto (History.points.concept.*). */
|
||||
export const SERVICE_CONCEPT: Record<string, string> = {
|
||||
rename: 'rename',
|
||||
customize: 'customize',
|
||||
'change-race': 'changeRace',
|
||||
'change-faction': 'changeFaction',
|
||||
'level-up': 'levelUp',
|
||||
gold: 'gold',
|
||||
transfer: 'transfer',
|
||||
'restore-item': 'restoreItem',
|
||||
'send-gift': 'sendGift',
|
||||
}
|
||||
|
||||
/** PD acreditados por un pago (si es una compra de PD), o null si es un servicio/ítem. */
|
||||
export function purchasedPD(productName: string, service: string | null, metadata: string | null): number | null {
|
||||
const m = /(\d+)\s*PD\b/i.exec(productName || '')
|
||||
if (m) return Number(m[1])
|
||||
if (service === 'dpoints') {
|
||||
try {
|
||||
const p = metadata ? JSON.parse(metadata).points : null
|
||||
return p ? Number(p) : null
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export interface Concept {
|
||||
conceptKey: string | null
|
||||
conceptArgs: Record<string, string | number>
|
||||
conceptRaw: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Concepto de una fila de home_stripelog: compra de PD -> "{n} PD"; servicio
|
||||
* conocido -> "{etiqueta}: {personaje}"; en otro caso, texto libre heredado.
|
||||
*/
|
||||
export function buildConcept(
|
||||
productName: string,
|
||||
service: string | null,
|
||||
characterName: string,
|
||||
metadata: string | null,
|
||||
): Concept {
|
||||
const raw = productName || '—'
|
||||
const pd = purchasedPD(raw, service, metadata)
|
||||
if (pd != null && (service === 'dpoints' || service === null)) {
|
||||
return { conceptKey: 'pd', conceptArgs: { n: pd }, conceptRaw: raw }
|
||||
}
|
||||
if (service && SERVICE_CONCEPT[service]) {
|
||||
return { conceptKey: SERVICE_CONCEPT[service], conceptArgs: { detail: characterName }, conceptRaw: raw }
|
||||
}
|
||||
return { conceptKey: null, conceptArgs: {}, conceptRaw: raw }
|
||||
}
|
||||
Reference in New Issue
Block a user