Fetch the translations of a database record 

\TYPO3\CMS\Backend\Domain\Repository\Localization\LocalizationRepository reads the translations that exist for a record. Inject it into the class that needs them:

EXT:my_extension/Classes/Service/RecordTranslationService.php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Service;

use TYPO3\CMS\Backend\Domain\Repository\Localization\LocalizationRepository;
use TYPO3\CMS\Core\Domain\RawRecord;

final readonly class RecordTranslationService
{
  public function __construct(
    private LocalizationRepository $localizationRepository,
  ) {}

  /**
   * @return RawRecord[] indexed by language ID
   */
  public function findTranslations(int $conferenceUid): array
  {
    return $this->localizationRepository->getRecordTranslations(
      'tx_myextension_conference',
      $conferenceUid,
    );
  }

  public function findTranslation(
    int $conferenceUid,
    int $languageId,
  ): ?RawRecord {
    return $this->localizationRepository->getRecordTranslation(
      'tx_myextension_conference',
      $conferenceUid,
      $languageId,
    );
  }

  public function countTranslations(int $conferenceUid): int
  {
    return count($this->findTranslations($conferenceUid));
  }
}
Copied!

The repository returns the translations only, never the record in the default language. The values come as RawRecord objects, which carry the values as they are stored, without the resolved relations of a record object.

A table that TCA does not describe, or that is not language aware, yields null or an empty array rather than an error.

The repository applies the workspace overlay and leaves out the placeholder records of a deleted translation. It does not read the backend user, so it answers the same in a console command as in a backend module.

Methods of the localization repository 

getRecordTranslation($tableOrSchema, $recordOrUid, $language)
The translation of a record in one language, or null when there is none.
getRecordTranslations($tableOrSchema, $recordOrUid, $limitToLanguageIds)
Every translation of a record, indexed by language ID. count() on the result is the number of translations.
getPageTranslations($pageUid, $limitToLanguageIds)
Every translation of a page, indexed by language ID.

Name the table either as a string or as a TcaSchema , and the record either as its uid, as the record array or as a RecordInterface . Passing the whole record lets the repository filter by the page of the record as well. The language is a language ID or a LanguageAspect . Two further optional arguments of every method choose the workspace and whether deleted translations are included.