Neos\Flow\I18n\Xliff\XliffModel::getTargetByTransUnitId PHP Метод

getTargetByTransUnitId() публичный Метод

Id is compared with "id" attribute of "trans-unit" tag (see XLIFF specification for details).
public getTargetByTransUnitId ( string $transUnitId, integer $pluralFormIndex ) : mixed
$transUnitId string The "id" attribute of "trans-unit" tag in XLIFF
$pluralFormIndex integer Index of plural form to use (starts with 0)
Результат mixed Translated label or FALSE on failure
    public function getTargetByTransUnitId($transUnitId, $pluralFormIndex = 0)
    {
        if (!isset($this->xmlParsedData['translationUnits'][$transUnitId])) {
            $this->i18nLogger->log('No trans-unit element with the id "' . $transUnitId . '" was found in ' . $this->sourcePath . '. Either this translation has been removed or the id in the code or template referring to the translation is wrong.', LOG_DEBUG);
            return false;
        }
        if (!isset($this->xmlParsedData['translationUnits'][$transUnitId][$pluralFormIndex])) {
            $this->i18nLogger->log('The plural form index "' . $pluralFormIndex . '" for the trans-unit element with the id "' . $transUnitId . '" in ' . $this->sourcePath . ' is not available.', LOG_DEBUG);
            return false;
        }
        if ($this->xmlParsedData['translationUnits'][$transUnitId][$pluralFormIndex]['target']) {
            return $this->xmlParsedData['translationUnits'][$transUnitId][$pluralFormIndex]['target'];
        } elseif ($this->locale->getLanguage() === $this->xmlParsedData['sourceLocale']->getLanguage()) {
            return $this->xmlParsedData['translationUnits'][$transUnitId][$pluralFormIndex]['source'] ?: false;
        } else {
            $this->i18nLogger->log('The target translation was empty and the source translation language (' . $this->xmlParsedData['sourceLocale']->getLanguage() . ') does not match the current locale (' . $this->locale->getLanguage() . ') for the trans-unit element with the id "' . $transUnitId . '" in ' . $this->sourcePath, LOG_DEBUG);
            return false;
        }
    }

Usage Example

 /**
  * @test
  */
 public function sourceIsReturnedWhenIdProvidedAndSourceEqualsTargetLanguage()
 {
     $this->model = new I18n\Xliff\XliffModel('foo', new I18n\Locale('en_US'));
     $this->model->injectCache($this->mockCache);
     $this->model->injectParser($this->mockXliffParser);
     $this->model->initializeObject();
     $result = $this->model->getTargetByTransUnitId('key3');
     $this->assertEquals('No target', $result);
 }