ShortCodesInGutenbergBlocks.php
1.46 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
49
50
51
52
<?php
namespace WPML\PB;
use WPML\FP\Fns;
/**
* Class ShortCodesInGutenbergBlocks
* @package WPML\PB
*
* This class is to handle an edge case when there is only one Gutenberg block
* that contains one or more shortcodes.
* In this case we need to force the Gutenberg processing as there will be
* no Gutenberg strings and only shortcode strings.
*
*/
class ShortCodesInGutenbergBlocks {
const FORCED_GUTENBERG = 'Forced-Gutenberg';
public static function recordPackage(
\WPML_PB_String_Translation_By_Strategy $strategy,
$strategyKind,
\WPML_Package $package,
$language
) {
if ( $strategyKind === 'Gutenberg' && $package->kind === 'Page Builder ShortCode Strings' ) {
$package->kind = self::FORCED_GUTENBERG;
$strategy->add_package_to_update_list( $package, $language );
}
}
public static function fixupPackage( $package_data ) {
if ( $package_data['package']->kind === self::FORCED_GUTENBERG ) {
$package_data['package']->kind = 'Gutenberg';
}
return $package_data;
}
public static function normalizePackages( array $packagesToUpdate ) {
if ( count( $packagesToUpdate ) > 1 ) {
// If we have more than one package then we don't need to 'Force' it.
// The normal Gutenberg package will update all translations correctly.
$isForced = function ( $package ) { return $package['package']->kind !== self::FORCED_GUTENBERG; };
$packagesToUpdate = array_filter( $packagesToUpdate, $isForced );
}
return $packagesToUpdate;
}
}