getTranslationCode example



    private function mapToTranslationCode(string $languageId): string
    {
        $criteria = (new Criteria([$languageId]))->addAssociation('translationCode');

        /** @var LanguageEntity|null $language */
        $language = $this->languageRepository
            ->search($criteria, Context::createDefaultContext())
            ->first();

        return $language && $language->getTranslationCode() ? $language->getTranslationCode()->getCode() : $languageId;
    }
}


    private function getSystemLanguageLocale(Context $context): string
    {
        $criteria = new Criteria();
        $criteria->addAssociation('translationCode');
        $criteria->addFilter(new EqualsFilter('id', Defaults::LANGUAGE_SYSTEM));

        /** @var LanguageEntity $language */
        $language = $this->languageRepository->search($criteria$context)->first();
        /** @var LocaleEntity $locale */
        $locale = $language->getTranslationCode();

        return $locale->getCode();
    }

    /** * @param array<string, mixed> $translations * * @return array<string, array<string, mixed>> */
    private function mapTranslations(array $translations, string $property, string $systemLanguageLocale): array
    {
        
Home | Imprint | This part of the site doesn't use cookies.