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

Feat/aut 3675/add support to solar UI locales #4053

Merged
merged 53 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d1ceaf6
feat: make translation with new prefix
SultanSagi Jun 4, 2024
9d2a76e
feat: make compile action
SultanSagi Jun 5, 2024
b09dfe4
chore: translate syntax
SultanSagi Jun 7, 2024
d64a7f9
feat: set translation json regarding lang code
SultanSagi Jun 10, 2024
4dcea5d
feat: fix test mock
SultanSagi Jun 10, 2024
5f99bd2
fix: test mock
SultanSagi Jun 10, 2024
2f17951
feat: add condition on RDF render
SultanSagi Jun 10, 2024
c6bceef
feat: add additional check prefix
SultanSagi Jun 11, 2024
3a02685
chore: add missed lab
SultanSagi Jun 11, 2024
8a840f4
chore: fix ClientConfig test
SultanSagi Jun 12, 2024
4205a8e
chore: cleanup
SultanSagi Jun 12, 2024
8030e1a
chore: set LayoutHelper in Service Provider
SultanSagi Jun 13, 2024
52c0758
refactor: extract to Solar theme helper
SultanSagi Jun 14, 2024
22ed38c
chore: remove extra lines
SultanSagi Jun 17, 2024
535be0d
feat: use common Theme helper
SultanSagi Jun 17, 2024
ca8fdae
feat: add mapClassesName helper to translate new terms
marpesia Jun 5, 2024
a979c09
feat: use helper to map and translate new terms
marpesia Jun 5, 2024
6b51f03
feat: map and translate new terms on tree panel
marpesia Jun 5, 2024
1c02188
feat: add line-height exception CSS on action-bar title
marpesia Jun 12, 2024
5e788c3
chore: bundle files
marpesia Jun 21, 2024
90dda0f
chore: refactor map label function
marpesia Jun 13, 2024
dd08d54
chore: add empty line on AbstractSolarThemeHelper
marpesia Jun 21, 2024
d2d63da
fix: set to postfix
SultanSagi Jun 21, 2024
e17fcae
chore: refactor function for testing purposes
marpesia Jun 21, 2024
4b9d5be
chore: format files
marpesia Jun 21, 2024
8ac6f88
fix: add LocaleFilesHelper
SultanSagi Jun 21, 2024
5ba52bf
chore: fix format
marpesia Jun 21, 2024
b0d4c28
fix: mock method in clientConfig
SultanSagi Jun 21, 2024
c3b82df
chore: add line at end of file
SultanSagi Jun 21, 2024
db0c0d8
chore: add line at end of file
SultanSagi Jun 21, 2024
200cea9
chore: add line at end of file
SultanSagi Jun 21, 2024
574af43
chore: use assertTrue in test
SultanSagi Jun 21, 2024
3b2dcbc
fix: remane file helpers/mapLabelNameService.php -> helpers/MapLabelN…
Jun 22, 2024
1738637
fix: AUT-3624 code formatting
Jun 22, 2024
b9e86a8
Update helpers/ServiceProvider/HelperServiceProvider.php
pribi Jun 22, 2024
d5411c8
chore: add import blank line
SultanSagi Jun 23, 2024
2a1e477
chore: move up postfix check condition
SultanSagi Jul 11, 2024
c550fd2
chore: refactor Solar helper
SultanSagi Jul 11, 2024
ccf1f48
chore: use static method
SultanSagi Jul 11, 2024
ced1e9b
chore: fix lint
SultanSagi Jul 11, 2024
400d6b8
chore: remove test
SultanSagi Jul 12, 2024
a6bdd4d
chore: refactor checkPostfix
SultanSagi Jul 12, 2024
53bf5d5
chore: remove unused imports
SultanSagi Jul 12, 2024
6df1ba6
chore: fix eslint
SultanSagi Jul 12, 2024
5923308
refactor: use Solar theme interface instead of abstract
SultanSagi Jul 12, 2024
a3fba28
chore: remove suppressor
SultanSagi Jul 12, 2024
2650027
Merge pull request #4055 from oat-sa/feature/AUT-3624/fix-CSS-SolarUI
marpesia Jul 13, 2024
028d792
chore: fix isValidDirectory argument type
SultanSagi Jul 15, 2024
77c9ee0
Merge pull request #4054 from oat-sa/feature/AUT-3624/add-translation…
SultanSagi Jul 16, 2024
0a3ea66
Merge branch 'develop' into feat/AUT-3675/add-support-to-SolarUI-locales
marpesia Jul 31, 2024
2e07760
Merge branch 'develop' into feat/AUT-3675/add-support-to-SolarUI-locales
marpesia Aug 1, 2024
3cec69d
chore: indent line
SultanSagi Aug 1, 2024
844576e
chore: remove blank line
SultanSagi Aug 1, 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
3 changes: 2 additions & 1 deletion actions/form/class.Instance.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use oat\oatbox\service\ServiceManager;
use oat\tao\helpers\form\ElementMapFactory;
use oat\tao\helpers\form\elements\ElementValue;
use oat\tao\helpers\LocaleFilesHelper;
use oat\tao\model\form\DataProvider\FormDataProviderInterface;
use oat\tao\model\form\DataProvider\ProxyFormDataProvider;
use Zend\ServiceManager\ServiceLocatorInterface;
Expand All @@ -44,7 +45,6 @@ class tao_actions_form_Instance extends tao_actions_form_Generis
use OntologyAwareTrait;

