Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use a package language file?

I'm trying to use a Laravel 4 package language file, but I don't know how to do it.

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'
];

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.

like image 669
Marwelln Avatar asked Jul 18 '14 18:07

Marwelln


People also ask

How does Laravel know language?

First you set $availableLangs the array of the available languages in your app, you may use config\app. php instead of initializing the array in the middleware as I did. If the first language is available in the request language data, it sets the locale, if not, it will search the next one, and so on.

What is @lang in Laravel?

Laravel-lang is a collection of over 68 language translations for Laravel by developer Fred Delrieu (caouecs), including authentication, pagination, passwords, and validation rules. This package also includes JSON files for many languages.


1 Answers

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

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

You can see more at the Laravel documentation on: 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');
like image 165
antoniputra Avatar answered Oct 06 '22 23:10

antoniputra