如何使用打包语言文件? [英] How do I use a package language file?
问题描述
我正在尝试使用Laravel 4打包语言文件,但是我不知道该怎么做.
I'm trying to use a Laravel 4 package language file, but I don't know how to do it.
我用php artisan workbench vendor/package --resources
创建了一个程序包.然后创建文件workbench/vendor/package/src/lang/en/routes.php
.
I created a package with php artisan workbench vendor/package --resources
. I then create file workbench/vendor/package/src/lang/en/routes.php
.
在该路由文件中,我有这个:
In that routes file a I have this:
<?php
return [
'foo' => 'bar'
];
现在我该如何访问?我尝试了Lang::get('routes.foo')
和Lang::get('vendor/package::routes.foo')
,但是都失败了,只是给了我输入的参数本身.我在服务提供商boot
方法中调用它.
Now how do I access that? I tried with Lang::get('routes.foo')
and Lang::get('vendor/package::routes.foo')
but both fails and just gives me the parameter itself I entered. I'm calling it in my service providers boot
method.
推荐答案
就像调用视图和配置一样:
Same like you call view and config:
// for lang
Lang::get('package::routes.foo')
// or with shortcut func
trans('package::routes.foo')
// for view
View::make('package::view.name');
// for config
Config::get('package::group.option');
您需要做的是删除vendor/
,但保留package
.
What you need to do is to remove vendor/
but leave package
.
您可以在以下Laravel文档中找到更多信息:封装约定.
You can see more at the Laravel documentation on: package conventions.
====
在 laravel 5 中,您可以像这样调用视图和配置:
in laravel 5 you can call view and config like this :
// for view (shorthand)
view('path_to_view', array('data' => 'somedata'));
// for config
config('config.name', 'default');
这篇关于如何使用打包语言文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!