public const EXCLUDED_PROPERTIES = 'excludedProperties';

/**
* Initialize the form
*
Expand Down Expand Up @@ -91,6 +91,7 @@ protected function initElements()
} catch (common_exception_Error $exception) {
$language = DEFAULT_LANG;
}
$language = LocaleFilesHelper::checkPostfixDirectory($language);

$topClass = $this->getTopClazz();

Expand Down
29 changes: 29 additions & 0 deletions helpers/LayoutHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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
{
return Layout::isSolarDesignEnabled();
}
}
bartlomiejmarszal marked this conversation as resolved.
Show resolved Hide resolved
78 changes: 78 additions & 0 deletions helpers/LocaleFilesHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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 LocaleFilesHelper
{
public const LANG_POSTFIX = '-S';

/**
* Check if the Solar design is enabled and the postfix has not yet been added
*/
public static function isContainPostfix(string $language): bool
{
$pattern = sprintf('/%s$/', self::LANG_POSTFIX);

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

/**
* Concatenate postfix for Solar design translations
*/
protected static function addPostfix(string $language): string
{
return $language . self::LANG_POSTFIX;
}

/**
* Check and add postfix for Solar design translations
*/
public static function checkPostfix(string $language): string
{
if (!self::isContainPostfix($language)) {
$language = self::addPostfix($language);
}

return $language;
}

/**
* Check and add postfix for Solar design translations
*/
public static function checkPostfixDirectory(string $language): string
{
if (self::isContainPostfix($language)) {
return $language;
}
$localesDir = 'views/locales';
$dir = sprintf('%s/../%s/%s', dirname(__FILE__), $localesDir, self::addPostfix($language));
if (is_dir($dir)) {
return self::addPostfix($language);
}

return $language;
}

public static function isPostfixApplied($localeDir, $pattern = null): bool
{
return null !== $pattern && preg_match($pattern, $localeDir) === 1;
}
}
7 changes: 6 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,9 +26,12 @@

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

pribi marked this conversation as resolved.
Show resolved Hide resolved
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

class HelperServiceProvider implements ContainerServiceProviderInterface
{
public function __invoke(ContainerConfigurator $configurator): void
Expand All @@ -38,5 +41,7 @@ public function __invoke(ContainerConfigurator $configurator): void
$services->set(DateFormatterFactory::class, DateFormatterFactory::class);

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

$services->set(SolarThemeFileHelper::class, SolarThemeFileHelper::class);
}
}
6 changes: 5 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\LocaleFilesHelper;

/**
* Internationalization helper.
Expand Down Expand Up @@ -60,6 +61,7 @@ public static function init(common_ext_Extension $extension, ?string $langCode):
if (empty($langCode)) {
throw new Exception("Language is not defined");
}
$langCode = LocaleFilesHelper::checkPostfixDirectory($langCode);

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

/**
Expand Down
35 changes: 35 additions & 0 deletions helpers/translation/SolarThemeFileHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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\LocaleFilesHelper;

class SolarThemeFileHelper implements SolarThemeHelperInterface
{
/**
* Check and add postfix for Solar design translations
*
*/
public function checkPostfix(string $language): string
{
return LocaleFilesHelper::checkPostfixDirectory($language);
}
}
34 changes: 34 additions & 0 deletions helpers/translation/SolarThemeHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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\LocaleFilesHelper;

