# wordpress-seo/18.0/admin/class-admin-asset-yoast-components-l10n.php

Yoast SEO – Advanced SEO with real-time guidance and built-in AI, version 18.0. 64 lines.

- Page: https://pluginprobe.com/plugins/wordpress-seo/18.0/code/admin/class-admin-asset-yoast-components-l10n.php
- Raw: https://pluginprobe.com/plugins/wordpress-seo/18.0/raw/admin/class-admin-asset-yoast-components-l10n.php
- Modified: 2021-05-18T13:42:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wordpress-seo/18.0/code/admin/class-admin-asset-yoast-components-l10n.php#L10-L20`.

```php
<?php
/**
 * WPSEO plugin file.
 *
 * @package WPSEO\Admin
 */

/**
 * Localizes JavaScript files.
 */
final class WPSEO_Admin_Asset_Yoast_Components_L10n {

	/**
	 * Represents the asset manager.
	 *
	 * @var WPSEO_Admin_Asset_Manager
	 */
	protected $asset_manager;

	/**
	 * WPSEO_Admin_Asset_Yoast_Components_L10n constructor.
	 */
	public function __construct() {
		$this->asset_manager = new WPSEO_Admin_Asset_Manager();
	}

	/**
	 * Localizes the given script with the JavaScript translations.
	 *
	 * @param string $script_handle The script handle to localize for.
	 *
	 * @return void
	 */
	public function localize_script( $script_handle ) {
		$translations = [
			'yoast-components'    => $this->get_translations( 'yoast-components' ),
			'wordpress-seo'       => $this->get_translations( 'wordpress-seojs' ),
			'yoast-schema-blocks' => $this->get_translations( 'yoast-schema-blocks' ),
		];
		$this->asset_manager->localize_script( $script_handle, 'wpseoYoastJSL10n', $translations );
	}

	/**
	 * Returns translations necessary for JS files.
	 *
	 * @param string $component The component to retrieve the translations for.
	 * @return object|null The translations in a Jed format for JS files.
	 */
	protected function get_translations( $component ) {
		$locale = \get_user_locale();

		$file = WPSEO_PATH . 'languages/' . $component . '-' . $locale . '.json';
		if ( file_exists( $file ) ) {
			// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Retrieving a local file.
			$file = file_get_contents( $file );
			if ( is_string( $file ) && $file !== '' ) {
				return json_decode( $file, true );
			}
		}

		return null;
	}
}

```
