463   Laravel

trans() is a helper function , which will help us to translate defferent language !

1, How to use this function ?

echo trans('validation.required'):

This function will read the file in ‘resources/lang/$locale/validation.php’, the $locale is based on your language !
Default locale is ‘en’ in ‘config/app.php’ file of ‘fallback_locale’ ! What you want to change is ‘locale’ by yourself !

2, Add my language file !
Edit ‘locale’ in ‘config/app.php’ to ‘zh_cn’ , create floder ‘zh_cn’ in ‘resources/lang’ , then add one file named ‘commom.php’ widthin content :

return [
    'Home' => '首页',
    'Login' => '登录',
    'Register' => '注册',
    'Logout' => '退出',
];

3, Use my language file !

echo trans('commom.Home'):



Leave a Reply

Your email address will not be published. Required fields are marked *