Server IP : 89.26.249.46  /  Your IP : 216.73.216.150
Web Server : Apache
System : Linux a.cp.cloudlink.pt 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User : eticalga ( 1129)
PHP Version : 8.3.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/eticalga/www/files/plugins/acfml/classes/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/eticalga/www/files/plugins/acfml/classes/TranslationDataTrait.php
<?php

namespace ACFML;

use ACFML\Helper\ContentType;
use WPML\FP\Obj;

trait TranslationDataTrait {

	/** @var ContentType $contentTypeHelper */
	private $contentTypeHelper;

	/** @var bool */
	private $hasTranslationType;

	public function __construct( ContentType $contentTypeHelper ) {
		$this->contentTypeHelper  = $contentTypeHelper;
		$this->hasTranslationType = ( null !== $this->contentTypeHelper->getWpmlSyncOptionKey() );
	}

	/**
	 * @param  string|null $objectSlug
	 *
	 * @return int
	 */
	protected function getObjectTranslationType( $objectSlug ) {
		if ( $objectSlug ) {
			$settings = wpml_get_setting( $this->contentTypeHelper->getWpmlSyncOptionKey(), [] );
			return Obj::propOr( WPML_CONTENT_TYPE_DONT_TRANSLATE, $objectSlug, $settings );
		}

		return WPML_CONTENT_TYPE_DONT_TRANSLATE;
	}

	/**
	 * @param  string|null $objectSlug
	 *
	 * @return string
	 */
	protected function getObjectTranslationContent( $objectSlug ) {
		switch ( $this->getObjectTranslationType( $objectSlug ) ) {
			case WPML_CONTENT_TYPE_DONT_TRANSLATE:
				return __( 'Not translatable', 'acfml' );
			case WPML_CONTENT_TYPE_TRANSLATE:
			case WPML_CONTENT_TYPE_DISPLAY_AS_IF_TRANSLATED:
				return __( 'Translatable', 'acfml' );
		}
		return '';
	}

	/**
	 * @param  string|null $objectSlug
	 *
	 * @return string
	 */
	protected function getObjectTranslationContext( $objectSlug ) {
		switch ( $this->getObjectTranslationType( $objectSlug ) ) {
			case WPML_CONTENT_TYPE_TRANSLATE:
				return __( 'only show translated items', 'acfml' );
			case WPML_CONTENT_TYPE_DISPLAY_AS_IF_TRANSLATED:
				return __( 'use translation if available or fallback to default language', 'acfml' );
		}
		return '';
	}

	/**
	 * @param  string $objectSlug
	 * @param  string $separator
	 *
	 * @return string
	 */
	protected function getObjectTranslationInformation( $objectSlug, $separator = '' ) {
		$content = $this->getObjectTranslationContent( $objectSlug );
		$context = $this->getObjectTranslationContext( $objectSlug );

		return $this->getTranslationInformation( $content, $context, $separator );
	}

	/**
	 * @param  string $content
	 * @param  string $context
	 * @param  string $separator
	 *
	 * @return string
	 */
	protected function getTranslationInformation( $content, $context = '', $separator = '' ) {
		$information = '<span class="acfml-translation-info">' . esc_html( $content );
		if ( $context ) {
			$information .= $separator . '<span class="acfml-translation-info-context">' . esc_html( $context ) . '</span>';
		}
		$information .= '</span>';

		return $information;
	}

}