Php 拉威尔:本地语言文件是如何加载的?
给定Laravel 5中的以下文件结构(与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
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' => ...];
这将回答我的问题:
转换器
对象中$this->loader->load($locale,$group,$namespace)代码>实际上是这样。但是,$this->loader
通过构造函数中的依赖注入进行分配,我找不到它的定义位置