discovery = new CoreYamlDiscovery($name, $directories); } /** * Set one of the YAML values as being translatable. * * @param string $value_key * The key corresponding to the value in the YAML that contains a * translatable string. * @param string $context_key * (Optional) the translation context for the value specified by the * $value_key. * * @return $this */ public function addTranslatableProperty($value_key, $context_key = '') { $this->translatableProperties[$value_key] = $context_key; return $this; } /** * {@inheritdoc} */ public function getDefinitions() { $plugins = $this->discovery->findAll(); // Flatten definitions into what's expected from plugins. $definitions = []; foreach ($plugins as $provider => $list) { foreach ($list as $id => $definition) { // Add TranslatableMarkup. foreach ($this->translatableProperties as $property => $context_key) { if (isset($definition[$property])) { $options = []; // Move the t() context from the definition to the translation // wrapper. if ($context_key && isset($definition[$context_key])) { $options['context'] = $definition[$context_key]; unset($definition[$context_key]); } $definition[$property] = new TranslatableMarkup($definition[$property], [], $options); } } // Add ID and provider. $definitions[$id] = $definition + [ 'provider' => $provider, 'id' => $id, ]; } } return $definitions; } }