Skip to content

Commit

Permalink
Lara (#3724)
Browse files Browse the repository at this point in the history
* Initial

* Update dependency webpack to v5.96.1 (#3710)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency react-hotkeys-hook to v4.6.1 (#3709)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency eslint-plugin-testing-library to v7 (#3711)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* yarn.lock update

* GetContribution completed

* UI integration

* Fix

* Get/set/analysis completed

* Update yarn.lock

* Add context list to setTranslation request

* Add context list to setTranslation request

* Fixed Engine type in API list

* Configurations submodule

* Updata getContributions parameters

* Lara: update labels

* Fixed tests

* Fixed tests

* Fixed tests

* fixed tests

* Completed Lara integration

* Fixed test

* Added context lists support

* Fixed contexts and Translation responses

* Fixed permissions in TM key election

* Fixed MMT fallback default key

* Added some logging on set

* [Chore] Fix error in log url

* Removed Languages check for set contribution

* Added a simple log to Lara Call

* Improved Lara logs

* Fix:
- MT must not called when performing get contribution as cross language
  matches
- Set contribution on adaptive engines send an object instead of a list
  when there is a read only key

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: riccio82 <[email protected]>
Co-authored-by: pierluigi.dicianni <[email protected]>
Co-authored-by: Mauro Cassani <[email protected]>
  • Loading branch information
5 people authored Jan 7, 2025
1 parent 2eabf19 commit 43ddd87
Show file tree
Hide file tree
Showing 47 changed files with 3,537 additions and 444 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"stevenmaguire/oauth2-microsoft": "^2.2",
"league/oauth2-github": "^3.1",
"league/oauth2-facebook": "^2.2",
"translated/lara-sdk":"^1.0.1",
"psr/log": "~1.0",
"ext-curl": "*",
"ext-pcntl": "*",
Expand Down
50 changes: 47 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docker
6 changes: 5 additions & 1 deletion inc/INIT.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ class INIT {
* @var int Interval in seconds
*/
public static $COPY_SOURCE_INTERVAL = 300;
public static $MAX_NUM_SEGMENTS = 500;

/**
* Default Matecat user agent string
Expand Down Expand Up @@ -205,6 +204,11 @@ class INIT {
*/
public static $DEFAULT_TM_KEY = '';

/**
* @var string The default MMT license is applied when Lara falls back for unsupported languages and the user does not add their personal MMT license.
*/
public static $DEFAULT_MMT_KEY = '';

public static $ENABLED_BROWSERS = [ 'applewebkit', 'chrome', 'safari', 'edge', 'firefox' ];

/**
Expand Down
7 changes: 3 additions & 4 deletions lib/Controller/catController.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,17 @@ public function doAction() {

$active_mt_engine_array = [];
if ( !empty( $active_mt_engine ) ) {
$engine_type = explode("\\", $active_mt_engine[ 0 ]->class_load);
$active_mt_engine_array = [
"id" => $active_mt_engine[ 0 ]->id,
"name" => $active_mt_engine[ 0 ]->name,
"type" => $active_mt_engine[ 0 ]->type,
"description" => $active_mt_engine[ 0 ]->description,
'engine_type' => ( $active_mt_engine[ 0 ]->class_load === 'MyMemory' ? 'MMTLite' : $active_mt_engine[ 0 ]->class_load ),
'engine_type' => ( $active_mt_engine[ 0 ]->class_load === 'MyMemory' ? 'MMTLite' : array_pop($engine_type) ),
];
}

$this->template->active_engine = Utils::escapeJsonEncode( $active_mt_engine_array );
$this->template->active_engine = $active_mt_engine_array;

/*
* array_unique cast EnginesModel_EngineStruct to string
Expand Down Expand Up @@ -380,7 +381,6 @@ public function setTemplateVars() {

$this->template->mt_engines = $this->translation_engines;
$this->template->translation_engines_intento_providers = Intento::getProviderList();
$this->template->translation_engines_intento_prov_json = Utils::escapeJsonEncode( Intento::getProviderList() );

$this->template->not_empty_default_tm_key = !empty( INIT::$DEFAULT_TM_KEY );

Expand Down Expand Up @@ -412,7 +412,6 @@ public function setTemplateVars() {
$this->template->maxTMXFileSize = INIT::$MAX_UPLOAD_TMX_FILE_SIZE;

$this->template->tagLockCustomizable = ( INIT::$UNLOCKABLE_TAGS == true ) ? true : false;
$this->template->maxNumSegments = INIT::$MAX_NUM_SEGMENTS;
$this->template->copySourceInterval = INIT::$COPY_SOURCE_INTERVAL;

/*
Expand Down
98 changes: 74 additions & 24 deletions lib/Controller/engineController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

use EnginesModel\DeepLStruct;
use EnginesModel\LaraStruct;
use Lara\LaraException;
use Users\MetadataDao;
use Utils\Engines\Lara;
use Validator\DeepLValidator;

/**
Expand All @@ -21,7 +25,7 @@ class engineController extends ajaxController {
'add', 'delete', 'execute'
];
private static $allowed_execute_functions = [
// 'letsmt' => [ 'getTermList' ] // letsmt no longer requires this function. it's left as an example
// 'letsmt' => [ 'getTermList' ] // letsmt no longer requires this function. it's left as an example
];

public function __construct() {
Expand Down Expand Up @@ -126,7 +130,7 @@ private function add() {
$newEngineStruct->extra_parameters[ 'DeepL-Auth-Key' ] = $this->engineData[ 'client_id' ];

try {
DeepLValidator::validate($newEngineStruct);
DeepLValidator::validate( $newEngineStruct );
} catch ( Exception $e ) {
$this->result[ 'errors' ][] = [ 'code' => $e->getCode(), 'message' => $e->getMessage() ];

Expand All @@ -143,11 +147,11 @@ private function add() {
*/
$newEngineStruct = EnginesModel_MicrosoftHubStruct::getStruct();

$newEngineStruct->name = $this->name;
$newEngineStruct->uid = $this->user->uid;
$newEngineStruct->type = Constants_Engines::MT;
$newEngineStruct->extra_parameters[ 'client_id' ] = $this->engineData[ 'client_id' ];
$newEngineStruct->extra_parameters[ 'category' ] = $this->engineData[ 'category' ];
$newEngineStruct->name = $this->name;
$newEngineStruct->uid = $this->user->uid;
$newEngineStruct->type = Constants_Engines::MT;
$newEngineStruct->extra_parameters[ 'client_id' ] = $this->engineData[ 'client_id' ];
$newEngineStruct->extra_parameters[ 'category' ] = $this->engineData[ 'category' ];
break;

case strtolower( Constants_Engines::APERTIUM ):
Expand Down Expand Up @@ -221,28 +225,42 @@ private function add() {

break;

case strtolower(Constants_Engines::INTENTO):
case strtolower( Constants_Engines::INTENTO ):
/**
* Create a record of type Intento
*/
$newEngineStruct = EnginesModel_IntentoStruct::getStruct();
$newEngineStruct->name = $this->name;
$newEngineStruct->uid = $this->user->uid;
$newEngineStruct->type = Constants_Engines::MT;
$newEngineStruct->extra_parameters['apikey'] = $this->engineData['secret'];
$newEngineStruct->extra_parameters['provider'] = $this->engineData['provider'];
$newEngineStruct->extra_parameters['providerkey'] = $this->engineData['providerkey'];
$newEngineStruct->extra_parameters['providercategory'] = $this->engineData['providercategory'];
$newEngineStruct = EnginesModel_IntentoStruct::getStruct();
$newEngineStruct->name = $this->name;
$newEngineStruct->uid = $this->user->uid;
$newEngineStruct->type = Constants_Engines::MT;
$newEngineStruct->extra_parameters[ 'apikey' ] = $this->engineData[ 'secret' ];
$newEngineStruct->extra_parameters[ 'provider' ] = $this->engineData[ 'provider' ];
$newEngineStruct->extra_parameters[ 'providerkey' ] = $this->engineData[ 'providerkey' ];
$newEngineStruct->extra_parameters[ 'providercategory' ] = $this->engineData[ 'providercategory' ];
break;

case strtolower( Constants_Engines::LARA ):
/**
* Create a record of type Lara
*/
$newEngineStruct = LaraStruct::getStruct();

$newEngineStruct->uid = $this->user->uid;
$newEngineStruct->type = Constants_Engines::MT;
$newEngineStruct->extra_parameters[ 'Lara-AccessKeyId' ] = $this->engineData[ 'lara-access-key-id' ];
$newEngineStruct->extra_parameters[ 'Lara-AccessKeySecret' ] = $this->engineData[ 'secret' ];
$newEngineStruct->extra_parameters[ 'MMT-License' ] = $this->engineData[ 'mmt-license' ];

break;

default:

// MMT
$validEngine = $newEngineStruct = $this->featureSet->filter( 'buildNewEngineStruct', false, (object)[
'featureSet' => $this->featureSet,
'providerName' => $this->provider,
'logged_user' => $this->user,
'engineData' => $this->engineData
'featureSet' => $this->featureSet,
'providerName' => $this->provider,
'logged_user' => $this->user,
'engineData' => $this->engineData
] );
break;

Expand All @@ -254,14 +272,20 @@ private function add() {
return;
}

$engineList = $this->featureSet->filter( 'getAvailableEnginesListForUser', Constants_Engines::getAvailableEnginesList(), $this->user );
$engineList = Constants_Engines::getAvailableEnginesList();
$UserMetadataDao = new MetadataDao();
$engineEnabled = $UserMetadataDao->get( $this->user->uid, $newEngineStruct->class_load );

if ( !empty( $engineEnabled ) ) {
unset( $engineList[ $newEngineStruct->class_load ] );
}

$engineDAO = new EnginesModel_EngineDAO( Database::obtain() );
$newCreatedDbRowStruct = null;

if ( array_search( $newEngineStruct->class_load, $engineList ) ) {
$newEngineStruct->active = true;
$newCreatedDbRowStruct = $engineDAO->create( $newEngineStruct );
$newCreatedDbRowStruct = $engineDAO->create( $newEngineStruct );
$this->destroyUserEnginesCache();
}

Expand Down Expand Up @@ -311,6 +335,26 @@ private function add() {

return;
}
} elseif ( $newEngineStruct instanceof LaraStruct ) {

/**
* @var $newTestCreatedMT Lara
*/
$newTestCreatedMT = Engine::createTempInstance( $newCreatedDbRowStruct );

try {
$newTestCreatedMT->getAvailableLanguages();
} catch ( LaraException $e ) {
$this->result[ 'errors' ][] = $e->getMessage();
$engineDAO->delete( $newCreatedDbRowStruct );
$this->destroyUserEnginesCache();

return;
}

$UserMetadataDao = new MetadataDao();
$UserMetadataDao->set( $this->user->uid, $newCreatedDbRowStruct->class_load, $newCreatedDbRowStruct->id );

} else {

try {
Expand All @@ -325,11 +369,12 @@ private function add() {

}

$engine_type = explode( "\\", $newCreatedDbRowStruct->class_load );
$this->result[ 'data' ][ 'id' ] = $newCreatedDbRowStruct->id;
$this->result[ 'data' ][ 'name' ] = $newCreatedDbRowStruct->name;
$this->result[ 'data' ][ 'description' ] = $newCreatedDbRowStruct->description;
$this->result[ 'data' ][ 'type' ] = $newCreatedDbRowStruct->type;
$this->result[ 'data' ][ 'engine_type' ] = $newCreatedDbRowStruct->class_load;
$this->result[ 'data' ][ 'engine_type' ] = array_pop( $engine_type );
}

/**
Expand Down Expand Up @@ -359,7 +404,12 @@ private function disable() {
return;
}

$this->featureSet->run( 'postEngineDeletion', $result );
$engine = Engine::createTempInstance( $result );

if ( $engine->isAdaptive() ) {
//retrieve OWNER Engine License
( new MetadataDao() )->delete( $this->user->uid, $result->class_load ); // engine_id
}

$this->result[ 'data' ][ 'id' ] = $result->id;

Expand Down
Loading

0 comments on commit 43ddd87

Please sign in to comment.