Skip to content

Commit

Permalink
remove translations config, translations are now enabled by default (g…
Browse files Browse the repository at this point in the history
  • Loading branch information
orthagh authored Jan 12, 2024
1 parent cde4d9d commit f81ac57
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 108 deletions.
16 changes: 7 additions & 9 deletions ajax/projecttask.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,13 @@
$template = new ProjectTaskTemplate();
$template->getFromDB($_POST['projecttasktemplates_id']);

if (DropdownTranslation::isDropdownTranslationActive()) {
$template->fields['description'] = DropdownTranslation::getTranslatedValue(
$template->getID(),
$template->getType(),
'description',
$_SESSION['glpilanguage'],
$template->fields['description']
);
}
$template->fields['description'] = DropdownTranslation::getTranslatedValue(
$template->getID(),
$template->getType(),
'description',
$_SESSION['glpilanguage'],
$template->fields['description']
);

echo json_encode($template->fields);
}
17 changes: 7 additions & 10 deletions ajax/solution.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,13 @@
// Render template content using twig
$template->fields['content'] = $template->getRenderedContent($parent);
} else {
$content = $template->fields['content'];
if (DropdownTranslation::isDropdownTranslationActive()) {
$content = DropdownTranslation::getTranslatedValue(
$template->getID(),
$template->getType(),
'content',
$_SESSION['glpilanguage'],
$content
);
}
$content = DropdownTranslation::getTranslatedValue(
$template->getID(),
$template->getType(),
'content',
$_SESSION['glpilanguage'],
$template->fields['content']
);
$template->fields['content'] = RichText::getSafeHtml($content);
}

Expand Down
3 changes: 0 additions & 3 deletions install/empty_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,6 @@ public function getEmptyData(): array
'registration_number_ssofield' => '',
'ssovariables_id' => '0',
'ssologout_url' => '',
'translate_kb' => '0',
'translate_dropdowns' => '0',
'translate_reminders' => '0',
'pdffont' => 'dejavusans',
'keep_devices_when_purging_item' => '0',
'maintenance_mode' => '0',
Expand Down
40 changes: 40 additions & 0 deletions install/migrations/update_10.0.x_to_10.1.0/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2024 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

Config::deleteConfigurationValues('core', [
'translate_dropdowns',
'translate_kb',
'translate_reminders',
]);
16 changes: 7 additions & 9 deletions src/AbstractITILChildTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,13 @@ public function getRenderedContent(CommonITILObject $itil_item): string
}

$content = $this->fields['content'];
if (DropdownTranslation::isDropdownTranslationActive()) {
$content = DropdownTranslation::getTranslatedValue(
$this->getID(),
$this->getType(),
'content',
$_SESSION['glpilanguage'],
$content
);
}
$content = DropdownTranslation::getTranslatedValue(
$this->getID(),
$this->getType(),
'content',
$_SESSION['glpilanguage'],
$content
);

$html = TemplateManager::renderContentForCommonITIL(
$itil_item,
Expand Down
12 changes: 11 additions & 1 deletion src/CommonDBTM.php
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,16 @@ protected function deleteChildrenAndRelationsFromDb(array $relations_classes)
}
}

/**
* Is translation enabled for this itemtype
*
* @return true if translation is available, false otherwise
**/
public function maybeTranslated()
{
return false;
}


