Last active
August 29, 2015 14:01
-
-
Save spolischook/f54b97ffb3ad3028bdc8 to your computer and use it in GitHub Desktop.
Get all translation files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| private function getAllTranslationsFiles($container) | |
| { | |
| // Discover translation directories | |
| $dirs = array(); | |
| $overridePath = $container->getParameter('kernel.root_dir').'/Resources/%s/translations'; | |
| foreach ($container->getParameter('kernel.bundles') as $bundle => $class) { | |
| $reflection = new \ReflectionClass($class); | |
| if (false === strpos($reflection->getFilename(), 'src')) { | |
| continue; | |
| } | |
| if (is_dir($dir = dirname($reflection->getFilename()).'/Resources/translations')) { | |
| $dirs[] = $dir; | |
| } | |
| if (is_dir($dir = sprintf($overridePath, $bundle))) { | |
| $dirs[] = $dir; | |
| } | |
| } | |
| if (is_dir($dir = $container->getParameter('kernel.root_dir').'/Resources/translations')) { | |
| $dirs[] = $dir; | |
| } | |
| if ($dirs) { | |
| $finder = Finder::create() | |
| ->files() | |
| ->filter(function (\SplFileInfo $file) { | |
| return 2 === substr_count($file->getBasename(), '.') && preg_match('/\.\w+$/', $file->getBasename()); | |
| }) | |
| ->in($dirs) | |
| ; | |
| $translationFiles = array(); | |
| foreach ($finder as $file) { | |
| // filename is domain.locale.format | |
| list($domain, $locale, $format) = explode('.', $file->getBasename(), 3); | |
| $translationFiles[] = array('format' => $format, 'file' => (string) $file, 'locale' => $locale, 'domain' => $domain); | |
| } | |
| return $translationFiles; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment