for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Terranet\Administrator\Services\Translations;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Terranet\Localizer\Locale;
class Reader
{
/**
* Reads the translation file's contents.
*
* @param Collection $files
* @param Collection $locales
* @return mixed
*/
public function read(Collection $files, Collection $locales)
return $locales->reduce(function ($translations, $locale) use ($files) {
$files->each(function ($file) use ($locale, &$translations) {
if (file_exists($path = $this->pathToFile($file, $locale))) {
$content[$file] = include_once $path;
$content
$content = array();
foreach (Arr::dot($content) as $key => $value) {
$translations[$key][$locale->iso6391()] = $value ? $value : '';
}
});
return $translations;
}, []);
* Retrieves the real path to a translation file.
* @param $file
* @param $locale
* @return string
public function pathToFile($file, $locale): string
return resource_path('lang'.\DIRECTORY_SEPARATOR.(is_a($locale, Locale::class) ? $locale->iso6391() : $locale).\DIRECTORY_SEPARATOR.$file.'.php');
resource_path
If this is a false-positive, you can also ignore this issue in your code via the ignore-call annotation
ignore-call
return /** @scrutinizer ignore-call */ resource_path('lang'.\DIRECTORY_SEPARATOR.(is_a($locale, Locale::class) ? $locale->iso6391() : $locale).\DIRECTORY_SEPARATOR.$file.'.php');