📄 Archivos .xlf — traducciones XLIFF en modulos
Actualizado: 2024-12-01
El sistema moderno de traducciones de PrestaShop 8+ usa el formato XLIFF 1.2 (.xlf). Cada modulo guarda sus traducciones en modules/mymodule/translations/ con archivos nombrados por locale (es-ES, en-US, fr-FR...).
#Estructura del directorio de traducciones
Estructura de archivos de traduccion de un modulo
bash
modules/mymodule/
├── translations/
│ ├── es-ES.xlf # Español (España) — todos los dominios
│ ├── en-US.xlf # Ingles (EEUU)
│ ├── fr-FR.xlf # Frances
│ ├── de-DE.xlf # Aleman
│ └── index.php # Seguridad: <?php exit;
└── mymodule.php
# Alternativa: un archivo por dominio
translations/
├── es-ES.Modules.Mymodule.Admin.xlf
├── es-ES.Modules.Mymodule.Shop.xlf
├── en-US.Modules.Mymodule.Admin.xlf
└── en-US.Modules.Mymodule.Shop.xlf
#Formato del archivo .xlf
modules/mymodule/translations/es-ES.xlf — formato completo
xml
<?xml version="1.0" encoding="UTF-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<!-- ── DOMINIO ADMIN ── -->
<file original="Modules.Mymodule.Admin"
source-language="en-US"
target-language="es-ES"
datatype="plaintext">
<body>
<!-- ID = version slug de la cadena fuente -->
<trans-unit id="SaveConfiguration">
<source>Save configuration</source>
<target>Guardar configuracion</target>
</trans-unit>
<trans-unit id="ApiKeyLabel">
<source>API Key</source>
<target>Clave API</target>
</trans-unit>
<trans-unit id="SuccessMessage">
<source>Settings saved successfully.</source>
<target>Configuracion guardada correctamente.</target>
</trans-unit>
</body>
</file>
<!-- ── DOMINIO SHOP ── -->
<file original="Modules.Mymodule.Shop"
source-language="en-US"
target-language="es-ES"
datatype="plaintext">
<body>
<trans-unit id="ReviewsTabTitle">
<source>Customer Reviews</source>
<target>Opiniones de Clientes</target>
</trans-unit>
</body>
</file>
</xliff>
#Extraer cadenas con bin/console
Extraer cadenas trans() a archivos .xlf con Symfony CLI
bash
# Extraer cadenas de traduccion del modulo
# (genera los archivos .xlf en translations/)
php bin/console prestashop:translation:extract mymodule
# Especificar locale
php bin/console prestashop:translation:extract mymodule --locale=es-ES
# Solo un dominio especifico
php bin/console prestashop:translation:extract mymodule --domain=Modules.Mymodule.Admin
# Ver cadenas sin traducir
php bin/console prestashop:translation:extract mymodule --untranslated-only
# Limpiar cache de traducciones despues de editar archivos
php bin/console cache:clear
#Traducir desde el Back Office
Las traducciones de modulos tambien se pueden gestionar desde el BO sin tocar archivos .xlf:
| Paso | Accion |
|---|---|
| 1 | BO > Internacional > Traducciones |
| 2 | Tipo de traduccion: 'Traducciones de modulos instalados' |
| 3 | Seleccionar el modulo y el idioma |
| 4 | Editar las cadenas en la interfaz visual |
| 5 | Guardar — PS escribe los archivos .xlf automaticamente |
#Fallback al idioma por defecto
Comportamiento del fallback cuando falta traduccion
php
<?php
// Si no existe traduccion para el idioma activo,
// PrestaShop devuelve la CADENA FUENTE (source) del .xlf
// o el primer argumento de trans() si no hay archivo.
// Ejemplo: idioma activo = 'pt-PT' (no hay traduccion)
$text = $this->trans('Save configuration', [], 'Modules.Mymodule.Admin');
// Resultado: 'Save configuration' (cadena fuente en ingles)
// Para garantizar el fallback a espanol:
// 1. Incluir siempre el archivo es-ES.xlf con todas las cadenas
// 2. O configurar el idioma por defecto del sitio en espanol
// Verificar si el modulo usa el nuevo sistema:
if ($this->isUsingNewTranslationSystem()) {
// El modulo tiene translations/*.xlf — usar trans()
return $this->trans('Mi texto', [], 'Modules.Mymodule.Admin');
} else {
// Modulo legacy sin .xlf — usar l()
return $this->l('Mi texto');
}
Activar el nuevo sistema de traducciones
Para que PrestaShop detecte el sistema moderno, el modulo debe devolver true en isUsingNewTranslationSystem() (disponible en PS 1.7.6+). Esto se activa automaticamente si existe el directorio translations/ con archivos .xlf.
Descargar en Markdown
Pensado para pegar en ChatGPT, Claude u otra IA. Incluye solo el contenido de esta pagina.