then( function () { /** @var \WPML_Notices $notices */ $notices = make( \WPML_Notices::class ); if ( isset( $_GET['ateJobCreationError'] ) ) { $notice = $notices->create_notice( __CLASS__, $this->getContent( $_GET ) ); $notice->set_css_class_types( 'error' ); $notice->set_dismissible( false ); $notices->add_notice( $notice ); } else { $notices->remove_notice( 'default', __CLASS__ ); } } ); } } /** * @param array $params * * @return string */ private function getContent( array $params ) { $isATENotActiveError = pipe( Obj::prop( 'ateJobCreationError' ), Cast::toInt(), Relation::equals( Editor::ATE_IS_NOT_ACTIVE ) ); $isRetryLimitExceeded = pipe( Obj::prop( 'jobId' ), [ ATERetry::class, 'getCount' ], Relation::gt( self::RETRY_LIMIT ) ); return Logic::cond( [ [ $isATENotActiveError, [ self::class, 'ateNotActiveMessage' ] ], [ $isRetryLimitExceeded, [ self::class, 'retryMessage' ] ], [ Fns::always( true ), [ self::class, 'retryFailedMessage' ] ] ], $params ); } public static function retryMessage( array $params ) { $returnUrl = \remove_query_arg( [ 'ateJobCreationError', 'jobId' ], Jobs::getCurrentUrl() ); $jobEditUrl = Jobs::getEditUrl( $returnUrl, Obj::prop( 'jobId', $params ) ); $fallbackErrorMessage = sprintf( '
%1$s %3$s
', __( "WPML didn't manage to translate this page.", 'wpml-translation-management' ), $jobEditUrl, __( 'Try again', 'wpml-translation-management' ) ); $tryAgainTextLink = sprintf( '%2$s', $jobEditUrl, __( 'Try again', 'wpml-translation-management' ) ); $ateApiErrorMessage = ATEDetailedErrorMessage::readDetailedError( $tryAgainTextLink ); return $ateApiErrorMessage ?: $fallbackErrorMessage; } public static function retryFailedMessage() { $fallbackErrorMessage = '
' . sprintf( __( 'WPML tried to translate this page three times and failed. To get it fixed, contact %s', 'wpml-translation-management' ), '' . __( 'WPML support', 'wpml-translation-management' ) . '' ) . '
'; $ateApiErrorMessage = ATEDetailedErrorMessage::readDetailedError(); return $ateApiErrorMessage ?: $fallbackErrorMessage; } public static function ateNotActiveMessage() { return '
' . sprintf( __( 'WPML’s Advanced Translation Editor is enabled but not activated. Go to %s to resolve the issue.', 'wpml-translation-management' ), '' . __( 'WPML Translation Management Dashboard', 'wpml-translation-management' ) . '' ) . '
'; } }