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
22 * @param $extensionPath
24 private function addResourceTranslationsByExtensionPath($extensionPath)
26 $languageDirectory = sprintf(
27 '%s/console/translations/%s',
32 if (!is_dir($languageDirectory)) {
35 $finder = new Finder();
38 ->in($languageDirectory);
39 foreach ($finder as $file) {
40 $resource = $languageDirectory . '/' . $file->getBasename();
41 $filename = $file->getBasename('.yml');
42 $key = 'commands.' . $filename;
44 $this->loadTranslationByFile($resource, $key);
45 } catch (ParseException $e) {
46 echo $key . '.yml ' . $e->getMessage();
54 private function addResourceTranslationsByModule($module)
56 if (!\Drupal::moduleHandler()->moduleExists($module)) {
59 $extensionPath = \Drupal::moduleHandler()->getModule($module)->getPath();
60 $this->addResourceTranslationsByExtensionPath(
68 private function addResourceTranslationsByTheme($theme)
70 $extensionPath = \Drupal::service('theme_handler')->getTheme($theme)->getPath();
71 $this->addResourceTranslationsByExtensionPath(
80 public function addResourceTranslationsByExtension($extension, $type)
82 if ($type == 'module') {
83 $this->addResourceTranslationsByModule($extension);
86 if ($type == 'theme') {
87 $this->addResourceTranslationsByTheme($extension);