Skip to content

Conversation

fabio-ivona
Copy link
Contributor

This PR will fix the translations FileLoader behaviour when multiple overrides are set up and the last one is missing a translation key:

as in Fileloader → loadNamespaceOverrides() the $lines variable is passed to the function through use, its value is used every time in array_replace_recursive(), instead of using the updated $output variable coming from previous iterations of the reduce function

this will cause the last iteration to remove all overrides made in previous ones

I added a failing test for this issue and implemented the fix:

protected function loadNamespaceOverrides(array $lines, $locale, $group, $namespace) { return (new Collection($this->paths)) - ->reduce(function ($output, $path) use ($lines, $locale, $group, $namespace) { + ->reduce(function ($output, $path) use ($locale, $group, $namespace) { $file = "{$path}/vendor/{$namespace}/{$locale}/{$group}.php"; if ($this->files->exists($file)) { - $lines = array_replace_recursive($lines, $this->files->getRequire($file)); + $output = array_replace_recursive($output, $this->files->getRequire($file)); } - return $lines; + return $output; - }, []); + }, $lines); }
@fabio-ivona fabio-ivona changed the title [12.x] Fix translation FileLoader overrides when a missing key [12.x] Fix translation FileLoader overrides with a missing key Apr 9, 2025
@taylorotwell taylorotwell merged commit b8f4f0d into laravel:12.x Apr 11, 2025
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants