diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 6c4d93ea..46de2b2a 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -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' => '']); /* diff --git a/ci4/app/Controllers/Language.php b/ci4/app/Controllers/Language.php index cd2b062e..437f18eb 100755 --- a/ci4/app/Controllers/Language.php +++ b/ci4/app/Controllers/Language.php @@ -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); + } } diff --git a/ci4/app/Language/en/Presupuestos.php b/ci4/app/Language/en/Presupuestos.php index 4d514cfa..cce0c828 100755 --- a/ci4/app/Language/en/Presupuestos.php +++ b/ci4/app/Language/en/Presupuestos.php @@ -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', diff --git a/ci4/app/Language/es/Presupuestos.php b/ci4/app/Language/es/Presupuestos.php index d14be329..bb163449 100755 --- a/ci4/app/Language/es/Presupuestos.php +++ b/ci4/app/Language/es/Presupuestos.php @@ -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', diff --git a/ci4/app/Views/themes/vuexy/main/defaultlayout.php b/ci4/app/Views/themes/vuexy/main/defaultlayout.php index cb651dea..12cef7af 100644 --- a/ci4/app/Views/themes/vuexy/main/defaultlayout.php +++ b/ci4/app/Views/themes/vuexy/main/defaultlayout.php @@ -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" /> + "> + <?= config('Safekat')->appName ?> diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js index 7c581044..47e3495a 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js @@ -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"); diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js index fca50cba..a3193bb1 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js @@ -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(); });