PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.6
28.6 28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 All 130 releases
wordpress-seo / admin / class-admin-asset-yoast-components-l10n.php

class-admin-asset-yoast-components-l10n.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.6, at admin/class-admin-asset-yoast-components-l10n.php

79 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPSEO plugin file.
4 *
5 * @package WPSEO\Admin
6 */
7
8 /**
9 * Localizes JavaScript files.
10 *
11 * @codeCoverageIgnore
12 * @deprecated 18.0
13 */
14 final class WPSEO_Admin_Asset_Yoast_Components_L10n {
15
16 /**
17 * Represents the asset manager.
18 *
19 * @var WPSEO_Admin_Asset_Manager
20 */
21 protected $asset_manager;
22
23 /**
24 * WPSEO_Admin_Asset_Yoast_Components_L10n constructor.
25 *
26 * @codeCoverageIgnore
27 * @deprecated 18.0
28 */
29 public function __construct() {
30 _deprecated_constructor( __CLASS__, '18.0' );
31 $this->asset_manager = new WPSEO_Admin_Asset_Manager();
32 }
33
34 /**
35 * Localizes the given script with the JavaScript translations.
36 *
37 * @codeCoverageIgnore
38 * @deprecated 18.0
39 *
40 * @param string $script_handle The script handle to localize for.
41 *
42 * @return void
43 */
44 public function localize_script( $script_handle ) {
45 _deprecated_function( __FUNCTION__, '18.0' );
46 $translations = [
47 'yoast-components' => $this->get_translations( 'yoast-components' ),
48 'wordpress-seo' => $this->get_translations( 'wordpress-seojs' ),
49 'yoast-schema-blocks' => $this->get_translations( 'yoast-schema-blocks' ),
50 ];
51 $this->asset_manager->localize_script( $script_handle, 'wpseoYoastJSL10n', $translations );
52 }
53
54 /**
55 * Returns translations necessary for JS files.
56 *
57 * @codeCoverageIgnore
58 * @deprecated 18.0
59 *
60 * @param string $component The component to retrieve the translations for.
61 * @return object|null The translations in a Jed format for JS files.
62 */
63 protected function get_translations( $component ) {
64 _deprecated_function( __FUNCTION__, '18.0' );
65 $locale = \get_user_locale();
66
67 $file = WPSEO_PATH . 'languages/' . $component . '-' . $locale . '.json';
68 if ( file_exists( $file ) ) {
69 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Retrieving a local file.
70 $file = file_get_contents( $file );
71 if ( is_string( $file ) && $file !== '' ) {
72 return json_decode( $file, true );
73 }
74 }
75
76 return null;
77 }
78 }
79