Php 拉威尔:本地语言文件是如何加载的?

Php 拉威尔:本地语言文件是如何加载的?,php,laravel-5,Php,Laravel 5,给定Laravel 5中的以下文件结构(与en相同): resources/ de/ list.php countries.php mail.php pages/ pageA.json pageB.json 我想知道: 有.json文件的文件夹pages是否会干扰\uuu

给定Laravel 5中的以下文件结构(与
en
相同):

  resources/
            de/
               list.php 
               countries.php
               mail.php
               pages/
                   pageA.json
                   pageB.json
我想知道:

  • .json
    文件的文件夹
    pages
    是否会干扰
    \uuu(…)
    @lang(…)

  • 语言文件是如何加载的


  • 这是我自己设法发现的:

    函数
    ('list.button_send')
    触发
    getFromJson($key,array$replace=[],$locale=null)
    $key='list.button_send'

    这是该功能的主要部分:

    $locale = $locale ?: $this->locale;
    
    // For JSON translations, there is only one file per locale, so we will simply load
    // that file and then we will be ready to check the array for the key. These are
    // only one level deep so we do not need to do any fancy searching through it.
    $this->load('*', '*', $locale);
    
    $line = $this->loaded['*']['*'][$locale][$key] ?? null;
    
    我已经被评论弄糊涂了——我的翻译在三个不同的
    *.php
    文件中。为什么Taylor谈论的是单个JSON文件?但是如果我们忽略这一点并继续,就会发现
    load
    函数如下所示:

    // The loader is responsible for returning the array of language lines for the
    // given namespace, group, and locale. We'll set the lines in this array of
    // lines that have already been loaded so that we can easily access them.
    $lines = $this->loader->load($locale, $group, $namespace);
    
    $this->loaded[$namespace][$group][$locale] = $lines;
    
    我不知道为什么需要使用
    $namespace
    $group
    调用此函数,因为在我看来,它们总是
    *
    Translator
    类中。但忽略这一点,我来到了有趣的部分:什么是
    $lines
    ?我猜这是一个数组的形式

    $lines = ['list' => ... , 'countries' => ..., 'mail' => ...];
    
    这将回答我的问题:

  • 不,他们不干涉

  • 如果访问lang中的单个键,则该lang中的所有语言文件(表示该目录中的所有*.php)都将加载并存储在
    转换器
    对象中

  • 然而,我无法证实我的猜测。为了做到这一点,我需要找出什么
    $this->loader->load($locale,$group,$namespace)实际上是这样。但是,
    $this->loader
    通过构造函数中的依赖注入进行分配,我找不到它的定义位置