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

Lara #3724

Open
wants to merge 40 commits into
base: develop
Choose a base branch
from
Open

Lara #3724

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
dc84481
Initial
Ostico Dec 2, 2024
6328e4e
Update dependency webpack to v5.96.1 (#3710)
renovate[bot] Dec 2, 2024
9b43447
Update dependency react-hotkeys-hook to v4.6.1 (#3709)
renovate[bot] Dec 2, 2024
51040ae
Update dependency eslint-plugin-testing-library to v7 (#3711)
renovate[bot] Dec 2, 2024
ce48ca7
yarn.lock update
riccio82 Dec 2, 2024
5a7b326
Merge branch 'develop' into lara
Ostico Dec 4, 2024
330a87c
GetContribution completed
Ostico Dec 6, 2024
c2c9bcf
UI integration
piedicianni Dec 10, 2024
a0da653
Merge branch 'develop' into lara
Ostico Dec 10, 2024
765a057
Merge branch 'lara' of github.com:matecat/MateCat into lara
Ostico Dec 10, 2024
44640bc
Fix
piedicianni Dec 10, 2024
12070c2
Get/set/analysis completed
Ostico Dec 10, 2024
1a4e157
Merge branch 'lara' of github.com:matecat/MateCat into lara
Ostico Dec 10, 2024
d321615
Merge remote-tracking branch 'origin/develop' into lara
riccio82 Dec 12, 2024
48a47af
Update yarn.lock
riccio82 Dec 12, 2024
cb9a2fa
Add context list to setTranslation request
riccio82 Dec 12, 2024
5885b3b
Add context list to setTranslation request
riccio82 Dec 12, 2024
d3b8b58
Fixed Engine type in API list
Ostico Dec 17, 2024
e09f241
Configurations submodule
Ostico Dec 17, 2024
d1d7d33
Updata getContributions parameters
riccio82 Dec 13, 2024
862d861
Merge branch 'develop' into lara
riccio82 Dec 17, 2024
62eda8a
Lara: update labels
riccio82 Dec 17, 2024
2d647b8
Fixed tests
mauretto78 Dec 17, 2024
d4f9d5a
Merge branch 'lara' of github.com:matecat/MateCat into lara
mauretto78 Dec 17, 2024
b9ec481
Fixed tests
mauretto78 Dec 17, 2024
a4d87a9
Fixed tests
mauretto78 Dec 17, 2024
48ea765
fixed tests
mauretto78 Dec 17, 2024
5b3bfc2
Completed Lara integration
Ostico Dec 20, 2024
fed45ba
Fixed test
Ostico Dec 20, 2024
56ba940
Added context lists support
Ostico Dec 20, 2024
7845984
Fixed contexts and Translation responses
Ostico Dec 23, 2024
d823447
Fixed permissions in TM key election
Ostico Dec 30, 2024
ba5360a
Fixed MMT fallback default key
Ostico Dec 30, 2024
81deea3
Added some logging on set
Ostico Dec 30, 2024
3e49a51
[Chore] Fix error in log url
Ostico Dec 30, 2024
0e4b25d
Removed Languages check for set contribution
Ostico Dec 30, 2024
d448cad
Merge branch 'develop' into lara
Ostico Dec 30, 2024
78bf7f2
Added a simple log to Lara Call
Ostico Jan 3, 2025
35cc3a4
Improved Lara logs
Ostico Jan 3, 2025
3198ad9
Fix:
Ostico Jan 3, 2025
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
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