How to use a language pack file?

I am trying to use the Laravel 4 language pack file, but I do not know how to do this.

I created a package with php artisan workbench vendor/package --resources . Then I create the workbench/vendor/package/src/lang/en/routes.php .

In this a route file, I have the following:

 <?php return [ 'foo' => 'bar' ]; 

Now how do I access this? I tried with Lang::get('routes.foo') and Lang::get('vendor/package::routes.foo') , but both fail and just give me the parameter itself that I entered. I call it in the boot method for service providers.

+8
laravel laravel-4
source share
1 answer

Just 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'); 

What you need to do is remove vendor/ but leave package .

You can see more in the Laravel documentation: package conventions .

====

UPDATE

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'); 
+7
source share

All Articles