5 * Contains \Drupal\Console\Utils\TranslatorManager.
8 namespace Drupal\Console\Utils;
10 use Drupal\Console\Core\Utils\TranslatorManager as TranslatorManagerBase;
11 use Symfony\Component\Yaml\Exception\ParseException;
12 use Symfony\Component\Finder\Finder;
15 * Class TranslatorManager
17 * @package Drupal\Console\Utils
19 class TranslatorManager extends TranslatorManagerBase
21 protected $extensions = [];
24 * @param $extensionPath
26 private function addResourceTranslationsByExtensionPath($extensionPath)
28 $languageDirectory = sprintf(
29 '%s/console/translations/%s',
34 if (!is_dir($languageDirectory)) {
37 $finder = new Finder();
40 ->in($languageDirectory);
41 foreach ($finder as $file) {
42 $resource = $languageDirectory . '/' . $file->getBasename();
43 $filename = $file->getBasename('.yml');
44 $key = 'commands.' . $filename;
46 $this->loadTranslationByFile($resource, $key);
47 } catch (ParseException $e) {
48 echo $key . '.yml ' . $e->getMessage();
56 private function addResourceTranslationsByModule($module)
58 if (!\Drupal::moduleHandler()->moduleExists($module)) {
61 $extensionPath = \Drupal::moduleHandler()->getModule($module)->getPath();
62 $this->addResourceTranslationsByExtensionPath(
70 private function addResourceTranslationsByTheme($theme)
72 $extensionPath = \Drupal::service('theme_handler')->getTheme($theme)->getPath();
73 $this->addResourceTranslationsByExtensionPath(
81 private function addResourceTranslationsByLibrary($library)
83 /** @var \Drupal\Console\Core\Utils\DrupalFinder $drupalFinder */
84 $drupalFinder = \Drupal::service('console.drupal_finder');
85 $path = $drupalFinder->getComposerRoot() . '/vendor/' . $library;
86 $this->addResourceTranslationsByExtensionPath(
95 public function addResourceTranslationsByExtension($extension, $type)
97 if (array_search($extension, $this->extensions) !== false) {
101 $this->extensions[] = $extension;
102 if ($type == 'module') {
103 $this->addResourceTranslationsByModule($extension);
106 if ($type == 'theme') {
107 $this->addResourceTranslationsByTheme($extension);
110 if ($type == 'library') {
111 $this->addResourceTranslationsByLibrary($extension);