PHP Class eZ\Publish\Core\Helper\TranslationHelper

Mostra file Open project: ezsystems/ezpublish-kernel Class Usage Examples

Protected Properties

Property Type Description
$configResolver eZ\Publish\Core\MVC\ConfigResolverInterface
$contentService eZ\Publish\API\Repository\ContentService

Public Methods

Method Description
__construct ( eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver, eZ\Publish\API\Repository\ContentService $contentService, array $siteAccessesByLanguage, Psr\Log\LoggerInterface $logger = null )
getAvailableLanguages ( ) : array Returns the list of all available languages, including the ones configured in related SiteAccesses.
getTranslatedByMethod ( eZ\Publish\API\Repository\Values\ValueObject $object, string $method, string $forcedLanguage = null ) : string | null Gets translated method generic helper.
getTranslatedByProperty ( eZ\Publish\API\Repository\Values\ValueObject $object, string $property, string $forcedLanguage = null ) : string | null Gets translated property generic helper.
getTranslatedContentName ( eZ\Publish\API\Repository\Values\Content\Content $content, string $forcedLanguage = null ) : string Returns content name, translated.
getTranslatedContentNameByContentInfo ( eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo, string $forcedLanguage = null ) : string Returns content name, translated, from a ContentInfo object.
getTranslatedField ( eZ\Publish\API\Repository\Values\Content\Content $content, string $fieldDefIdentifier, string $forcedLanguage = null ) : eZ\Publish\API\Repository\Values\Content\Field | null Returns Field object in the appropriate language for a given content.
getTranslatedFieldDefinitionProperty ( eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType, string $fieldDefIdentifier, string $property = 'name', string $forcedLanguage = null ) : string | null Returns Field definition name in the appropriate language for a given content.
getTranslationSiteAccess ( string $languageCode ) : string | null Returns a SiteAccess name for translation in $languageCode.

Private Methods

Method Description
getLanguages ( string | null $forcedLanguage = null, string | null $fallbackLanguage = null ) : array | mixed
getTranslatedContentNameByVersionInfo ( eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo, string $forcedLanguage = null ) : string Returns content name, translated, from a VersionInfo object.

Method Details

__construct() public method

public __construct ( eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver, eZ\Publish\API\Repository\ContentService $contentService, array $siteAccessesByLanguage, Psr\Log\LoggerInterface $logger = null )
$configResolver eZ\Publish\Core\MVC\ConfigResolverInterface
$contentService eZ\Publish\API\Repository\ContentService
$siteAccessesByLanguage array
$logger Psr\Log\LoggerInterface

getAvailableLanguages() public method

Returns the list of all available languages, including the ones configured in related SiteAccesses.
public getAvailableLanguages ( ) : array
return array

getTranslatedByMethod() public method

For generic use, expects method exposing translated property as-is on value object, typically $object->$method($language) Languages will consist of either forced language or current languages list, in addition helper will append null to list of languages so method may fallback to main/initial language if supported by domain.
public getTranslatedByMethod ( eZ\Publish\API\Repository\Values\ValueObject $object, string $method, string $forcedLanguage = null ) : string | null
$object eZ\Publish\API\Repository\Values\ValueObject Can be any kind of Value object which directly holds the methods that provides translated value.
$method string Method name, example 'getName', 'description'
$forcedLanguage string Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)
return string | null

getTranslatedByProperty() public method

For generic use, expects array property as-is on value object, typically $object->$property[$language] Languages will consist of either forced language or current languages list, in addition helper will check if for mainLanguage property and append that to languages if alwaysAvailable property is true or non-existing.
public getTranslatedByProperty ( eZ\Publish\API\Repository\Values\ValueObject $object, string $property, string $forcedLanguage = null ) : string | null
$object eZ\Publish\API\Repository\Values\ValueObject Can be any kid of Value object which directly holds the translated property
$property string Property name, example 'names', 'descriptions'
$forcedLanguage string Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)
return string | null

getTranslatedContentName() public method

By default this method uses prioritized languages, unless $forcedLanguage is provided.
public getTranslatedContentName ( eZ\Publish\API\Repository\Values\Content\Content $content, string $forcedLanguage = null ) : string
$content eZ\Publish\API\Repository\Values\Content\Content
$forcedLanguage string Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)
return string

getTranslatedContentNameByContentInfo() public method

By default this method uses prioritized languages, unless $forcedLanguage is provided.
public getTranslatedContentNameByContentInfo ( eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo, string $forcedLanguage = null ) : string
$contentInfo eZ\Publish\API\Repository\Values\Content\ContentInfo
$forcedLanguage string Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)
return string

getTranslatedField() public method

By default, this method will return the field in current language if translation is present. If not, main language will be used. If $forcedLanguage is provided, will return the field in this language, if translation is present.
public getTranslatedField ( eZ\Publish\API\Repository\Values\Content\Content $content, string $fieldDefIdentifier, string $forcedLanguage = null ) : eZ\Publish\API\Repository\Values\Content\Field | null
$content eZ\Publish\API\Repository\Values\Content\Content
$fieldDefIdentifier string Field definition identifier.
$forcedLanguage string Locale we want the field translation in (e.g. "fre-FR"). Null by default (takes current locale)
return eZ\Publish\API\Repository\Values\Content\Field | null

getTranslatedFieldDefinitionProperty() public method

By default, this method will return the field definition name in current language if translation is present. If not, main language will be used. If $forcedLanguage is provided, will return the field definition name in this language, if translation is present.
public getTranslatedFieldDefinitionProperty ( eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType, string $fieldDefIdentifier, string $property = 'name', string $forcedLanguage = null ) : string | null
$contentType eZ\Publish\API\Repository\Values\ContentType\ContentType
$fieldDefIdentifier string Field Definition identifier
$property string Specifies if 'name' or 'description' should be used
$forcedLanguage string Locale we want the field definition name translated in in (e.g. "fre-FR"). Null by default (takes current locale)
return string | null

getTranslationSiteAccess() public method

This is used for LanguageSwitcher feature (generate links for current content in a different language if available). Will use configured translation_siteaccesses if any. Otherwise will use related siteaccesses (e.g. same repository, same rootLocationId). Will return null if no translation SiteAccess can be found.
public getTranslationSiteAccess ( string $languageCode ) : string | null
$languageCode string Translation language code.
return string | null

Property Details

$configResolver protected_oe property

protected ConfigResolverInterface,eZ\Publish\Core\MVC $configResolver
return eZ\Publish\Core\MVC\ConfigResolverInterface

$contentService protected_oe property

protected ContentService,eZ\Publish\API\Repository $contentService
return eZ\Publish\API\Repository\ContentService