2
votes

i want to set the default locale to zh-tw from en, i changed the locale='en' to locale='zh-tw' in \config\app.php,

'locale' => 'zh-tw',

but the view is keep using 'resources\lang\en',

i've also tried but all not useful:
added APP_LOCALE in .env=zh-tw
run php artisan cache:clear

Why \config\app.php locale setting has no effect and meanless in laravel?

Except to run setlocale('zh-tw') in every controller or create a middleware to set language, is there any other simplest method to change the default locale in few seconds?

5
Hope you have already created 'resources\lang\zh-tw' - VipindasKS
Do oyu need to do a clear cache "php artisan clear:cache" or "cache:clear" i can never remember - Brett

5 Answers

3
votes

To set the locale and make it work properly you need to do below configurations:

1) First make your locale folder inside \resources\lang\YOUR_LOCALE_NAME.

2) Then add file messages.php or as per your need. which has following structure:

<?php

return array(
    'welcome' => 'Welcome to our application'
);

3) Then go to \config\app.php and set the locale as your LOCALE_FOLDER_NAME.

4) Remember to set fallback_locale in app.php which will be used in case YOUR_LOCALE_NAME is not found.

3
votes

To modify the hideDefaultLocaleInURL parameter in the config/laravellocalization.php file.

From:

'hideDefaultLocaleInURL' => false

To:

'hideDefaultLocaleInURL' => true

0
votes

just go to config/app.php and look for locale key and change it whatever you want

0
votes

To fix this you need to do below instructions:

  1. First make your locale folder inside \resources\lang\LOCALE_NAME.

  2. Then you have to add files which has following structure:

    <?php return [    
     'reset' => 'Your password has been reset!',
     'sent' => 'We have emailed your password reset link!',
     'throttled' => 'Please wait before retrying.',
     'token' => 'This password reset token is invalid.',
     'user' => "We can't find a user with that email address.",];
    
  3. Then you have to go to \config\app.php and set locale as your LOCALE_FOLDER_NAME.

    'locale' => 'LOCALE_NAME',

  4. After this you have to clear your config cache. Go to your terminal and paste this code to clear it.

    php artisan config:cache

*Note: Some times you could get an error like this:

Illuminate\Contracts\Container\BindingResolutionException 

  Target class [view.engine.resolver] does not exist.

Just run the following code in the root of your application in your system terminal.

composer dump-autoload
0
votes
  1. run php artisan config:cache command in your root directory of the laravel project
  2. check if it works fine
  3. go to /bootstrap/cache address to find config.php and delete it if exists