master

laravel/framework

Last updated at: 29/12/2023 09:25

ArrayLoader.php

TLDR

The provided file ArrayLoader.php is a class implementation of the Loader interface in the Illuminate\Translation namespace. It loads translation messages for a given locale and group from an array. The class also provides methods to add namespaces and JSON paths to the loader, as well as to add messages to the loader.

Methods

load

The load method is responsible for loading the translation messages for a given locale, group, and namespace. It returns an array of messages.

addNamespace

The addNamespace method is used to add a new namespace to the loader. It takes a namespace and a hint as parameters and does not have a return value.

addJsonPath

The addJsonPath method is used to add a new JSON path to the loader. It takes a path as a parameter and does not have a return value.

addMessages

The addMessages method is used to add messages to the loader. It takes a locale, group, messages, and an optional namespace as parameters. It returns the instance of the loader.

namespaces

The namespaces method is used to get an array of all the registered namespaces. It does not take any parameters and returns an array.

Classes

There are no additional classes in the provided file.

<?php

namespace Illuminate\Translation;

use Illuminate\Contracts\Translation\Loader;

class ArrayLoader implements Loader
{
    /**
     * All of the translation messages.
     *
     * @var array
     */
    protected $messages = [];

    /**
     * Load the messages for the given locale.
     *
     * @param  string  $locale
     * @param  string  $group
     * @param  string|null  $namespace
     * @return array
     */
    public function load($locale, $group, $namespace = null)
    {
        $namespace = $namespace ?: '*';

        return $this->messages[$namespace][$locale][$group] ?? [];
    }

    /**
     * Add a new namespace to the loader.
     *
     * @param  string  $namespace
     * @param  string  $hint
     * @return void
     */
    public function addNamespace($namespace, $hint)
    {
        //
    }

    /**
     * Add a new JSON path to the loader.
     *
     * @param  string  $path
     * @return void
     */
    public function addJsonPath($path)
    {
        //
    }

    /**
     * Add messages to the loader.
     *
     * @param  string  $locale
     * @param  string  $group
     * @param  array  $messages
     * @param  string|null  $namespace
     * @return $this
     */
    public function addMessages($locale, $group, array $messages, $namespace = null)
    {
        $namespace = $namespace ?: '*';

        $this->messages[$namespace][$locale][$group] = $messages;

        return $this;
    }

    /**
     * Get an array of all the registered namespaces.
     *
     * @return array
     */
    public function namespaces()
    {
        return [];
    }
}