From 913fc96205d813409d2a8dd979533783bba9c207 Mon Sep 17 00:00:00 2001 From: Wesley Lancel Date: Wed, 6 May 2020 11:05:34 +0200 Subject: [PATCH] Choose correct default translation folder based on Symfony version --- .../Service/TranslationFileExplorer.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Kunstmaan/TranslatorBundle/Service/TranslationFileExplorer.php b/src/Kunstmaan/TranslatorBundle/Service/TranslationFileExplorer.php index 08f57aea9c..2e78d7aad9 100644 --- a/src/Kunstmaan/TranslatorBundle/Service/TranslationFileExplorer.php +++ b/src/Kunstmaan/TranslatorBundle/Service/TranslationFileExplorer.php @@ -4,16 +4,10 @@ use Kunstmaan\TranslatorBundle\Service\Exception\TranslationsNotFoundException; use Symfony\Component\Finder\Finder; +use Symfony\Component\HttpKernel\Kernel; class TranslationFileExplorer { - /** - * Symfony default translation folder (in a bundle) - * - * @var string - */ - private $defaultTranslationFolder = 'Resources/translations'; - /** * An array of supported file formats to look for * @@ -32,7 +26,7 @@ class TranslationFileExplorer public function find($path, array $locales, $translationDirectory = null) { $finder = new Finder(); - $translationDirectory = $translationDirectory ?? $this->defaultTranslationFolder; + $translationDirectory = $translationDirectory ?? $this->getDefaultTranslationFolder(); $exploreDir = $path . '/' . $translationDirectory; @@ -51,4 +45,13 @@ public function setFileFormats($fileFormats) { $this->fileFormats = $fileFormats; } + + protected function getDefaultTranslationFolder(): string + { + if (Kernel::VERSION_ID >= 40000) { + return 'translations'; + } + + return 'Resources/translations'; + } }