/**
* Clean translations associated to a dropdown
Expand All @@ -1015,7 +1025,7 @@ public function cleanTranslations()
{

//Do not try to clean is dropdown translation is globally off
if (DropdownTranslation::isDropdownTranslationActive()) {
if ($this->maybeTranslated()) {
$translation = new DropdownTranslation();
$translation->deleteByCriteria(['itemtype' => get_class($this),
'items_id' => $this->getID()
Expand Down
41 changes: 22 additions & 19 deletions src/DropdownTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,12 @@ public static function getTranslatedValue($ID, $itemtype, $field = 'name', $lang
}
//ID > 0 : dropdown item might be translated !
if ($ID > 0) {
$item = new $itemtype();
$item->getFromDB($ID);
if (!$item->maybeTranslated()) {
return $value;
}

//There's at least one translation for this itemtype
if (self::hasItemtypeATranslation($itemtype)) {
$iterator = $DB->request([
Expand Down Expand Up @@ -780,23 +786,22 @@ public static function getTranslationID($ID, $itemtype, $field, $language)
public static function canBeTranslated(CommonGLPI $item)
{

return (self::isDropdownTranslationActive()
&& (($item instanceof CommonDropdown)
&& $item->maybeTranslated()));
return ($item instanceof CommonDropdown) && $item->maybeTranslated();
}


/**
* Is dropdown item translation functionality active
*
* @deprecated 10.1.0
*
* @return true if active, false if not
**/
public static function isDropdownTranslationActive()
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;
Toolbox::deprecated("Dropdown translations are now always active");

return $CFG_GLPI['translate_dropdowns'];
return true;
}


Expand Down Expand Up @@ -905,19 +910,17 @@ public static function getAvailableTranslations($language)
global $DB;

$tab = [];
if (self::isDropdownTranslationActive()) {
$iterator = $DB->request([
'SELECT' => [
'itemtype',
'field'
],
'DISTINCT' => true,
'FROM' => self::getTable(),
'WHERE' => ['language' => $language]
]);
foreach ($iterator as $data) {
$tab[$data['itemtype']][$data['field']] = $data['field'];
}
$iterator = $DB->request([
'SELECT' => [
'itemtype',
'field'
],
'DISTINCT' => true,
'FROM' => self::getTable(),
'WHERE' => ['language' => $language]
]);
foreach ($iterator as $data) {
$tab[$data['itemtype']][$data['field']] = $data['field'];
}
return $tab;
}
Expand Down
20 changes: 4 additions & 16 deletions src/KnowbaseItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -1571,10 +1571,7 @@ public static function getListRequest(array $params, $type = 'search')
}
}

