diff --git a/app/config/container.php b/app/config/container.php index 236640a..4ff1e86 100644 --- a/app/config/container.php +++ b/app/config/container.php @@ -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' => [ diff --git a/app/src/Factories/TranslationFactory.php b/app/src/Factories/TranslationFactory.php index a1a5f6f..56ced95 100644 --- a/app/src/Factories/TranslationFactory.php +++ b/app/src/Factories/TranslationFactory.php @@ -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);