class SolarThemeHelper implements SolarThemeHelperInterface
{
/**
* Check and add postfix for Solar design translations
*/
public function checkPostfix(string $language): string
{
return LocaleFilesHelper::checkPostfix($language);
}
}
30 changes: 30 additions & 0 deletions helpers/translation/SolarThemeHelperInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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;

interface SolarThemeHelperInterface
{
/**
* Check and add postfix for Solar design translations
*
*/
public function checkPostfix(string $language): string;
}
26 changes: 23 additions & 3 deletions models/classes/class.LanguageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/

use oat\generis\model\OntologyRdf;
use oat\tao\helpers\LocaleFilesHelper;
use oat\tao\helpers\translation\TranslationBundle;
use oat\generis\model\data\ModelManager;
use oat\tao\helpers\translation\rdf\RdfPack;
Expand Down Expand Up @@ -52,6 +53,7 @@ class tao_models_classes_LanguageService extends tao_models_classes_GenerisServi
public const INSTANCE_ORIENTATION_LTR = 'http://www.tao.lu/Ontologies/TAO.rdf#OrientationLeftToRight';
public const INSTANCE_ORIENTATION_RTL = 'http://www.tao.lu/Ontologies/TAO.rdf#OrientationRightToLeft';
// --- OPERATIONS ---
public const LANG_POSTFIX = '-S';

/**
* Short description of method createLanguage
Expand Down Expand Up @@ -351,7 +353,7 @@ public static function getExistingLanguageUri($value)
*
* @return array of ns => files
*/
private function getLanguageFiles()
private function getLanguageFiles($pattern = null)
{
$extManager = $this->getServiceLocator()->get(common_ext_ExtensionsManager::SERVICE_ID);
$localesPath = $extManager->getExtensionById('tao')->getDir() . 'locales';
Expand All @@ -363,7 +365,7 @@ private function getLanguageFiles()
$localeDirectories = scandir($localesPath);
foreach ($localeDirectories as $localeDir) {
$path = $localesPath . '/' . $localeDir;
if ($localeDir[0] != '.' && @is_dir($path)) {
if ($this->isValidDirectory($path, $localeDir, $pattern)) {
// Look if the lang.rdf can be read.
$languageModelFile = $path . '/lang.rdf';
if (@file_exists($languageModelFile) && @is_readable($languageModelFile)) {
Expand All @@ -374,14 +376,32 @@ private function getLanguageFiles()
return $files;
}


/**
* Check the path is directory
*/
private function isDirectory(string $path, array $localeDir): bool
{
return $localeDir[0] != '.' && @is_dir($path);
}
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
private function isDirectory(string $path, array $localeDir): bool
{
return $localeDir[0] != '.' && @is_dir($path);
}
private function isDirectory(string $path, array $localeDir): bool
{
if (!isset($localeDir[0])) {
return false;
}
if ($localeDir[0] == '.') {
return false;
}
if (!is_dir($path)) {
return false;
}
return true;
}


/**
* Check the directory is valid
*/
private function isValidDirectory(string $path, array $localeDir, string $pattern): bool
{
return $this->isDirectory($path, $localeDir) && !LocaleFilesHelper::isPostfixApplied($localeDir, $pattern);
}

/**
* Return the definition of the languages as an RDF iterator
* @return AppendIterator
*/
public function getLanguageDefinition()
{
$model = new AppendIterator();
foreach ($this->getLanguageFiles() as $rdfPath) {
$pattern = sprintf('/%s$/', self::LANG_POSTFIX);
foreach ($this->getLanguageFiles($pattern) as $rdfPath) {
$iterator = new FileIterator($rdfPath);
$model->append($iterator->getIterator());
}
Expand Down
4 changes: 3 additions & 1 deletion models/classes/clientConfig/ClientConfigServiceProvider.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 @@ -30,6 +30,7 @@
use oat\oatbox\session\SessionService;
use oat\oatbox\user\UserLanguageServiceInterface;
use oat\tao\helpers\dateFormatter\DateFormatterFactory;
use oat\tao\helpers\translation\SolarThemeFileHelper;
use oat\tao\model\asset\AssetService;
use oat\tao\model\ClientLibRegistry;
use oat\tao\model\featureFlag\FeatureFlagConfigSwitcher;
Expand Down Expand Up @@ -67,6 +68,7 @@ public function __invoke(ContainerConfigurator $configurator): void
service(tao_helpers_Mode::class),
service(DateFormatterFactory::class),
service(MenuService::class),
service(SolarThemeFileHelper::class),
]
);
}
Expand Down
Loading
Loading