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

Conversation

SultanSagi
Copy link
Contributor

@SultanSagi SultanSagi commented Jun 4, 2024

Related to: https://oat-sa.atlassian.net/browse/AUT-3675

Summary

It makes translations with new prefix

To create and update new local files:

// from Docker container

php  tao/scripts/taoTranslate.php -v -a=create -e=taoQtiItem -l=en-us```

Copy link

github-actions bot commented Jun 4, 2024

Front-end summary Node 18

💯 Total ✅ Passed ⏭️ Skipped ❌ Failed
161 161 0 0

@marpesia marpesia requested review from marpesia and pribi June 4, 2024 10:06
@SultanSagi SultanSagi changed the title AUT-3765: make translation with new prefix draft: AUT-3765: make translation with new prefix Jun 5, 2024
Comment on lines 366 to 374
$pattern = '/' . self::LANG_PREFIX . '$/';
if (!preg_match($pattern, $localeDir, $matches)) {
$path = $localesPath . '/' . $localeDir;
if ($localeDir[0] != '.' && @is_dir($path)) {
// Look if the lang.rdf can be read.
$languageModelFile = $path . '/lang.rdf';
if (@file_exists($languageModelFile) && @is_readable($languageModelFile)) {
$files[] = $languageModelFile;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This may impact existing functionality. I recommend to extract this business logic into different service and unit service. I also recommend when replacing business logic here to use proxy approach maybe including Feature Flag to keep it safe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to clarify what do you mean with Business logic? Only my added if condition or whole logic inside foreach?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I understand this answer. You are adding new business logic into existing service. This will impact other parts of the code that is using models/classes/class.LanguageService.php. You should make sure it will not brake anything and for this you need to isolate impact of your change. I would recommend to create new Sprout class with method getLanguageFiles overloaded.

Comment on lines 294 to 304
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please extract this to exteranal service and unit 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.

fixed

@marpesia
Copy link
Contributor

I'm still confused about mapClassesNames method

Please, re-check again @bartlomiejmarszal

Copy link
Contributor

@bartlomiejmarszal bartlomiejmarszal left a comment

Choose a reason for hiding this comment

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

Missing empty lines on the end of php files

helpers/translation/SolarThemeHelper.php Outdated Show resolved Hide resolved
}
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
}
}

@pribi
Copy link
Contributor

pribi commented Jun 21, 2024

Please resolve the merge conflicts.
image

 Conflicts:
	views/js/loader/vendor.es5.min.js
	views/js/loader/vendor.es5.min.js.map
	views/js/loader/vendor.min.js.map
@marpesia
Copy link
Contributor

Please resolve the merge conflicts. image

Fixed @pribi

*
*/
abstract public 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.

Empty line on the end of line

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link

Version

Target Version 54.15.0
Last version 54.14.6

There are 0 BREAKING CHANGE, 12 features, 1 fix

Copy link
Contributor

Choose a reason for hiding this comment

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

This file change is not well readable. This is just reformatting? Could you skip reformatting for this?

Copy link
Contributor

Choose a reason for hiding this comment

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

There are new code added at the bottom of the array, though.
I can move the first square bracket to the line 29. Is that ok?

* 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

@@ -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?

Comment on lines +31 to +35
public function __construct(
LayoutHelper $layoutHelper
) {
$this->layoutHelper = $layoutHelper;
}
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

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

@@ -107,6 +110,7 @@ class tao_scripts_TaoTranslate extends tao_scripts_Runner
protected $verbose = false;
// --- OPERATIONS ---

private ?AbstractSolarThemeHelper $solarThemeHelper;
Copy link
Contributor

Choose a reason for hiding this comment

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

How this could be null? It is defined in ServiceProvider.

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

@SultanSagi SultanSagi changed the title draft: AUT-3675: make translation with new prefix AUT-3675: make translation with new prefix Jun 21, 2024
*/
private static function checkPrefix(string $language): string
{
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

* Check and Add prefix for Solar design translations
*
*/
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

}

/**
* 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?

@marpesia marpesia closed this Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants