HEX
Server: Apache
System: Linux webd001.cluster127.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64
User: mciraet (192513)
PHP: 8.2.31
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/mciraet/www/wp-content/plugins/polylang-pro/src/services/translation/translation-content.php
<?php
/**
 * Class PLL_Translation_Content
 *
 * @package Polylang-Pro
 */

use WP_Syntex\Polylang_Pro\Modules\Import_Export\Services\Context;

/**
 * Translates content.
 *
 * @since 3.3
 */
class PLL_Translation_Content {

	/**
	 * The translations used to transform the content.
	 *
	 * @since 3.3
	 *
	 * @var Translations
	 */
	private $translations;

	/**
	 * Constructor
	 *
	 * @since 3.7
	 *
	 * @param Translations $translations Used to translate the content.
	 * @return void
	 */
	public function __construct( Translations $translations ) {
		$this->translations = $translations;
	}

	/**
	 * Translates the original's post title.
	 *
	 * @since 3.3
	 *
	 * @param string $from_post The post_content field of the original WP_Post.
	 * @return string
	 */
	public function translate_title( $from_post ) {
		return $this->translations->translate(
			$from_post,
			Context::to_string(
				array(
					Context::FIELD => PLL_Import_Export::POST_TITLE,
				)
			)
		);
	}

	/**
	 * Uses a {@see PLL_Translation_Walker_Interface} subclass to iterate over each translatable part of the passed content, and applies a transformation callback to it. Then returns the transformed content.
	 *
	 * @since 3.3
	 *
	 * @param string $content The post_content field of the original WP_Post.
	 * @return string
	 */
	public function translate_content( $content ) {
		$walker = PLL_Translation_Walker_Factory::create_from( $content );

		return $walker->walk( array( $this->translations, 'translate_entry' ) );
	}

	/**
	 * Translates the original post's excerpt.
	 *
	 * @since 3.3
	 *
	 * @param string $post_excerpt The post_excerpt field of the original WP_Post.
	 * @return string
	 */
	public function translate_excerpt( $post_excerpt ) {
		return $this->translations->translate(
			$post_excerpt,
			Context::to_string(
				array(
					Context::FIELD => PLL_Import_Export::POST_EXCERPT,
				)
			)
		);
	}
}