if (
KnowbaseItemTranslation::isKbTranslationActive()
&& (countElementsInTable('glpi_knowbaseitemtranslations') > 0)
) {
if (countElementsInTable('glpi_knowbaseitemtranslations') > 0) {
$criteria['LEFT JOIN']['glpi_knowbaseitemtranslations'] = [
'ON' => [
'glpi_knowbaseitems' => 'id',
Expand Down Expand Up @@ -1621,10 +1618,7 @@ public static function getListRequest(array $params, $type = 'search')
$search_wilcard = self::computeBooleanFullTextSearch($search);

$addscore = [];
if (
KnowbaseItemTranslation::isKbTranslationActive()
&& (countElementsInTable('glpi_knowbaseitemtranslations') > 0)
) {
if (countElementsInTable('glpi_knowbaseitemtranslations') > 0) {
$addscore = [
'glpi_knowbaseitemtranslations.name',
'glpi_knowbaseitemtranslations.answer'
Expand Down Expand Up @@ -1711,10 +1705,7 @@ public static function getListRequest(array $params, $type = 'search')
["glpi_knowbaseitems.name" => ['LIKE', Search::makeTextSearchValue($contains)]],
["glpi_knowbaseitems.answer" => ['LIKE', Search::makeTextSearchValue($contains)]]
];
if (
KnowbaseItemTranslation::isKbTranslationActive()
&& (countElementsInTable('glpi_knowbaseitemtranslations') > 0)
) {
if (countElementsInTable('glpi_knowbaseitemtranslations') > 0) {
$ors[] = ["glpi_knowbaseitemtranslations.name" => ['LIKE', Search::makeTextSearchValue($contains)]];
$ors[] = ["glpi_knowbaseitemtranslations.answer" => ['LIKE', Search::makeTextSearchValue($contains)]];
}
Expand Down Expand Up @@ -2210,10 +2201,7 @@ public static function showRecentPopular(string $type = "", bool $display = true
$criteria['WHERE']['glpi_knowbaseitems.is_faq'] = 1;
}

if (
KnowbaseItemTranslation::isKbTranslationActive()
&& (countElementsInTable('glpi_knowbaseitemtranslations') > 0)
) {
if (countElementsInTable('glpi_knowbaseitemtranslations') > 0) {
$criteria['LEFT JOIN']['glpi_knowbaseitemtranslations'] = [
'ON' => [
'glpi_knowbaseitems' => 'id',
Expand Down
10 changes: 5 additions & 5 deletions src/KnowbaseItemTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,15 @@ public static function getTranslatedValue(KnowbaseItem $item, $field = "name")
/**
* Is kb item translation functionality active
*
* @deprecated 10.1.0
*
* @return true if active, false if not
**/
public static function isKbTranslationActive()
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;
Toolbox::deprecated("KB translations are now always active");

return $CFG_GLPI['translate_kb'];
return true;
}


Expand All @@ -395,8 +396,7 @@ public static function isKbTranslationActive()
public static function canBeTranslated(CommonGLPI $item)
{

return (self::isKbTranslationActive()
&& $item instanceof KnowbaseItem);
return $item instanceof KnowbaseItem;
}


Expand Down
2 changes: 1 addition & 1 deletion src/Reminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ public static function showListForCentral(bool $personal = true, bool $display =
// Do not force the inclusion of reminders created by the current user
unset($public_criteria['WHERE']['glpi_reminders.users_id'], $public_criteria['WHERE']['OR']['glpi_reminders.users_id']);

if (ReminderTranslation::isReminderTranslationActive()) {
if (countElementsInTable('glpi_remindertranslations') > 0) {
$additional_criteria = [
'SELECT' => ["glpi_remindertranslations.name AS transname", "glpi_remindertranslations.text AS transtext"],
'LEFT JOIN' => [
Expand Down
10 changes: 5 additions & 5 deletions src/ReminderTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,15 @@ public static function getTranslatedValue(Reminder $item, $field = "name")
/**
* Is reminder translation functionality active
*
* @deprecated 10.1.0
*
* @return boolean
**/
public static function isReminderTranslationActive()
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;
Toolbox::deprecated("Reminders translations are now always active");

return $CFG_GLPI['translate_reminders'];
return true;
}


Expand All @@ -319,8 +320,7 @@ public static function isReminderTranslationActive()
public static function canBeTranslated(CommonGLPI $item)
{

return (self::isReminderTranslationActive()
&& $item instanceof Reminder);
return ($item instanceof Reminder);
}


Expand Down
30 changes: 0 additions & 30 deletions templates/pages/setup/general/general_setup.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -105,36 +105,6 @@

</div>

<div class="hr-text">
<i class="ti ti-language"></i>
<span>{{ __('Translations') }}</span>
</div>

<div class="row ps-4">

{{ fields.checkboxField(
'translate_dropdowns',
config['translate_dropdowns'],
__("Translation of dropdowns"),
field_options
) }}

{{ fields.checkboxField(
'translate_kb',
config['translate_kb'],
__("Knowledge base translation"),
field_options
) }}

{{ fields.checkboxField(
'translate_reminders',
config['translate_reminders'],
__("Translation of reminders"),
field_options
) }}

</div>

<div class="hr-text">
<i class="ti ti-list"></i>
<span>{{ __('Dynamic display') }}</span>
Expand Down
1 change: 1 addition & 0 deletions tests/functional/OperatingSystemEdition.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protected function getTabs()
{
return [
'OperatingSystemEdition$main' => "<span><i class='ti ti-edit me-2'></i>Edition</span>",
'DropdownTranslation$1' => "<span><i class='ti ti-language me-2'></i>Translations</span>"
];
}

Expand Down

0 comments on commit f81ac57

Please sign in to comment.