<?php

namespace LaraBB\Translate\Tasks;

use Illuminate\Support\Collection;

/**
 * Class GetTranslationsTask
 * @package LaraBB\Translate\Tasks
 */
class GetTranslationsTask
{
    /**
     * @return Collection
     */
    public function run(): Collection
    {
        $translations = collect();
        array_map(function ($file) use($translations) {
            if ($file != '.' && $file != '..') {
                $locale       = pathinfo($file, PATHINFO_FILENAME);
                $localization = (array) json_decode(file_get_contents(resource_path('lang/' . $file)));

                $translations->put($locale, $localization);
            }

            return null;
        }, scandir(resource_path('lang')));

        return $translations;
    }
}
