1

I added this in fr.json

{
    "There is one apple|There are many apples": "Hay una manzana|Hay muchas manzanas"
}

In blade file:

{{__("There is one apple")}}

Then it shows

There is one apple

It should show Hay una manzana. Please help me to solve it.

abhishekvbajaj
  • 73
  • 1
  • 10

2 Answers2

0

The default language for your application is stored in the config/app.php configuration file's locale configuration option. You are free to modify this value to suit the needs of your application.

In your case it should be

'locale' => 'fr',

You may find more details in documentation https://laravel.com/docs/8.x/localization#configuring-the-locale

SiZE
  • 2,217
  • 1
  • 13
  • 24
0

First make sure you set config/app.php, as 'locale' => 'fr'. You may set that per request using Illuminate\Support\Facades\App::setLocal('fr'); within the routes(Route::get()) or maybe using a middleware.

After you set the locale, add this key:value pair to resources/lang/fr.json file: "There is one apple|There are many apples" : "{1} Hay una manzana|[2,*] Hay muchas manzanas".

And instead of __() use trans_choice() method. And you also have to provide the number of apple/apples as the second argument. That's how it knows if it's going to be singular(1) or plural(2+). So this how you use it inside the blade file:

{{ trans_choice("There is one apple|There are many apples", 2) }}.

PMekuli
  • 90
  • 8