Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
eZ\Publish\Core\Helper\TranslationHelper Class Reference

Helper class for translation. More...

## Public Member Functions
| __construct (ConfigResolverInterface $configResolver, ContentService $contentService, array $siteAccessesByLanguage, LoggerInterface $logger=null)
| getTranslatedContentName (Content $content, $forcedLanguage=null)
| Returns content name, translated. More...
| getTranslatedContentNameByContentInfo (ContentInfo $contentInfo, $forcedLanguage=null)
| Returns content name, translated, from a ContentInfo object. More...
| getTranslatedField (Content $content, $fieldDefIdentifier, $forcedLanguage=null)
| Returns Field object in the appropriate language for a given content. More...
| getTranslatedFieldDefinitionProperty (ContentType $contentType, $fieldDefIdentifier, $property='name', $forcedLanguage=null)
| Returns Field definition name in the appropriate language for a given content. More...
| getTranslatedByProperty (ValueObject $object, $property, $forcedLanguage=null)
| Gets translated property generic helper. More...
| getTranslatedByMethod (ValueObject $object, $method, $forcedLanguage=null)
| Gets translated method generic helper. More...
| getTranslationSiteAccess ($languageCode)
| Returns a SiteAccess name for translation in $languageCode. More...
| getAvailableLanguages ()
| Returns the list of all available languages, including the ones configured in related SiteAccesses. More...

## Protected Attributes
| $configResolver
| $contentService

## Private Member Functions
| getTranslatedContentNameByVersionInfo (VersionInfo $versionInfo, $forcedLanguage=null)
| Returns content name, translated, from a VersionInfo object. More...
| getLanguages ($forcedLanguage=null, $fallbackLanguage=null)

## Private Attributes
| $siteAccessesByLanguage
| $logger

## Detailed Description

Helper class for translation.

Definition at line 24 of file TranslationHelper.php.

## Constructor & Destructor Documentation

## ◆ __construct()

eZ\Publish\Core\Helper\TranslationHelper::__construct | ( | ConfigResolverInterface | $configResolver,
|  | ContentService | $contentService,
|  | array | $siteAccessesByLanguage,
|  | LoggerInterface | $logger = `null`
| ) |  |

Definition at line 38 of file TranslationHelper.php.

References eZ\Publish\Core\Helper\TranslationHelper\$configResolver, eZ\Publish\Core\Helper\TranslationHelper\$contentService, eZ\Publish\Core\Helper\TranslationHelper\$logger, and eZ\Publish\Core\Helper\TranslationHelper\$siteAccessesByLanguage.

## Member Function Documentation

## ◆ getAvailableLanguages()

eZ\Publish\Core\Helper\TranslationHelper::getAvailableLanguages | ( |  | ) |

Returns the list of all available languages, including the ones configured in related SiteAccesses.

Returns
  array

Definition at line 275 of file TranslationHelper.php.

## ◆ getLanguages()

eZ\Publish\Core\Helper\TranslationHelper::getLanguages | ( |  | $forcedLanguage = `null`,
|  |  | $fallbackLanguage = `null`
| ) |  |
| private

Parameters

  string | null | $forcedLanguage |
  string | null | $fallbackLanguage |

Returns
  array|mixed

Definition at line 299 of file TranslationHelper.php.

Referenced by eZ\Publish\Core\Helper\TranslationHelper\getTranslatedByMethod(), eZ\Publish\Core\Helper\TranslationHelper\getTranslatedByProperty(), eZ\Publish\Core\Helper\TranslationHelper\getTranslatedContentNameByVersionInfo(), eZ\Publish\Core\Helper\TranslationHelper\getTranslatedField(), and eZ\Publish\Core\Helper\TranslationHelper\getTranslatedFieldDefinitionProperty().

## ◆ getTranslatedByMethod()

eZ\Publish\Core\Helper\TranslationHelper::getTranslatedByMethod | ( | ValueObject | $object,
|  |  | $method,
|  |  | $forcedLanguage = `null`
| ) |  |

Gets translated method generic helper.

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.

Parameters

  \eZ\Publish\API\Repository\Values\ValueObject | $object | Can be any kind of Value object which directly holds the methods that provides translated value.
  string | $method | Method name, example 'getName', 'description'
  string | $forcedLanguage | Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)

Exceptions

  InvalidArgumentException |

Returns
  string|null

Definition at line 227 of file TranslationHelper.php.

References eZ\Publish\Core\Helper\TranslationHelper\getLanguages().

## ◆ getTranslatedByProperty()

eZ\Publish\Core\Helper\TranslationHelper::getTranslatedByProperty | ( | ValueObject | $object,
|  |  | $property,
|  |  | $forcedLanguage = `null`
| ) |  |

Gets translated property generic helper.

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.

Parameters

  \eZ\Publish\API\Repository\Values\ValueObject | $object | Can be any kid of Value object which directly holds the translated property
  string | $property | Property name, example 'names', 'descriptions'
  string | $forcedLanguage | Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)

Exceptions

  InvalidArgumentException |

Returns
  string|null

Definition at line 188 of file TranslationHelper.php.

References eZ\Publish\Core\Helper\TranslationHelper\getLanguages().

## ◆ getTranslatedContentName()

eZ\Publish\Core\Helper\TranslationHelper::getTranslatedContentName | ( | Content | $content,
|  |  | $forcedLanguage = `null`
| ) |  |

Returns content name, translated.

By default this method uses prioritized languages, unless $forcedLanguage is provided.

