Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AUT-3675: make translation with new prefix #4035

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
617b0f9
feat: make translation with new prefix
SultanSagi Jun 4, 2024
5cacb4b
feat: make compile action
SultanSagi Jun 5, 2024
942d2a6
feat: add mapClassesName helper to translate new terms
marpesia Jun 5, 2024
a04e9b1
feat: use helper to map and translate new terms
marpesia Jun 5, 2024
a4e7f5f
feat: map and translate new terms on tree panel
marpesia Jun 5, 2024
e2c8cf2
feat: add new terms locale
marpesia Jun 5, 2024
f015a21
Merge pull request #4037 from oat-sa/feature/AUT-3624/add-new-termino…
marpesia Jun 6, 2024
aa780ee
chore: translate syntax
SultanSagi Jun 7, 2024
b388e44
feat: set translation json regarding lang code
SultanSagi Jun 10, 2024
eabb184
feat: fix test mock
SultanSagi Jun 10, 2024
f429772
fix: test mock
SultanSagi Jun 10, 2024
40a91ba
feat: add condition on RDF render
SultanSagi Jun 10, 2024
3c36d23
feat: add additional check prefix
SultanSagi Jun 11, 2024
fdfb9b8
chore: add missed lab
SultanSagi Jun 11, 2024
522a003
feat: add line-height exception CSS on action-bar title
marpesia Jun 12, 2024
4218c85
chore: bundle CSS
marpesia Jun 12, 2024
e2dfd84
chore: bundle JS
marpesia Jun 12, 2024
c19b6f9
Merge pull request #4043 from oat-sa/feature/AUT-3677/refactor-styles
marpesia Jun 12, 2024
f3d24ac
Merge branch 'develop' into feat/AUT-3675/new-prefix-translate
marpesia Jun 12, 2024
8954b07
chore: fix ClientConfig test
SultanSagi Jun 12, 2024
762b7d7
chore: cleanup
SultanSagi Jun 12, 2024
12aea03
chore: set LayoutHelper in Service Provider
SultanSagi Jun 13, 2024
6e188af
chore: refactor map label function
marpesia Jun 13, 2024
b4c5faa
refactor: extract to Solar theme helper
SultanSagi Jun 14, 2024
8ee971a
chore: remove extra lines
SultanSagi Jun 17, 2024
d28dca7
feat: use common Theme helper
SultanSagi Jun 17, 2024
62d8ffd
Merge branch 'develop' into feat/AUT-3675/new-prefix-translate
marpesia Jun 21, 2024
97a942b
chore: add empty line on AbstractSolarThemeHelper
marpesia Jun 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion actions/class.RdfController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
use oat\generis\model\resource\Contract\ResourceDeleterInterface;
use oat\tao\model\metadata\exception\InconsistencyConfigException;
use oat\tao\model\resources\Exception\PartialClassDeletionException;
use oat\tao\helpers\MapLabelNameService;

/**
* The TaoModule is an abstract controller,
Expand Down Expand Up @@ -467,7 +468,8 @@ public function editClassLabel()
$this->setData('reload', true);
}

$this->setData('formTitle', __('Edit class %s', \tao_helpers_Display::htmlize($class->getLabel())));
$getLabel = MapLabelNameService::mapLabelName($class->getLabel());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you call it as you would call service?

$this->setData('formTitle', __('Edit class %s', tao_helpers_Display::htmlize($getLabel)));
$this->setData('myForm', $myForm->render());
$this->setView('form.tpl', 'tao');
}
Expand Down
41 changes: 41 additions & 0 deletions actions/form/class.Instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use oat\generis\model\OntologyAwareTrait;
use oat\generis\model\OntologyRdfs;
use oat\oatbox\service\ServiceManager;
use oat\tao\helpers\Layout;
use oat\tao\helpers\form\ElementMapFactory;
use oat\tao\helpers\form\elements\ElementValue;
use oat\tao\model\form\DataProvider\FormDataProviderInterface;
Expand All @@ -45,6 +46,7 @@ class tao_actions_form_Instance extends tao_actions_form_Generis

public const EXCLUDED_PROPERTIES = 'excludedProperties';

public const LANG_PREFIX = '-S';
/**
* Initialize the form
*
Expand Down Expand Up @@ -91,6 +93,7 @@ protected function initElements()
} catch (common_exception_Error $exception) {
$language = DEFAULT_LANG;
}
$language = $this->checkPrefix($language);

$topClass = $this->getTopClazz();

Expand Down Expand Up @@ -227,4 +230,42 @@ private function isEmptyLabel($element): bool
return $element instanceof tao_helpers_form_elements_Label
&& empty($element->getRawValue());
}

/**
* Check if the Solar design is enabled and the prefix has not yet been added
*
*/
private function isContainPrefix(string $language): bool
{
$pattern = '/' . self::LANG_PREFIX . '$/';


return !Layout::isSolarDesignEnabled() || preg_match($pattern, $language, $matches);
}

