Neos\FluidAdaptor\ViewHelpers\Form\SelectViewHelper::getTranslatedLabel PHP Méthode

getTranslatedLabel() protected méthode

Returns a translated version of the given label
protected getTranslatedLabel ( string $value, string $label ) : string
$value string option tag value
$label string option tag label
Résultat string
    protected function getTranslatedLabel($value, $label)
    {
        $translationConfiguration = $this->arguments['translate'];
        $translateBy = isset($translationConfiguration['by']) ? $translationConfiguration['by'] : 'id';
        $sourceName = isset($translationConfiguration['source']) ? $translationConfiguration['source'] : 'Main';
        $request = $this->controllerContext->getRequest();
        $packageKey = null;
        if (isset($translationConfiguration['package'])) {
            $packageKey = $translationConfiguration['package'];
        } elseif ($request instanceof ActionRequest) {
            $packageKey = $request->getControllerPackageKey();
        }
        $prefix = isset($translationConfiguration['prefix']) ? $translationConfiguration['prefix'] : '';
        if (isset($translationConfiguration['locale'])) {
            try {
                $localeObject = new Locale($translationConfiguration['locale']);
            } catch (InvalidLocaleIdentifierException $e) {
                throw new ViewHelper\Exception('"' . $translationConfiguration['locale'] . '" is not a valid locale identifier.', 1330013193);
            }
        } else {
            $localeObject = null;
        }
        switch ($translateBy) {
            case 'label':
                $label = isset($translationConfiguration['using']) && $translationConfiguration['using'] === 'value' ? $value : $label;
                return $this->translator->translateByOriginalLabel($label, array(), null, $localeObject, $sourceName, $packageKey);
            case 'id':
                $id = $prefix . (isset($translationConfiguration['using']) && $translationConfiguration['using'] === 'label' ? $label : $value);
                $translation = $this->translator->translateById($id, array(), null, $localeObject, $sourceName, $packageKey);
                return $translation !== null ? $translation : $label;
            default:
                throw new ViewHelper\Exception('You can only request to translate by "label" or by "id", but asked for "' . $translateBy . '" in your SelectViewHelper tag.', 1340050647);
        }
    }