Parameters

  \eZ\Publish\API\Repository\Values\Content\Content | $content |
  string | $forcedLanguage | Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)

Returns
  string

Definition at line 55 of file TranslationHelper.php.

References eZ\Publish\Core\Helper\TranslationHelper\getTranslatedContentNameByVersionInfo(), and eZ\Publish\API\Repository\Values\Content\Content\getVersionInfo().

## ◆ getTranslatedContentNameByContentInfo()

eZ\Publish\Core\Helper\TranslationHelper::getTranslatedContentNameByContentInfo | ( | ContentInfo | $contentInfo,
|  |  | $forcedLanguage = `null`
| ) |  |

Returns content name, translated, from a ContentInfo object.

By default this method uses prioritized languages, unless $forcedLanguage is provided.

Parameters

  \eZ\Publish\API\Repository\Values\Content\ContentInfo | $contentInfo |
  string | $forcedLanguage | Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)

Todo:
  Remove ContentService usage when translated names are available in ContentInfo (see https://jira.ez.no/browse/EZP-21755)

Returns
  string

Definition at line 95 of file TranslationHelper.php.

References eZ\Publish\Core\Helper\TranslationHelper\getTranslatedContentNameByVersionInfo().

## ◆ getTranslatedContentNameByVersionInfo()

eZ\Publish\Core\Helper\TranslationHelper::getTranslatedContentNameByVersionInfo | ( | VersionInfo | $versionInfo,
|  |  | $forcedLanguage = `null`
| ) |  |
| private

Returns content name, translated, from a VersionInfo object.

By default this method uses prioritized languages, unless $forcedLanguage is provided.

Parameters

  \eZ\Publish\API\Repository\Values\Content\VersionInfo | $versionInfo |
  string | $forcedLanguage |

Returns
  string

Definition at line 72 of file TranslationHelper.php.

References eZ\Publish\Core\Helper\TranslationHelper\getLanguages(), and eZ\Publish\SPI\Repository\Values\MultiLanguageName\getName().

Referenced by eZ\Publish\Core\Helper\TranslationHelper\getTranslatedContentName(), and eZ\Publish\Core\Helper\TranslationHelper\getTranslatedContentNameByContentInfo().

## ◆ getTranslatedField()

eZ\Publish\Core\Helper\TranslationHelper::getTranslatedField | ( | Content | $content,
|  |  | $fieldDefIdentifier,
|  |  | $forcedLanguage = `null`
| ) |  |

Returns Field object in the appropriate language for a given content.

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.

Parameters

  \eZ\Publish\API\Repository\Values\Content\Content | $content |
  string | $fieldDefIdentifier | Field definition identifier.
  string | $forcedLanguage | Locale we want the field translation in (e.g. "fre-FR"). Null by default (takes current locale)

Returns
  \eZ\Publish\API\Repository\Values\Content\Field|null

Definition at line 118 of file TranslationHelper.php.

References eZ\Publish\API\Repository\Values\Content\Content\getField(), and eZ\Publish\Core\Helper\TranslationHelper\getLanguages().

## ◆ getTranslatedFieldDefinitionProperty()

eZ\Publish\Core\Helper\TranslationHelper::getTranslatedFieldDefinitionProperty | ( | ContentType | $contentType,
|  |  | $fieldDefIdentifier,
|  |  | $property = `'name'`,
|  |  | $forcedLanguage = `null`
| ) |  |

Returns Field definition name in the appropriate language for a given content.

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.

Parameters

  \eZ\Publish\API\Repository\Values\ContentType\ContentType | $contentType |
  string | $fieldDefIdentifier | Field Definition identifier
  string | $property | Specifies if 'name' or 'description' should be used
  string | $forcedLanguage | Locale we want the field definition name translated in in (e.g. "fre-FR"). Null by default (takes current locale)

Exceptions

  InvalidArgumentException |

Returns
  string|null

Definition at line 144 of file TranslationHelper.php.

References eZ\Publish\API\Repository\Values\ContentType\ContentType\getFieldDefinition(), and eZ\Publish\Core\Helper\TranslationHelper\getLanguages().

## ◆ getTranslationSiteAccess()

eZ\Publish\Core\Helper\TranslationHelper::getTranslationSiteAccess | ( |  | $languageCode | ) |

Returns a SiteAccess name for translation in $languageCode.

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.

Parameters

  string | $languageCode | Translation language code.

Returns
  string|null

Definition at line 251 of file TranslationHelper.php.

## Member Data Documentation

## ◆ $configResolver

eZ\Publish\Core\Helper\TranslationHelper::$configResolver
| protected

Definition at line 27 of file TranslationHelper.php.

Referenced by eZ\Publish\Core\Helper\TranslationHelper\__construct().

## ◆ $contentService

eZ\Publish\Core\Helper\TranslationHelper::$contentService
| protected

Definition at line 30 of file TranslationHelper.php.

Referenced by eZ\Publish\Core\Helper\TranslationHelper\__construct().

## ◆ $logger

eZ\Publish\Core\Helper\TranslationHelper::$logger
| private

Definition at line 36 of file TranslationHelper.php.

Referenced by eZ\Publish\Core\Helper\TranslationHelper\__construct().

## ◆ $siteAccessesByLanguage

eZ\Publish\Core\Helper\TranslationHelper::$siteAccessesByLanguage
| private

Definition at line 33 of file TranslationHelper.php.

Referenced by eZ\Publish\Core\Helper\TranslationHelper\__construct().

The documentation for this class was generated from the following file:

- TranslationHelper.php

Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.