Skip to content

Commit 6a43eaa

Browse files
authored
Merge pull request #27 from TomAtomCZ/dev
Add fallback for locales if enabled_locales is missing
2 parents 5113f16 + 1417b12 commit 6a43eaa

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Services/NodeHelper.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ public function checkAtom($name, $body, $type = 'atom')
5656

5757
// Check if the translation exists for all locales - enabled_locales must be defined in translation.yaml
5858
$locales = $this->getAllEnabledLocales();
59+
// If enabled_locales is missing fallback to get locales from the translation messages files
60+
$translationDir = $this->parameterBag->get('kernel.project_dir') . '/translations';
61+
if (empty($locales) && is_dir($translationDir)) {
62+
// Get the translation messages files
63+
$translationFiles = glob($translationDir . '/*.{yml,yaml}', GLOB_BRACE);
64+
// Get the locales from the translation files
65+
$locales = array_map(function ($filePath) {
66+
$info = pathinfo($filePath);
67+
return str_replace('messages.', '', $info['filename']);
68+
}, $translationFiles);
69+
}
70+
5971
foreach ($locales as $locale) {
6072
$translation = $atom->translate($locale, false);
6173
if ($translation->isEmpty()) {

0 commit comments

Comments
 (0)