Saturday, 15 August 2015

php - laravel translation custom fallback -



php - laravel translation custom fallback -

i build multilingual site. store the content in database , give ui in browser show normal admin user can edit data.when ever admin add together string in database he/she can re generate language file under app/lang/ under corresponding file admin panel pressing 1 button.

my table construction

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

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

now want automatically collect info view file. suppose add together echo trans('global.hello'); in view file , it's not nowadays in app/lang/en/global.php fallback language call. want track situation can add together 1 row in database table hello key. want of things in development time not in production.

is things in way or there improve alternative ? how fire own function in fallback time ?

how having own translation function (only development or production). in there first check if translation exists , after phone call default trans method. approach if want utilize development or production (maybe useful additional functionality)

development only: edit trans function straight in helpers.php file or override it (you'll have comment function in helpers.php out)

development & production: create own function own name

the code, however, stays same

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

php laravel laravel-4

No comments:

Post a Comment