How can Laravel implement multi-language functionality?

In Laravel, implementing multilingual functionality mainly involves the following steps:

  1. app.php configuration file
'locale' => 'en',
'locales' => ['en', 'zh'],
  1. language resources
  2. Could you please repeat that in English?
  3. I will only provide one option natively in English.
  4. The file messages.php
// resources/lang/en/messages.php
return [
    'welcome' => 'Welcome to our website!',
];

// resources/lang/zh/messages.php
return [
    'welcome' => '欢迎来到我们的网站!',
];
  1. Could you help me with this task?
// 在视图文件中
{{ trans('messages.welcome') }}

// 在控制器中
return view('welcome')->with('message', trans('messages.welcome'));
  1. locality
app()->setLocale('zh');

By following the steps above, multi-language functionality can be implemented in Laravel.

bannerAds