Skip to content

Commit 62a93e2

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 16720ba + 8114499 commit 62a93e2

File tree

106 files changed

+2358
-8538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+2358
-8538
lines changed

docker

lib/Controller/API/V2/ChangeProjectNameController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace API\V2;
44

55
use API\Commons\Validators\LoginValidator;
6+
use API\Commons\Validators\ProjectAccessValidator;
67
use API\Commons\Validators\ProjectPasswordValidator;
78
use CatUtils;
89
use Database;
@@ -60,7 +61,12 @@ public function changeName()
6061
}
6162

6263
try {
64+
$this->validator->validate();
65+
( new ProjectAccessValidator( $this, $this->validator->getProject() ) )->validate();
66+
$ownerEmail = $this->validator->getProject()->id_customer;
67+
6368
$this->changeProjectName($id, $password, $name);
69+
$this->featureSet->filter( 'filterProjectNameModified', $id, $name, $password, $ownerEmail );
6470

6571
$this->response->status()->setCode(200);
6672
$this->response->json( [

lib/Controller/engineController.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,50 @@ private function add() {
320320
return;
321321
}
322322

323+
} elseif( $newEngineStruct instanceof EnginesModel_IntentoStruct ){
324+
325+
$newTestCreatedMT = Engine::createTempInstance( $newCreatedDbRowStruct );
326+
$config = $newTestCreatedMT->getEngineRecord()->getExtraParamsAsArray();
327+
$config[ 'segment' ] = "Hello World";
328+
$config[ 'source' ] = "en-US";
329+
$config[ 'target' ] = "fr-FR";
330+
331+
$mt_result = $newTestCreatedMT->get( $config );
332+
333+
if ( isset( $mt_result[ 'error' ][ 'code' ] ) ) {
334+
335+
switch ($mt_result[ 'error' ][ 'code' ]){
336+
337+
// wrong provider credentials
338+
case -2:
339+
$this->result[ 'errors' ][] = [
340+
'code' => $mt_result[ 'error' ][ 'http_code' ] ?? 413,
341+
'message' => $mt_result[ 'error' ][ 'message' ]
342+
];
343+
break;
344+
345+
// not valid license
346+
case -403:
347+
$this->result[ 'errors' ][] = [
348+
'code' => 413,
349+
'message' => "The Intento license you entered cannot be used inside CAT tools. Please subscribe to a suitable license to start using Intento as MT engine."
350+
];
351+
break;
352+
353+
default:
354+
$this->result[ 'errors' ][] = [
355+
'code' => 500,
356+
'message' => "Intento license not valid, please verify its validity and try again"
357+
];
358+
break;
359+
}
360+
361+
$engineDAO->delete( $newCreatedDbRowStruct );
362+
$this->destroyUserEnginesCache();
363+
364+
return;
365+
}
366+
323367
} elseif ( $newEngineStruct instanceof EnginesModel_GoogleTranslateStruct ) {
324368

325369
$newTestCreatedMT = Engine::createTempInstance( $newCreatedDbRowStruct );

lib/Model/ConversionHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ private function formatConversionFailureMessage( $message ) {
321321
return 'Scanned file conversion issue, please convert it to editable format (e.g. docx) and retry upload';
322322
}
323323

324-
return 'File conversion issue, please contact us at <a href="mailto:support@matecat.com">support@matecat.com</a>';
324+
return 'File conversion issue, please contact us at support@matecat.com';
325325
}
326326

327327
return $message;

lib/Utils/Engines/Intento.php

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,24 @@ class Engines_Intento extends Engines_AbstractEngine {
1212
'target' => null
1313
];
1414

15+
private $apiKey;
16+
private $provider = [];
17+
private $providerKey;
18+
private $providerCategory;
19+
1520
public function __construct( $engineRecord ) {
1621
parent::__construct( $engineRecord );
22+
1723
if ( $this->getEngineRecord()->type != Constants_Engines::MT ) {
1824
throw new Exception( "Engine {$this->getEngineRecord()->id} is not a MT engine, found {$this->getEngineRecord()->type} -> {$this->getEngineRecord()->class_load}" );
1925
}
26+
27+
$extra = $engineRecord->getExtraParamsAsArray();
28+
29+
$this->apiKey = $extra['apikey'] ?? null;
30+
$this->provider = $extra['provider'] ?? [];
31+
$this->providerKey = $extra['providerkey'] ?? null;
32+
$this->providerCategory = $extra['providercategory'] ?? null;
2033
}
2134

2235
/**
@@ -40,32 +53,39 @@ protected function _fixLangCode( $lang ) {
4053
* @throws Exception
4154
*/
4255
protected function _decode( $rawValue, $parameters = null, $function = null ) {
43-
$all_args = func_get_args();
56+
4457
if ( is_string( $rawValue ) ) {
4558
$result = json_decode( $rawValue, false );
59+
4660
if ( $result and isset( $result->id ) ) {
4761
$id = $result->id;
48-
if ( isset( $result->response ) and isset( $result->done ) and $result->done == true ) {
62+
63+
if ( isset( $result->response ) and !empty($result->response) and isset( $result->done ) and $result->done == true ) {
4964
$text = $result->response[ 0 ]->results[ 0 ];
5065
$decoded = [
51-
'data' => [
52-
'translations' => [
53-
[ 'translatedText' => $text ]
54-
]
66+
'data' => [
67+
'translations' => [
68+
[ 'translatedText' => $text ]
5569
]
70+
]
5671
];
5772

5873
} elseif ( isset( $result->done ) and $result->done == false ) {
5974
sleep( 2 );
6075
$cnf = [ 'async' => true, 'id' => $id ];
6176

6277
return $this->_curl_async( $cnf, $parameters, $function );
63-
} elseif ( isset( $result->error ) and $result->error != null ) {
78+
} elseif ( isset( $result->error ) and !empty($result->error) ) {
79+
80+
$httpCode = $result->error->data[0]->response->body->error->code ?? 500;
81+
$message = $result->error->data[0]->response->body->error->message ?? $result->error->reason ?? "Unknown error";
82+
6483
$decoded = [
65-
'error' => [
66-
'code' => '-2',
67-
'message' => $result->error->reason
68-
]
84+
'error' => [
85+
'code' => -2,
86+
'message' => $message,
87+
'http_code' => $httpCode
88+
]
6989
];
7090
} else {
7191
$cnf = [ 'async' => true, 'id' => $id ];
@@ -130,23 +150,27 @@ public function get( $_config ) {
130150
$_config[ 'target' ] = $this->_fixLangCode( $_config[ 'target' ] );
131151

132152
$parameters = [];
133-
if ( $this->apikey != null and $this->apikey != '' ) {
134-
$_headers = [ 'apikey: ' . $this->apikey, 'Content-Type: application/json' ];
153+
if ( !empty($this->apiKey) ) {
154+
$_headers = [ 'apikey: ' . $this->apiKey, 'Content-Type: application/json' ];
135155
}
136156

137157
$parameters[ 'context' ][ 'from' ] = $_config[ 'source' ];
138158
$parameters[ 'context' ][ 'to' ] = $_config[ 'target' ];
139159
$parameters[ 'context' ][ 'text' ] = $_config[ 'segment' ];
140160
$provider = $this->provider;
141-
if ( $provider != null and $provider != '' ) {
161+
$providerKey = $this->providerKey;
162+
$providerCategory = $this->providerCategory;
163+
164+
if ( !empty($provider) ) {
142165
$parameters[ 'service' ][ 'async' ] = true;
143-
$parameters[ 'service' ][ 'provider' ] = $provider;
144-
if ( $this->providerkey != null and $this->providerkey != '' ) {
145-
$providerkey = json_decode( $this->providerkey );
146-
$parameters[ 'service' ][ 'auth' ][ $provider ] = [ $providerkey ];
166+
$parameters[ 'service' ][ 'provider' ] = $provider['id'];
167+
168+
if ( !empty($providerKey) ) {
169+
$parameters[ 'service' ][ 'auth' ][ $provider['id'] ] = [json_decode( $providerKey, true )];
147170
}
148-
if ( $this->providercategory != null and $this->providercategory != '' ) {
149-
$parameters[ 'context' ][ 'category' ] = $this->providercategory;
171+
172+
if ( !empty($providerCategory) ) {
173+
$parameters[ 'context' ][ 'category' ] = $providerCategory;
150174
}
151175
}
152176

@@ -168,8 +192,9 @@ public function get( $_config ) {
168192

169193
protected function _curl_async( $config, $parameters = null, $function = null ) {
170194
$id = $config[ 'id' ];
171-
if ( $this->apikey != null and $this->apikey != '' ) {
172-
$_headers = [ 'apikey: ' . $this->apikey, 'Content-Type: application/json' ];
195+
196+
if ( !empty($this->apiKey) ) {
197+
$_headers = [ 'apikey: ' . $this->apiKey, 'Content-Type: application/json' ];
173198
}
174199

175200
$this->_setIntentoUserAgent(); //Set Intento User Agent

lib/Utils/Engines/Results/ErrorMatches.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Engines_Results_ErrorMatches {
77

88
public function __construct( $result = [] ) {
99
if ( !empty( $result ) ) {
10-
$this->http_code = $result[ 'message' ];
10+
$this->http_code = $result[ 'http_code' ] ?? null;
1111
$this->code = $result[ 'code' ];
1212
$this->message = $result[ 'message' ];
1313
}

lib/Utils/Langs/supported_langs.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@
756756
{
757757
"localized": [
758758
{
759-
"en": "Chinese (Simplified)"
759+
"en": "Chinese (Simplified, mainland China)"
760760
}
761761
],
762762
"isocode": "zh",
@@ -783,6 +783,21 @@
783783
"not_supported_or_rtl": false
784784
}
785785
},
786+
{
787+
"localized": [
788+
{
789+
"en": "Chinese (Simplified, Singapore)"
790+
}
791+
],
792+
"isocode": "zh",
793+
"enabled": true,
794+
"rtl": false,
795+
"rfc3066code": "zh-SG",
796+
"ocr": {
797+
"supported": false,
798+
"not_supported_or_rtl": false
799+
}
800+
},
786801
{
787802
"localized": [
788803
{

0 commit comments

Comments
 (0)