From fbf7375fe52c6eff216574ba387f5b34abd66e84 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Mon, 30 Mar 2020 21:10:27 +0200 Subject: [PATCH 1/4] NEW compatibility of translabel with more dict --- htdocs/api/class/api_setup.class.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index 2afca6aedb5..20148205203 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -230,7 +230,7 @@ class Setup extends DolibarrApi if ($country->fetch($obj->rowid) > 0) { // Translate the name of the country if needed // and then apply the filter if there is one. - $this->translateLabel($country, $lang); + $this->translateLabel($country, $lang, 'Country'); if (empty($filter) || stripos($country->label, $filter) !== false) { $list[] = $this->_cleanObjectDatas($country); @@ -318,7 +318,7 @@ class Setup extends DolibarrApi throw new RestException(404, 'country not found'); } - $this->translateLabel($country, $lang); + $this->translateLabel($country, $lang, 'Country'); return $this->_cleanObjectDatas($country); } @@ -403,14 +403,15 @@ class Setup extends DolibarrApi } /** - * Translate the name of the country to the given language. + * Translate the name of the object to the given language. * - * @param Ccountry $country Country - * @param string $lang Code of the language the name of the - * country must be translated to + * @param object $object Object with label to translate + * @param string $lang Code of the language the name of the object must be translated to + * @param string $modprefix Prefix for translation + * * @return void */ - private function translateLabel($country, $lang) + private function translateLabel($object, $lang, $prefix) { if (!empty($lang)) { // Load the translations if this is a new language. @@ -420,11 +421,12 @@ class Setup extends DolibarrApi $this->translations->setDefaultLang($lang); $this->translations->load('dict'); } - if ($country->code) { - $key = 'Country'.$country->code; + if ($object->code) { + $key = $prefix.$object->code; + $translation = $this->translations->trans($key); if ($translation != $key) { - $country->label = html_entity_decode($translation); + $object->label = html_entity_decode($translation); } } } From 74096426365c319fedf896a9fc6c04f1f92cb7d5 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 30 Mar 2020 19:12:29 +0000 Subject: [PATCH 2/4] Fixing style errors. --- htdocs/api/class/api_setup.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index 20148205203..34ad9badc69 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -408,7 +408,7 @@ class Setup extends DolibarrApi * @param object $object Object with label to translate * @param string $lang Code of the language the name of the object must be translated to * @param string $modprefix Prefix for translation - * + * * @return void */ private function translateLabel($object, $lang, $prefix) @@ -423,7 +423,7 @@ class Setup extends DolibarrApi } if ($object->code) { $key = $prefix.$object->code; - + $translation = $this->translations->trans($key); if ($translation != $key) { $object->label = html_entity_decode($translation); From a0c2bc374345578d0d25da519393875ce8a65a04 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 31 Mar 2020 20:52:15 +0200 Subject: [PATCH 3/4] Update api_setup.class.php --- htdocs/api/class/api_setup.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index 34ad9badc69..15493159110 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -407,7 +407,7 @@ class Setup extends DolibarrApi * * @param object $object Object with label to translate * @param string $lang Code of the language the name of the object must be translated to - * @param string $modprefix Prefix for translation + * @param string $prefix Prefix for translation * * @return void */ From a94f8572f1ecdf82b8ff11fe8424b00f42ba99dc Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 2 Apr 2020 12:53:41 +0200 Subject: [PATCH 4/4] Update api_setup.class.php --- htdocs/api/class/api_setup.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index 15493159110..1b619acfeb7 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -407,11 +407,11 @@ class Setup extends DolibarrApi * * @param object $object Object with label to translate * @param string $lang Code of the language the name of the object must be translated to - * @param string $prefix Prefix for translation + * @param string $prefix Prefix for translation key * * @return void */ - private function translateLabel($object, $lang, $prefix) + private function translateLabel($object, $lang, $prefix = 'Country') { if (!empty($lang)) { // Load the translations if this is a new language.