Q:

Laravel: how to use short variable name with language files in blades and controllers

I know how to language files:  
/resources/lang/en/account/login.php
    

return [
    'text_login' => 'Login',
    'text_register' => 'Register',
    'error_login' => 'These credentials do not match our records.',
];

/resources/lang/zh-tw/account/login.php
    

return [
    'text_login' => '登入',
    'text_register' => '註冊',
    'error_login' => '帳號或密碼輸入錯誤',
];

/resources/views/welcome.blade.php  

<a href="{{ route('login') }}">{{ __('account/login.text_login') }}</a>
<a href="{{ route('register') }}">{{ __('account/login.text_register') }}</a>

This works. But too long, I wish to make it shorter.
change this  
{{ __('account/login.text_login') }}  

to  
{{ $text_login }}  

Is it possible to do this?

A:

I have a solution.
In each language, I have sub folders and files.  
/resources/lang/en  
  common.php  
  /catalog
    category.php
    product.php
    attribute.php
    option.php
  ...

common.php
<?php

return [
  'text_yes' => 'Yes',
  'text_no' => 'No',
  'text_enabled' => 'Enabled',
  'text_disabled' => 'Disabled',
  'text_none' => ' --- None --- ',
  'text_select' => ' --- Please Select --- ',
  'text_select_all' => 'Select All',
  'text_unselect_all' => 'Unselect All',
  'text_default' => ' <b>(Default)</b>',
  'text_close' => 'Close',
  'text_pagination' => 'Showing %d to %d of %d (%d Pages)',
  'text_loading' => 'Loading....',
  'text_no_results' => 'No results!',
  'text_confirm' => 'Are you sure?',
  'text_home' => 'Home',
];

category.php
<?php

return [
    'heading_title' => 'Categories',

    'text_list' => 'Category List',
    'text_edit' => 'Edit Category',
    'text_repaire' => 'Repaire Category',
    'text_copy' => 'Copy Category',

    'column_name' => 'Name',
    'column_parent_name' => 'Parent Category',
];

In CategoryController, 
//Language
$langs = Lang::get('common');
foreach ($langs as $key => $value) {
  $data[$key] = $value;
}

$langs = Lang::get('category');
foreach ($langs as $key => $value) {
  $data[$key] = $value;
}

//breadcomb
$data['breadcumbs'][] = array(
  'text' => $data['text_home'],
  'href' => route('admin.dashboard'),
);

$data['breadcumbs'][] = array(
  'text' => $data['heading_title'],
  'href' => route('admin.category.index'),
);

I thought my idea was so great!
But there are still problems. For example, the key text_pagination, needs arguments: firstItem, lastItem, totals, which is generated by laravel pagination class.  
If I load the language files at the begging of the controller function, there are no $categories->firstItem, $categories->lastItem to let me use sprintf. $categories is generated later.  
If the language files are put at the bottom, sometimes we need to use the language variables before that, like validation error message.  
Edit:
Put language files at the begging should be ok. Later reset the text_pagination:  
$data['text_pagination'] = sprintf($data['text_pagination'],   
  $categories->firstItem(), 
  $categories->lastItem(), 
  $categories->total(), 
  $categories->lastPage() );

