I have a choice of language on the site, through {{ trans('index.main') }}
, all good. But I have a page with payment on my site, and for a user from Russia you need to display the Russian version of the payment system, for users from America – the English version and a link to the payment is formed in the controller. In this link I need to pass the parameter &lang=ru
or &lang=en
, but when I try to pass it, I get an error:
Type error: Too few arguments to function Illuminate Translation Translator :: choice (), 1 passed in /var/www/vhosts/skins.games/dota2.skins.games/vendor/laravel/framework/src/Illuminate/Support /Facades/Facade.php on line 210 and at least 2 expected
My code is:
$url = 'https://kassa/merchant/cash.php?m='.$merchant_id.'&oa='.$sum.'&o='.$u.'&s='.$sign.'&lang='.Lang::choice('pay.lang').'&i=&em=';
Where is my mistake?
Advertisement
Answer
As stated in the other answer, Lang::choice() is for handling pluralization of a translation string in your application. If you are trying to get the current locale for the authenticated User you can use this:
...'&lang='.app()->getLocale().'&i=&em=';
This assumes the locales you have defined, match the format desired by the consuming API.
If you do need to format the locale for consumption by the external api, and that is what you have stored in ‘pay.lang’, then you can use __('pay.lang')
or Lang::get('pay.lang')
.
This of course also assumes you are indeed setting the User’s locale in some manner.