Browse code

[webmail] BM-15081 Fix: folder name translation

David Phan authored on 07/10/2019 07:11:46
Showing 2 changed files
... ...
@@ -37,18 +37,26 @@ class bm_books extends rcube_plugin {
37 37
   private $mailManager;
38 38
 
39 39
   private $contactBMClient;
40
+  private $translatedAddressbooksName;
40 41
 
41 42
   const USERS = 'users';
42 43
   const CONTACTS = 'contacts';
43 44
   const COLLECTED_CONTACTS = 'collected_contacts';
44
-  const DIRECTORY = 'Annuaire'; // fixme bm-core set Annuaire as default name
45 45
 
46 46
   function __construct($api) {
47 47
     parent::__construct($api);
48 48
     $this->add_texts('localization/');
49
-    $this->contactsManager = new bm_contacts_manager();
49
+    $this->setTranslatedAddressbooksName();
50
+    $this->contactsManager = new bm_contacts_manager($this->translatedAddressbooksName);
50 51
     $this->mailManager = new bm_mail_manager($this->contactsManager);
51 52
   }
53
+
54
+
55
+  private function setTranslatedAddressbooksName() {
56
+    $this->translatedAddressbooksName[$this::USERS] = $this->gettext($this::USERS);
57
+    $this->translatedAddressbooksName[$this::CONTACTS] = $this->gettext($this::CONTACTS);
58
+    $this->translatedAddressbooksName[$this::COLLECTED_CONTACTS] = $this->gettext($this::COLLECTED_CONTACTS);
59
+  }
52 60
   
53 61
   public function init() {
54 62
     // global hooks
... ...
@@ -35,11 +35,26 @@ class bm_contacts_manager {
35 35
   private $bmAddressbookIds;
36 36
   private $defaultAddressbook;
37 37
   private $userSubscriptionClient;
38
+  private $translatedAddressbooksName;
38 39
 
39
-  function __construct() {
40
+  function __construct($translatedAddressbooksName) {
40 41
     unset($this->bmAddressbookIds);
42
+    $this->translatedAddressbooksName = $translatedAddressbooksName;
41 43
   }
42 44
 
45
+  private function getAddressbookName($folder) {
46
+    $userUid = $_SESSION['bm_sso']['bmUserId'];
47
+    if ("book:CollectedContacts_".$userUid == $folder->containerUid){
48
+      return $this->translatedAddressbooksName['collected_contacts'];
49
+    } else if ("addressbook_".$_SESSION['bm_sso']['bmDomain'] == $folder->containerUid) {
50
+      return $this->translatedAddressbooksName['users'];
51
+    } else if ("book:Contacts_".$userUid == $folder->containerUid){
52
+      return $this->translatedAddressbooksName['contacts'];
53
+    }
54
+    return $folder->name;
55
+  }
56
+
57
+
43 58
   public function setAddressBookCompletionIds() {
44 59
     $rcmail = rcmail::get_instance();
45 60
     $rcmail->config->set('autocomplete_addressbooks', array(0 => 'bm_autocomp'));
... ...
@@ -99,9 +114,12 @@ class bm_contacts_manager {
99 114
   }
100 115
 
101 116
   public function convertBMFolderToRCFolder($bmFolder) {
117
+
118
+    $this->getAddressbookName($bmFolder);
119
+
102 120
     return array(
103 121
           'id' => (string)$bmFolder->uid,
104
-          'name' => $bmFolder->name,
122
+          'name' => $this->getAddressbookName($bmFolder),
105 123
           'readonly' => $bmFolder->writable ? false : true,
106 124
           'groups' => false
107 125
         );
... ...
@@ -162,7 +180,7 @@ class bm_contacts_manager {
162 180
     $folder = $this->getFolderFromId($addressBook['id']);
163 181
 
164 182
     if(isset($folder)) {
165
-      $addressbook['instance'] = new bm_book($folder->name, $folder, $this);
183
+      $addressbook['instance'] = new bm_book($this->getAddressbookName($folder), $folder, $this);
166 184
     }
167 185
     
168 186
     return $addressbook;