Home > Software design >  laravel placeholder translation of an array
laravel placeholder translation of an array

Time:06-13

i have a translation which is an array and i want to replace some string in the array. this throws an error

# translation
[
  'key' = [
    'b' => [ 
      'c' => [
                [
                    'title' => 'Extract ',
                    'text' => ':num_replace some text',
                ],
              ]
           ]
       ]
]


$result = __('key.b.c', ['num_replace' => $num > 0 ? number_format($totalModelsPositionsCount) : '']);

but this errors with local.ERROR: strtr() expects parameter 1 to be string, array given Can laravel https://laravel.com/docs/9.x/localization#replacing-parameters-in-translation-strings be used only in strings?

CodePudding user response:

You are missing key text :

__('key.b.c', 

It should be :

__('key.b.c.text',

Can laravel https://laravel.com/docs/9.x/localization#replacing-parameters-in-translation-strings be used only in strings? : Yes

it takes an array of arguments and returns a translation string

  • Related