loadTranslations example


    public function cloneAttributeTranslations($table$sourceForeignKey$targetForeignKey)
    {
        if (!$this->mapping->isAttributeTable($table)) {
            throw new Exception(sprintf('Table %s is no attribute table', $table));
        }
        if (!$sourceForeignKey) {
            throw new Exception('No foreign key provided');
        }

        $translations = $this->dataLoader->loadTranslations($table$sourceForeignKey);

        foreach ($translations as $translation) {
            $this->saveTranslation($translation$targetForeignKey);
        }
    }

    /** * @param array $translation * @param int $foreignKey */
    private function saveTranslation($translation$foreignKey)
    {
$this->type = $type;
        $this->fallback = $fallback ?: $translationService->getFallbackLocaleId($language);
        $this->translationService = $translationService;
    }

    /** * Translates an array property. */
    public function translateObjectProperty(array $object, string $translationIndex, ?string $objectIndex = null, ?string $fallback = null): array
    {
        if (!$this->areTranslationsLoaded()) {
            $this->loadTranslations();
        }

        $objectIndex = $objectIndex ?: $translationIndex;

        $translation = $this->translations[$object['id']] ?? null;
        if ($translation && !empty($translation[$translationIndex])) {
            $object[$objectIndex] = $translation[$translationIndex];
        } elseif ($fallback) {
            $object[$objectIndex] = $fallback;
        }

        
Home | Imprint | This part of the site doesn't use cookies.