Skip to content

[9.x] Fixes applying replacements to multi-level localization arrays#42022

Merged
taylorotwell merged 1 commit into
laravel:9.xfrom
dtorras:recursive_replacements
Apr 18, 2022
Merged

[9.x] Fixes applying replacements to multi-level localization arrays#42022
taylorotwell merged 1 commit into
laravel:9.xfrom
dtorras:recursive_replacements

Conversation

@dtorras

@dtorras dtorras commented Apr 17, 2022

Copy link
Copy Markdown
Contributor

This pull request fixes the localization parameters replacement when retrieving a multi-level localization array.

Back on 5.7 (#27254) this was fixed for single-level arrays, but it fails if you are retrieving something with more levels because makeReplacements function expects a string, not an array.

For example, currently this will fail:

trans('foo', ['appName' => 'Laravel'])

Translation file lang/en/foo.php:

return [
    'bar' => 'tree :appName',
    'qux' => [
        'baz' => 'localization :appName',
        'thud' => [
            'vapor' => 'level :appName',
        ],
    ],
];

This solution walks all the values recursively in the array case instead of just looping on the first-level array.

@GrahamCampbell GrahamCampbell changed the title Fixes applying replacements to multi-level localization arrays. [9.x] Fixes applying replacements to multi-level localization arrays Apr 17, 2022
@taylorotwell taylorotwell merged commit e209f38 into laravel:9.x Apr 18, 2022
@dtorras dtorras deleted the recursive_replacements branch April 19, 2022 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants