From 24412c63ca3062e54767508389318ca048d443e9 Mon Sep 17 00:00:00 2001 From: amazuecos Date: Sun, 2 Mar 2025 13:44:10 +0100 Subject: [PATCH] add name translation wiki-section --- ci4/app/Controllers/Wiki/WikiController.php | 7 ++-- ...-03-02-120000_WikiSectionNameMigration.php | 36 +++++++++++++++++++ ci4/app/Entities/Wiki/WikiSectionEntity.php | 6 +++- .../Entities/Wiki/WikiSectionRoleEntity.php | 2 -- ci4/app/Language/en/Wiki.php | 7 +++- ci4/app/Language/es/Wiki.php | 5 +++ .../vuexy/components/modals/modalSection.php | 8 +++-- ci4/app/Views/themes/vuexy/wiki/layout.php | 2 +- .../safekat/components/editorjs/WikiEditor.js | 2 +- .../components/forms/WikiSectionForm.js | 16 ++++++--- 10 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 ci4/app/Database/Migrations/2025-03-02-120000_WikiSectionNameMigration.php diff --git a/ci4/app/Controllers/Wiki/WikiController.php b/ci4/app/Controllers/Wiki/WikiController.php index 8fc93f87..9ffca5ac 100644 --- a/ci4/app/Controllers/Wiki/WikiController.php +++ b/ci4/app/Controllers/Wiki/WikiController.php @@ -53,7 +53,7 @@ class WikiController extends BaseController $this->viewData['slug'] = $slug; $this->viewData['section'] = $section->withAll($this->locale); $this->viewData['breadcrumb'] = [ - ['title' => lang("Wiki." . $section->slug), 'route' => route_to('showWikiPage', $slug), 'active' => true], + ['title' => $section->name->{$this->locale}, 'route' => route_to('showWikiPage', $slug), 'active' => true], ]; return view('themes/vuexy/wiki/pages/render', $this->viewData); }else{ @@ -173,8 +173,9 @@ class WikiController extends BaseController $bodyData = $this->request->getPost(); $sectionName = $bodyData['name']; $roles = $bodyData['roles']; - $bodyData["slug"] = implode('-', array_map(fn($e) => strtolower($e), explode(' ', $sectionName))); + $bodyData["slug"] = implode('-', array_map(fn($e) => strtolower($e), explode(' ', $sectionName['es']))); $bodyData["order"] = $this->wikiSectionModel->selectMax('order')->first()->order + 1; + $bodyData['name'] = json_encode($sectionName); $wikiSectionId = $this->wikiSectionModel->insert($bodyData); if(count($roles) > 0){ foreach ($roles as $key => $role) { @@ -193,7 +194,7 @@ class WikiController extends BaseController $wikiSectionId = $bodyData['wiki_section_id']; $roles = $bodyData['roles']; $this->wikiSectionModel->update($wikiSectionId, [ - "name" => $bodyData['name'], + "name" => json_encode($bodyData['name']), "icon" => $bodyData['icon'] ]); $this->wikiSectionRoleModel->where('wiki_section_id',$wikiSectionId)->delete(); diff --git a/ci4/app/Database/Migrations/2025-03-02-120000_WikiSectionNameMigration.php b/ci4/app/Database/Migrations/2025-03-02-120000_WikiSectionNameMigration.php new file mode 100644 index 00000000..60779f5d --- /dev/null +++ b/ci4/app/Database/Migrations/2025-03-02-120000_WikiSectionNameMigration.php @@ -0,0 +1,36 @@ +db->table('wiki_sections')->select()->get()->getResultArray(); + $this->forge->dropColumn('wiki_sections','name'); + $this->forge->addColumn('wiki_sections',[ + 'name' => [ + 'type' => 'LONGTEXT', + 'null' => false, + ] + ]); + foreach ($sections as $key => $value) { + $this->db->table('wiki_sections')->update( + [ + "name" => json_encode(["es" => $value['name'],"en" => $value['name']]) + ], + 'id = '.$value['id'] + ); + } + } + + public function down() + { + + } +} diff --git a/ci4/app/Entities/Wiki/WikiSectionEntity.php b/ci4/app/Entities/Wiki/WikiSectionEntity.php index 160b42f4..ede44807 100644 --- a/ci4/app/Entities/Wiki/WikiSectionEntity.php +++ b/ci4/app/Entities/Wiki/WikiSectionEntity.php @@ -17,13 +17,17 @@ class WikiSectionEntity extends Entity "parent_id" => null ]; protected $casts = [ - "name" => "string", "slug" => "string", "role" => "string", "icon" => "string", "order" => "int", "parent_id" => "int" ]; + public function getName() : object + { + return json_decode($this->attributes['name']); + } + public function withPage(): self { diff --git a/ci4/app/Entities/Wiki/WikiSectionRoleEntity.php b/ci4/app/Entities/Wiki/WikiSectionRoleEntity.php index bde02da8..76028efe 100644 --- a/ci4/app/Entities/Wiki/WikiSectionRoleEntity.php +++ b/ci4/app/Entities/Wiki/WikiSectionRoleEntity.php @@ -1,8 +1,6 @@ "Section name", 'help' => "Help", 'intro-admin' => "Introduction", 'presupuesto-cliente' => "Client budget", @@ -22,6 +23,7 @@ return [ 'new_section' => "New section", 'edit_section' => "Edit section", 'header-placeholder' => "Start writing a header ...", + 'section_placeholder' => "Write the name of the section", 'errors' => [ 'publish_before_save' => "You have to save before publish the content" ], @@ -40,9 +42,12 @@ return [ 'no_content' => 'Page is empty', 'dropdown_roles' => 'Roles that can see this section', 'save_content' => 'Save contents', + 'release_content' => "Release contents", 'delete_section' => 'Delete section', 'roles' => 'Roles', - 'multiple_select_role' => 'Select one or multiple roles' + 'multiple_select_role' => 'Select one or multiple roles', + 'spanish' => "Spanish", + 'english' => "English", diff --git a/ci4/app/Language/es/Wiki.php b/ci4/app/Language/es/Wiki.php index 0365a09f..c9cb50b2 100644 --- a/ci4/app/Language/es/Wiki.php +++ b/ci4/app/Language/es/Wiki.php @@ -1,6 +1,7 @@ "Nombre sección", 'help' => "Ayuda", 'intro-admin' => "Introducción", 'intro-cliente' => "Introducción", @@ -46,9 +47,13 @@ return [ 'no_content' => 'No hay contenido en la página', 'dropdown_roles' => 'Roles que pueden ver la sección', 'save_content' => 'Guardar contenido', + 'release_content' => "Publicar contenido", 'delete_section' => 'Eliminar sección', 'roles' => 'Roles', 'multiple_select_role' => 'Selecciona uno o varios roles', 'select_icon' => 'Selecciona un icono', + 'spanish' => "Español", + 'english' => "Ingles", + ]; diff --git a/ci4/app/Views/themes/vuexy/components/modals/modalSection.php b/ci4/app/Views/themes/vuexy/components/modals/modalSection.php index 466da285..f235ba02 100644 --- a/ci4/app/Views/themes/vuexy/components/modals/modalSection.php +++ b/ci4/app/Views/themes/vuexy/components/modals/modalSection.php @@ -15,8 +15,12 @@
- - + + +
+
+ +
diff --git a/ci4/app/Views/themes/vuexy/wiki/layout.php b/ci4/app/Views/themes/vuexy/wiki/layout.php index 7d582df1..0be1a0e1 100644 --- a/ci4/app/Views/themes/vuexy/wiki/layout.php +++ b/ci4/app/Views/themes/vuexy/wiki/layout.php @@ -117,7 +117,7 @@ $picture = "/assets/img/default-user.png"; slug) ?>" class="menu-link"> - slug) ?> + getName()->{$session->get("lang")} ?> user()->inGroup('admin')): ?> diff --git a/httpdocs/assets/js/safekat/components/editorjs/WikiEditor.js b/httpdocs/assets/js/safekat/components/editorjs/WikiEditor.js index a30ea75c..a308e7fa 100644 --- a/httpdocs/assets/js/safekat/components/editorjs/WikiEditor.js +++ b/httpdocs/assets/js/safekat/components/editorjs/WikiEditor.js @@ -136,7 +136,7 @@ class WikiEditor extends TranslationHelper { $('#release-editor').on('click', () => { this.editor.save().then(outputData => { - alertConfirmAction('Publicar contenido').then(result => { + alertConfirmAction(this.get_lang('release_content')).then(result => { if (result.isConfirmed) { this.handlePublishContent(outputData) } diff --git a/httpdocs/assets/js/safekat/components/forms/WikiSectionForm.js b/httpdocs/assets/js/safekat/components/forms/WikiSectionForm.js index fecce941..8b92f4e9 100644 --- a/httpdocs/assets/js/safekat/components/forms/WikiSectionForm.js +++ b/httpdocs/assets/js/safekat/components/forms/WikiSectionForm.js @@ -8,7 +8,9 @@ class WikiSectionForm { this.btnNew = $("#submit-new-section") this.btnUpdate = $("#submit-update-section") this.btnDelete = $("#delete-section") - this.name = this.item.find('#section-name') + this.nameEs = this.item.find('#section-name-es') + this.nameEn = this.item.find('#section-name-en') + this.icon = this.item.find('#section-icon') this.roles = this.item.find('#section-roles').select2({ dropdownParent: this.item.parent() @@ -61,7 +63,11 @@ class WikiSectionForm { } getFormData() { return { - name: this.name.val(), + name: { + es : this.nameEs.val(), + en : this.nameEn.val(), + + }, icon: this.icon.val(), roles: this.roles.val() } @@ -128,7 +134,8 @@ class WikiSectionForm { const sectionData = await this.handleShowSection() if (sectionData) { console.log(sectionData) - this.name.val(sectionData.data.name) + this.nameEs.val(sectionData.data.name?.es) + this.nameEn.val(sectionData.data.name?.en) this.icon.val(sectionData.data.icon).trigger('change') this.roles.val(sectionData.data.roles_array).trigger('change') } @@ -158,7 +165,8 @@ class WikiSectionForm { }) } empty() { - this.name.val(null) + this.nameEs.val(null) + this.nameEn.val(null) this.icon.val("").trigger('change') this.roles.val("").trigger('change')