añadido coger el idioma

This commit is contained in:
2024-09-30 11:06:00 +02:00
parent f09d5aeceb
commit 13e3a69cd6
7 changed files with 43 additions and 3 deletions

View File

@ -776,6 +776,15 @@ $routes->group('api', ['filter' => 'jwt'], static function ($routes) {
// ...
});
/*
* --------------------------------------------------------------------
* Translation
* --------------------------------------------------------------------
*/
$routes->group('translate', ['namespace' => 'App\Controllers'], function ($routes) {
$routes->post('getTranslation', 'Language::getTranslation', ['as' => 'getKeys']);
});
$routes->resource('translate', ['namespace' => 'App\Controllers', 'controller' => 'Language', 'except' => '']);
/*

View File

@ -15,4 +15,15 @@ class Language extends BaseController
$url = previous_url();
return redirect()->to($url);
}
// Function to get the translation of the language file from a AJAX request
public function getTranslation()
{
$translationFile = $this->request->getPost('translationFile');
$locale = $this->request->getPost('locale');
$path = "Language/{$locale}/$translationFile.php";
$lang = require APPPATH.$path;
return json_encode($lang);
}
}

View File

@ -31,12 +31,12 @@ return [
'presupuestoEstadoAceptado' => 'Acepted',
'incidencia' => 'Incident',
'reimpresion' => 'Reprint',
'reimpresion' => 'Free of charge',
'autor' => 'Author',
'coleccion' => 'Collection',
'numeroEdicion' => 'Edition number',
'isbn' => 'ISBN',
'referenciaCliente' => 'Customer reference',
'formatoLibro' => "Book format",
'papelFormatoId' => "Size",
'papelFormatoPersonalizado' => 'Custom size',
'papelFormatoAncho' => 'Width',

View File

@ -63,6 +63,7 @@ return [
'isbn' => 'ISBN',
'referenciaCliente' => 'Referencia del cliente',
'referenciaCliente2' => 'Referencia',
'formatoLibro' => "Formato libro",
'papelFormatoId' => "Tamaño",
'papelFormatoPersonalizado' => 'Tamaño personalizado',
'papelFormatoAncho' => 'Ancho',

View File

@ -20,6 +20,8 @@ $picture = "/assets/img/default-user.png";
name="viewport"
content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
<meta name="locale" content="<?= $session->get("lang") ?>">
<title><?= config('Safekat')->appName ?></title>
<meta name="description" content="" />

View File

@ -5,7 +5,7 @@ class DatosGenerales {
constructor(domItem) {
this.domItem = domItem;
this.formatoLibro = new ClassSelect($("#papelFormatoId"), '/papel-formato/menuitems', 'Seleccione formato');
this.formatoLibro = new ClassSelect($("#papelFormatoId"), '/papel-formato/menuitems', window.translations["formatoLibro"]);
this.checkFormatoPersonalizado = this.domItem.find("#papelFormatoPersonalizado");
this.formatoPersonalizado = this.domItem.find("#formatoPersonalizado");

View File

@ -1,9 +1,26 @@
import DatosGenerales from './datosGenerales.js';
import Ajax from '../../components/ajax.js';
document.addEventListener('DOMContentLoaded', function() {
function initPresupuesto(response){
window.translations = JSON.parse(response);
let datosGenerales = new DatosGenerales($("#datos-generales"));
datosGenerales.init();
}
document.addEventListener('DOMContentLoaded', function() {
const locale = document.querySelector('meta[name="locale"]').getAttribute('content');
new Ajax('/translate/getTranslation', {locale: locale, translationFile: 'Presupuestos'}, {},
initPresupuesto,
function(error){
console.log("Error getting translations:", error);
}
).post();
});