UI.php
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace WPML\ST\Main;
use WPML\Element\API\Languages;
use WPML\FP\Relation;
use WPML\ST\Main\Ajax\FetchCompletedStrings;
use WPML\ST\Main\Ajax\SaveTranslation;
use WPML\ST\WP\App\Resources;
use WPML\LIB\WP\Hooks as WPHooks;
class UI implements \IWPML_Backend_Action_Loader {
/**
* @return callable|null
*/
public function create() {
$isAdminTextsPage = isset( $_GET['trop'] );
if ( Relation::propEq( 'page', WPML_ST_FOLDER . '/menu/string-translation.php', $_GET ) && ! $isAdminTextsPage ) {
return function () {
WPHooks::onAction( 'admin_enqueue_scripts' )
->then( [ self::class, 'localize' ] )
->then( Resources::enqueueApp( 'main-ui' ) );
};
} else {
return null;
}
}
public static function localize() {
/** @var array $languages */
$languages = Languages::withFlags( Languages::getAll() );
return [
'name' => 'wpml_st_main_ui',
'data' => [
'defaultLang' => Languages::getDefaultCode(),
'languageDetails' => Languages::withRtl( $languages ),
'endpoints' => [
'saveTranslation' => SaveTranslation::class,
'translationMemory' => apply_filters( 'wpml_st_translation_memory_endpoint', '' ),
'fetchStrings' => FetchCompletedStrings::class,
],
],
];
}
}