mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-08-22 21:54:15 +02:00
Converted translation language array to a Collection
This commit is contained in:
@@ -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' => [
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user