/**
* Concatenate prefix for Solar design translations
*
*/
private function addPrefix(string $language): string
{
return $language . self::LANG_PREFIX;
}

/**
* Check and Add prefix for Solar design translations
*
*/
private function checkPrefix(string $language): string
{
if (!$this->isContainPrefix($language)) {
$localesDir = 'views/locales';
$dir = dirname(__FILE__) . '/../../' . $localesDir . '/' . $this->addPrefix($language);
if (is_dir($dir)) {
$language = $this->addPrefix($language);
}
}

return $language;
}
}
31 changes: 31 additions & 0 deletions helpers/LayoutHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* 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; under version 2
* of the License (non-upgradable).
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA;
*
*
*/

namespace oat\tao\helpers;

class LayoutHelper
{
public function isSolarDesignEnabled(): bool
bartlomiejmarszal marked this conversation as resolved.
Show resolved Hide resolved
{
return Layout::isSolarDesignEnabled();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some kind o proxy? I could not find this reference

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was problematic to test a static method. So I wrapped it in the LayoutHelper class

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it was less problematic when wrapped? Where have you test it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I didn't add new test, but it triggers here ClientConfigStorageTest.php

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a Mock?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How could you test a class by mocking it only?

}
}
15 changes: 14 additions & 1 deletion helpers/ServiceProvider/HelperServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2023 (original work) Open Assessment Technologies SA.
* Copyright (c) 2023-2024 (original work) Open Assessment Technologies SA.
*
* @author Andrei Shapiro <andrei.shapiro@taotesting.com>
*/
Expand All @@ -26,6 +26,8 @@

use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface;
use oat\tao\helpers\dateFormatter\DateFormatterFactory;
use oat\tao\helpers\LayoutHelper;
use oat\tao\helpers\translation\SolarThemeFileHelper;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use tao_helpers_Mode;

Expand All @@ -38,5 +40,16 @@ public function __invoke(ContainerConfigurator $configurator): void
$services->set(DateFormatterFactory::class, DateFormatterFactory::class);

$services->set(tao_helpers_Mode::class, tao_helpers_Mode::class);

$services->set(LayoutHelper::class, LayoutHelper::class);

$services
->set(SolarThemeFileHelper::class, SolarThemeFileHelper::class)
->public()
->args(
[
service(LayoutHelper::class)
]
);
}
}
1 change: 1 addition & 0 deletions helpers/class.Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,5 @@ private static function getApplicationService(): ApplicationService
/** @noinspection PhpIncompatibleReturnTypeInspection */
return ServiceManager::getServiceManager()->get(ApplicationService::SERVICE_ID);
}

}
47 changes: 46 additions & 1 deletion helpers/class.I18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

use oat\generis\model\OntologyRdf;
use oat\tao\helpers\Layout;

/**
* Internationalization helper.
Expand All @@ -40,6 +41,12 @@ class tao_helpers_I18n
*/
public const AVAILABLE_LANGS_CACHEKEY = 'i18n_available_langs';

/**
* locale prefix for New theme
*
*/
public const LANG_PREFIX = '-S';

/**
* Short description of attribute availableLangs
*
Expand All @@ -60,6 +67,7 @@ public static function init(common_ext_Extension $extension, ?string $langCode):
if (empty($langCode)) {
throw new Exception("Language is not defined");
}
$langCode = self::checkPrefix($langCode);

//init the ClearFw l10n tools
$translations = tao_models_classes_LanguageService::singleton()->getServerBundle($langCode);
Expand All @@ -78,7 +86,7 @@ public static function init(common_ext_Extension $extension, ?string $langCode):
*/
public static function getLangCode()
{
return common_session_SessionManager::getSession()->getInterfaceLanguage();
return self::checkPrefix(common_session_SessionManager::getSession()->getInterfaceLanguage());
}

/**
Expand Down Expand Up @@ -193,4 +201,41 @@ public static function getAvailableLangsByUsage(core_kernel_classes_Resource $us
}
return $returnValue;
}

/**
* Check if the Solar design is enabled and the prefix has not yet been added
*
*/
private static function isContainPrefix(string $language): bool
{
$pattern = '/' . self::LANG_PREFIX . '$/';

return !Layout::isSolarDesignEnabled() || preg_match($pattern, $language, $matches);
}

