collectLocalesStrings() as $locale) { Cache::remember(sprintf('translations_%s', $locale), 172800, function () use ($locale) { $phpTransFallback = $this->phpTranslations(config('app.fallback_locale')); $phpTransLocale = $this->phpTranslations($locale); return ToolboxHelper::arrayMergeRecursiveDistinct( $phpTransFallback, $phpTransLocale, ); }); } //end foreach } /** * Gather provided langs checking from files. * * @return \Illuminate\Support\Collection */ private function collectLocalesStrings(): \Illuminate\Support\Collection { // @phpstan-ignore-next-line return collect(File::allFiles(base_path('lang/')))->flatMap(function (SplFileInfo $file) { if ($file->getRelativePath() and \strpos($file->getRelativePath(), 'vendor') !== 0) { return [$file->getRelativePath() => '']; } })->keys()->merge(config('app.locales', [])); } /** * Gather all php translations. * * @param string $locale * @return array */ private function phpTranslations(string $locale): array { $path = base_path("lang/$locale"); if (!File::exists($path) or !File::isReadable($path)) { return []; } return collect(File::allFiles($path))->flatMap(function ($file) use ($locale) { $translation = $file->getBasename('.php'); return [$translation => trans($translation, [], $locale)]; })->all(); } }