Skip to content

Commit cf7a95f

Browse files
eiriksmenzolutions
authored andcommitted
Support new installers location. Avoid infinite loop in translator. Fix #363 (#364)
1 parent 5134178 commit cf7a95f

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/Utils/DrupalFinder.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ protected function defineConstants($vendorDir)
7878
"/{$vendorDir}/drupal/console-%s/translations/"
7979
);
8080
}
81+
if (!defined("DRUPAL_CONSOLE_LANGUAGE_INSTALLERS")) {
82+
define(
83+
"DRUPAL_CONSOLE_LANGUAGE_INSTALLERS",
84+
"/console/language/console-%s/translations/"
85+
);
86+
}
8187

8288
if (!defined("DRUPAL_CONSOLE_LIBRARY")) {
8389
define(

src/Utils/TranslatorManager.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,32 @@ private function buildCoreLanguageDirectory(
109109
DRUPAL_CONSOLE_LANGUAGE,
110110
$language
111111
);
112+
$installersLanguageDirectory =
113+
$directoryRoot .
114+
sprintf(
115+
DRUPAL_CONSOLE_LANGUAGE_INSTALLERS,
116+
$language
117+
);
118+
119+
$languageDirectory = null;
120+
foreach ([$coreLanguageDirectory, $installersLanguageDirectory] as $candidate) {
121+
if (is_dir($candidate)) {
122+
$languageDirectory = $candidate;
123+
}
124+
}
112125

113-
if (!is_dir($coreLanguageDirectory)) {
126+
if (!isset($languageDirectory)) {
127+
if ($language == 'en') {
128+
throw new \Exception('No languages found. Make sure you have installed a console language package in a supported directory');
129+
}
114130
return $this->buildCoreLanguageDirectory('en', $directoryRoot);
115131
}
116132

117133
if (!$this->coreLanguageRoot) {
118134
$this->coreLanguageRoot = $directoryRoot;
119135
}
120136

121-
return [$language, $coreLanguageDirectory];
137+
return [$language, $languageDirectory];
122138
}
123139

124140
/**

0 commit comments

Comments
 (0)