/**
* Concatenate prefix for Solar design translations
*
*/
private static function addPrefix(string $language): string
{
return $language . self::LANG_PREFIX;
}

/**
* Check and Add prefix for Solar design translations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this check about? If I check something and it fails I throw an error and you seem to modify return

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the ticket there is a condition to check for a new translation, if there is no new translation then use a normal translation. That's why I check via is_dir. If the comment doesn't fit, is there any suggestion on how to change it?

*
*/
private static function checkPrefix(string $language): string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it static?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this class itself initiates statically. It's not using construct method

{
if (!self::isContainPrefix($language)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be under feature flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feature flag is called inside isContainPrefix

$localesDir = 'views/locales';
$dir = dirname(__FILE__) . '/../' . $localesDir . '/' . self::addPrefix($language);
if (is_dir($dir)) {
$language = self::addPrefix($language);
}
}

return $language;
}
}
52 changes: 52 additions & 0 deletions helpers/mapLabelNameService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/**
* 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; under version 2
* of the License (non-upgradable).
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA ;
*/

namespace oat\tao\helpers;
use oat\tao\helpers\Layout;

class MapLabelNameService
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not understand purpose of this class

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several places in the UI take the Label name from the PHP code. To set the correct Label for the translation, I need to map the PHP names with the translation IDs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you point me the UI that will be impacted by your change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was reviewing this with @pribi and I think I understand purpose of this.
Looking into usage of actions/class.RdfController.php you will make a change translation for Items.
Screenshot 2024-06-21 at 14 56 00
I understand that Items now should be renamed? WIll we rename root class Item? Do we want to apply this change everywhere? To each client and each instance?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that the new name is ONLY when the SolarUI Theme is applied.
Shall we continue these comments on the new PRs?
Locales only -> #4052
BE logic -> #4053
BE to change FE -> #4054
CSS FE fix -> #4055

{

private const ITEM = 'Item';
private const MEDIA = 'Media';
private const DELIVERY = 'Delivery';
private const ASSETS = 'Assets';

// New terms for isSolarDesignEnabled FF
private $mapLabelNames = [
self::ITEM => 'Item',
self::MEDIA => 'Asset',
self::DELIVERY => 'Delivery',
self::ASSETS => 'Asset'
];

/**
* @param $labelName
* @return string
*/
public function mapLabelName(string $labelName): string
{
$mapName = $labelName;
pribi marked this conversation as resolved.
Show resolved Hide resolved
if (Layout::isSolarDesignEnabled()) {
$mapName = __(self::$mapLabelNames[$labelName]);
}
return $mapName;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

62 changes: 62 additions & 0 deletions helpers/translation/AbstractSolarThemeHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/**
* 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; under version 2
* of the License (non-upgradable).
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA ;
*/

namespace oat\tao\helpers\translation;

use oat\tao\helpers\LayoutHelper;

abstract class AbstractSolarThemeHelper
{
public const LANG_PREFIX = '-S';

private LayoutHelper $layoutHelper;

public function __construct(
LayoutHelper $layoutHelper
) {
$this->layoutHelper = $layoutHelper;
}
Comment on lines +31 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function __construct(
LayoutHelper $layoutHelper
) {
$this->layoutHelper = $layoutHelper;
}
public function __construct(LayoutHelper $layoutHelper) {
$this->layoutHelper = $layoutHelper;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


/**
* Check if the Solar design is enabled and the prefix has not yet been added
*
*/
public function isContainPrefix(string $language): bool
{
$pattern = '/' . self::LANG_PREFIX . '$/';

return !$this->layoutHelper->isSolarDesignEnabled() || preg_match($pattern, $language, $matches);
}

/**
* Concatenate prefix for Solar design translations
*
*/
protected function addPrefix(string $language): string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You actually adding postfix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

{
return $language . self::LANG_PREFIX;
}

/**
* Check and add prefix for Solar design translations
*
*/
abstract public function checkPrefix(string $language): string;
}
41 changes: 41 additions & 0 deletions helpers/translation/SolarThemeFileHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* 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; under version 2
* of the License (non-upgradable).
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2024 (original work) Open Assessment Technologies SA ;
*/

namespace oat\tao\helpers\translation;

class SolarThemeFileHelper extends AbstractSolarThemeHelper
{
/**
* Check and add prefix for Solar design translations
*
*/
public function checkPrefix(string $language): string
{
if (!$this->isContainPrefix($language)) {
$localesDir = 'views/locales';
$dir = dirname(__FILE__) . '/../../' . $localesDir . '/' . $this->addPrefix($language);
if (is_dir($dir)) {
$language = $this->addPrefix($language);
}
}

return $language;
}
}
Loading
Loading