From 8642d129075142f6ec33c7dc8d2a63e3a3becee3 Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-sa.fr>
Date: Fri, 4 May 2018 16:10:16 +0200
Subject: [PATCH] dev #74865 add link to update string + add more translatable
 strngs

---
 .../admin/controllers/I18nController.php      | 14 +++++---
 .../admin/views/scripts/i18n/index.phtml      | 12 +++++--
 library/Class/I18n.php                        |  9 ++++-
 library/Class/Profil/I18n.php                 | 35 +++++++++++++++----
 library/Class/Profil/I18nStringUpdator.php    |  5 +++
 .../ZendAfi/Form/Admin/I18n/UpdateString.php  |  5 ++-
 .../admin/controllers/I18nControllerTest.php  | 14 ++++++--
 7 files changed, 77 insertions(+), 17 deletions(-)

diff --git a/application/modules/admin/controllers/I18nController.php b/application/modules/admin/controllers/I18nController.php
index 5f3781838e0..3089892c433 100644
--- a/application/modules/admin/controllers/I18nController.php
+++ b/application/modules/admin/controllers/I18nController.php
@@ -25,6 +25,7 @@ class Admin_I18nController extends ZendAfi_Controller_Action {
   protected $_i18n;
 
   public function init() {
+    parent::init();
     $this->_helper->getHelper('AjaxContext')
                     ->addActionContext('update', 'json')
                     ->initContext()
@@ -32,6 +33,7 @@ class Admin_I18nController extends ZendAfi_Controller_Action {
   }
 
   public function preDispatch() {
+    parent::preDispatch();
     $this->_i18n = Class_I18n::getInstance();
 
   }
@@ -206,6 +208,8 @@ class Admin_I18nController extends ZendAfi_Controller_Action {
       = $form
       = ZendAfi_Form_Admin_I18n_UpdateString::newWith($this->_request->getParams());
 
+    $form->setAction($this->view->url(['render' => null]));
+
     if(!$this->_request->isPost())
       return;
 
@@ -213,13 +217,15 @@ class Admin_I18nController extends ZendAfi_Controller_Action {
     $to = $this->_getParam('to', '');
 
     if(!$this->_i18n->updateString($from, $to)) {
-      $this->_helper->notify($this->_('La modification de la "%s" par "%s" a échoué.',
-                                      $from, $to));
-      return $this->_redirectToReferer();
+      $this->_helper->notify($this->_('La modification de la "%s" par "%s" a échoué. Erreurs : %s',
+                                      $from,
+                                      $to,
+                                      implode(BR, $this->_i18n->getErrors())));
+      return $this->_redirectClose($this->_getReferer());
     }
 
     $this->_helper->notify($this->_('La modification de la chaîne "%s" par "%s" a été enregistrée.',
                                     $from, $to));
-    $this->_redirectToReferer();
+    $this->_redirectClose($this->_getReferer());
   }
 }
\ No newline at end of file
diff --git a/application/modules/admin/views/scripts/i18n/index.phtml b/application/modules/admin/views/scripts/i18n/index.phtml
index b05372b6636..86c0ea17445 100644
--- a/application/modules/admin/views/scripts/i18n/index.phtml
+++ b/application/modules/admin/views/scripts/i18n/index.phtml
@@ -35,12 +35,18 @@ foreach ($this->translated as $langue => $v) { ?>
   <div class="i18n_content" id="i18n_<?php echo $langue;?>" style="display: none;">
   <table>
     <tr>
-      <th><?php echo $this->_('Original');?></th>
+      <th><?php echo $this->_('Original').'&nbsp;'.$this->tagImg(URL_ADMIN_IMG.'flags/' . Class_AdminVar::getDefaultLanguage() .'.png');?></th>
       <th><?php echo $this->_('Traduction').'&nbsp;'.$this->tagImg(URL_ADMIN_IMG.'flags/' . $langue .'.png'); ?></th>
     </tr>
   <?php foreach ($this->form->{$langue}->getElements() as $element) { ?>
     <tr>
-      <td class="i18n_label"><?php echo $element->getLabel(); ?></td>
+      <td class="i18n_label"><?php echo $element->getLabel()
+                                                          . $this->tagAnchor(['action' => 'update-string',
+                                                                              'from' => $element->getLabel()],
+                                                                             $this->tagImg(Class_Admin_Skin::current()->getIconUrl('actions', 'edit'),
+                                                                                           ['style' => 'width: 16px; margin-left: 1em;']),
+                                                                             ['data-popup' => 'true']);
+                             ?></td>
       <td><?php echo $element->removeDecorator('label') ?></td>
     </tr>
   <?php } ?>
@@ -48,4 +54,4 @@ foreach ($this->translated as $langue => $v) { ?>
   </div>
 <?php } ?>
   <?php echo new Zend_Form_Element_Hidden('i18nFormId', array('value' => 1)); ?>
-</form>
\ No newline at end of file
+</form>
diff --git a/library/Class/I18n.php b/library/Class/I18n.php
index 47caa70b308..95970bede53 100644
--- a/library/Class/I18n.php
+++ b/library/Class/I18n.php
@@ -249,6 +249,13 @@ return array(
       $this->_profile_updator->updateString($from, $to);
     }
 
-    return $this->_profile_updator->hasError();
+    return !$this->_profile_updator->hasError();
+  }
+
+
+  public function getErrors() {
+    return $this->_profile_updator
+      ? $this->_profile_updator->getErrors()
+      : [];
   }
 }
\ No newline at end of file
diff --git a/library/Class/Profil/I18n.php b/library/Class/Profil/I18n.php
index a46ecbb9a24..e760bef4f18 100644
--- a/library/Class/Profil/I18n.php
+++ b/library/Class/Profil/I18n.php
@@ -16,18 +16,41 @@
  *
  * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
  * along with BOKEH; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
  */
 class Class_Profil_I18n {
   const VISITABLE_CLASS_KEY = 'visitable';
   const CONFIG_GETTER_KEY = 'configGetter';
 
   /** @var Array */
-  protected static $_knownStringKeys = array(
-    'titre', 'message', 'exemple', 'libelle',
-    'message_carte', 'identifiant', 'mot_de_passe',
-    'facettes_message', 'tags_message', 'barre_nav',
-  );
+  protected static $_knownStringKeys = [
+                                        'titre',
+                                        'titre_connecte',
+                                        'libelle',
+
+                                        'message',
+                                        'message_connecte',
+                                        'intro',
+                                        'exemple',
+                                        'placeholder',
+                                        'message_carte',
+
+                                        'identifiant',
+                                        'identifiant_exemple',
+                                        'mot_de_passe',
+                                        'mot_de_passe_exemple',
+
+                                        'lien_compte',
+                                        'lien_deconnection',
+                                        'lien_connexion',
+                                        'lien_mot_de_passe_oublie',
+                                        'lien_creer_compte',
+                                        'pre-registration',
+                                        'pre_registration',
+
+                                        'facettes_message',
+                                        'tags_message',
+                                        'barre_nav'];
 
   /**
    * @var array
diff --git a/library/Class/Profil/I18nStringUpdator.php b/library/Class/Profil/I18nStringUpdator.php
index 35eed66d428..b169f3162a7 100644
--- a/library/Class/Profil/I18nStringUpdator.php
+++ b/library/Class/Profil/I18nStringUpdator.php
@@ -71,4 +71,9 @@ class Class_Profil_I18nStringUpdator extends Class_Profil_I18n {
   public function hasError() {
     return !empty($this->_errors);
   }
+
+
+  public function getErrors() {
+    return $this->_errors;
+  }
 }
\ No newline at end of file
diff --git a/library/ZendAfi/Form/Admin/I18n/UpdateString.php b/library/ZendAfi/Form/Admin/I18n/UpdateString.php
index 7876336bd45..e535c73c7c6 100644
--- a/library/ZendAfi/Form/Admin/I18n/UpdateString.php
+++ b/library/ZendAfi/Form/Admin/I18n/UpdateString.php
@@ -29,9 +29,12 @@ class ZendAfi_Form_Admin_I18n_UpdateString extends ZendAfi_Form {
                       'from',
                       ['label' => $this->_('Chaîne de caratères à remplacer'),
                        'disabled' => 'disabled'])
+
       ->addElement('text',
                    'to',
-                   ['label' => $this->_('par')])
+                   ['label' => $this->_('par'),
+                    'allowEmpty' => false,
+                    'required' => true])
 
       ->addUniqDisplayGroup('update-string');
   }
diff --git a/tests/application/modules/admin/controllers/I18nControllerTest.php b/tests/application/modules/admin/controllers/I18nControllerTest.php
index da8bdb8b9f8..1e52d902c77 100644
--- a/tests/application/modules/admin/controllers/I18nControllerTest.php
+++ b/tests/application/modules/admin/controllers/I18nControllerTest.php
@@ -156,6 +156,8 @@ class I18nControllerUpdateStringTest extends Admin_AbstractControllerTestCase {
   public function setUp() {
     parent::setUp();
 
+    Class_AdminVar::set('LANGUES', 'fr;en;es');
+
     $profil_8 = $this->fixture('Class_Profil',
                    ['id' => 8]);
 
@@ -169,20 +171,25 @@ class I18nControllerUpdateStringTest extends Admin_AbstractControllerTestCase {
 
     $profil_8->setCfgAccueil($simple_widgets)->save();
     $profil_9->setCfgAccueil($simple_widgets)->save();
+  }
 
 
+  /** @test */
+  public function linkToUpdateStringShouldBePresent() {
+    $this->dispatch('/admin/I18n/index', true);
+    $this->assertXPath('//a[contains(@href, "/admin/I18n/update-string/from/Bienvenue")]', $this->_response->getBody());
   }
 
 
   /** @test */
-  public function dispatchShouldRenderForm() {
+  public function dispatchUpdateStringShouldRenderForm() {
     $this->dispatch('/admin/I18n/update-string/from/Bienvenue', true);
     $this->assertXPath('//form//input[@name="from"]');
   }
 
 
   /** @test */
-  public function afterPostDipatchkiosqueInProfile8TitreShouldBeBienvenido() {
+  public function updateStringPostDipatchkiosqueInProfile8TitreShouldBeBienvenido() {
     $this->postDispatch('/admin/I18n/update-string/from/Bienvenue',
                         ['to' => 'Bienvenido']);
     $widget = (new Class_Systeme_Widget_Widget())
@@ -190,5 +197,8 @@ class I18nControllerUpdateStringTest extends Admin_AbstractControllerTestCase {
       ->setProfileId(8)
       ->load();
     $this->assertEquals('Bienvenido', $widget->gettitre());
+
+    $this->assertRedirect();
+    $this->assertFlashMessengerContentContains('enregistrée');
   }
 }
\ No newline at end of file
-- 
GitLab