Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 501 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get whole language file array

#1
I'm newbie in **laravel 4.0**.

- How to get the whole array from `lang/en/texts.php`?
- Is there a `Lang::getAll()` method?


My goal is to generate keywords/description in my base controller, to fill them into the the meta tags and other places in the DOM in the master blade template. If my approach is completely wrong, please tell me!

Generating the keywords and description from an associative array is NOT the problem, but the lack of knowledge about the framework. And, I was googling for quite a time before ending up here...

Working with blade templates:
This is my BaseController:

class HomeController extends BaseController {

protected $layout = 'layouts.master';
private $keyWords = array();

private function getKeyWords () {
// ???

}

public function getIndex() {
return View::make('home')
->with('errorcanvas', trans('texts.canvas'))
->with('errortextwebgl', trans('texts.webgl'))
...;
}

...

}


----------


I found something in the [API][1]:

`Illuminate\Translation\FileLoader load()` which loads the messages with a given `locale`
...


[1]:

[To see links please register here]

Reply

#2
Here's how yo can load them:

Route::get('test', function()
{
$a = File::getRequire(base_path().'/app/lang/en/pagination.php');

foreach($a as $key => $value)
{
echo "$key => $value<br>";
}
});

If you need to load them all, you can use:

$languages = File::directories(base_path().'/app/lang/');

I had to find a way to create an language import command in my Glottos package:

[To see links please register here]

.
Reply

#3
Antonio answered loading of language file perfectly, but I don't like your approach.
It can be done much easier. Why not to do it this way?

// view file
<html>
<head>
<meta name="description" content="{{ trans('texts.description') }}">
...
</head>
...
</html>

You do not need to send all the content thru controller, which makes your controller clean.
Reply

#4
Lets say, a language file: lang/en/countries.php

return [
'afg' => 'Afghanistan',
'ala' => 'Aland',
'alb' => 'Albania',
'dza' => 'Algeria',
'asm' => 'American Samoa'
];

Retrieving lines from the language file with **Lang::get()** method

$array = Lang::get('countries'); // return entire array
$text = Lang::get('countries.afg'); // return single item

for **Laravel 5.0** & above, You may also use the **trans** helper function, which is an alias for the **Lang::get()** method.

$array = trans('countries'); // return entire array
$text = trans('countries.afg'); // return single item

[Find out more on Laravel docs...][1]


[1]:

[To see links please register here]

Reply

#5
You can [get the entire array][1] with `Lang::get()`.

$array = Lang::get('pagination'); // return entire array
$text = Lang::get('pagination.next'); // return single item


[1]:

[To see links please register here]

Reply

#6
you can actually use the helper function `__('lang_file')` as well.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through