Converted translation language array to a Collection

This commit is contained in:
Chris Kankiewicz
2020-05-12 11:00:31 -07:00
parent a7999070eb
commit f4212de655
2 changed files with 10 additions and 8 deletions

View File

@@ -4,6 +4,7 @@ use App\Factories;
use App\Middlewares;
use App\SortMethods;
use App\ViewFunctions;
use Tightenco\Collect\Support\Collection;
return [
/** Path definitions */
@@ -34,11 +35,13 @@ return [
'type' => SortMethods\Type::class,
],
/** Array of available translation languages */
'translations' => [
'de', 'en', 'es', 'fr', 'id', 'it', 'kr', 'nl',
'pl', 'pt-BR', 'ro', 'ru', 'zh-CN', 'zh-TW'
],
/** Collection of available translation languages */
'translations' => function (): Collection {
return Collection::make([
'de', 'en', 'es', 'fr', 'id', 'it', 'kr', 'nl',
'pl', 'pt-BR', 'ro', 'ru', 'zh-CN', 'zh-TW'
]);
},
/** Array of view functions */
'view_functions' => [

View File

@@ -7,7 +7,6 @@ use RuntimeException;
use Symfony\Component\Translation\Loader\YamlFileLoader;
use Symfony\Component\Translation\Translator;
use Symfony\Contracts\Translation\TranslatorInterface;
use Tightenco\Collect\Support\Collection;
class TranslationFactory
{
@@ -33,14 +32,14 @@ class TranslationFactory
{
$language = $this->container->get('language');
if (! in_array($language, $this->container->get('translations'))) {
if (! $this->container->get('translations')->contains($language)) {
throw new RuntimeException("Invalid language option '{$language}'");
}
$translator = new Translator($language);
$translator->addLoader('yaml', new YamlFileLoader());
Collection::make($this->container->get('translations'))->each(
$this->container->get('translations')->each(
function (string $language) use ($translator): void {
$resource = sprintf($this->container->get('translations_path') . '/%s.yaml', $language);
$translator->addResource('yaml', $resource, $language);