Ad

Pass Dynamic Value To Localization JSON File In Laravel

In my Laravel app, I am doing localization with JSON files instead of PHP files. I am following this docs and searching for a way to pass a dynamic value.

In i18n in React, it is done like this...

In ja.json

{
    "searchResultText":"{{count}} 件表示. ({{rangeStart}} - {{rangeEnd}})"
}

While using it in JSX...

i18n.t('searchResultText', {count: data.count, rangeStart: data.rangeStart, rangeEnd: data.rangeEnd});

But how can I pass dynamic value from blade templates and how to use it in the JSON file?

Laravel version: 5.4

Ad

Answer

In ja.json

{
    "searchResultText":":count 件表示. (:rangeStart - :rangeEnd)"
}

In blade template

{{ __('searchResultText', ['count' => 'Dynamic count value here', 'rangeStart' => 'Dynamic rangeStart value here', 'rangeEnd' => 'Dynamic rangeEnd value here']) }}
Ad
source: stackoverflow.com
Ad