laravel翻译自定义后备

I build a multilingual site. Initially, I store the content in the database and I give a UI in browser show that normal admin user can edit those data. Whenever admin adds any string in the database he/she can regenerate all those language files under app/lang/ under the corresponding file from admin panel by just pressing one button.

My table structure is

id | location | key     |hindi   | english |
---------------------------------------
 1 | global   | welcome |namaste | Welcome | 

and use in view file like echo trans('global.welcome');

Now I want to automatically collect data from view file. Suppose I add echo trans('global.hello'); in my view file and it's not present in app/lang/en/global.php so fallback language will call. I want to track that situation so that I can add one row in the database table with hello as a key. I want to add to the database at development time, not in production.

  1. Is it good or any better option?
  2. How to fire my own function in fallback time?

How about having your own translation function (only for development or even for production). In there you could first check if the translation exists and after that call the default trans method. Now the approach if you want to use it only for development or also for production (maybe it would be useful for some additional functionality)

Development only: Edit the trans function directly in the helpers.php file or override it
(you'll have to comment the function in helpers.php out)

Development & Production: Create your own function with its own name

The code, however, stays the same

function trans($id, $parameters = array(), $domain = 'messages', $locale = null){
    $translator = app('translator');
    if(!$translator->has($id, Config::get('app.locale')){
        // insert db row
    }
    return $translator->trans($id, $parameters, $domain, $locale);
}